Skip to content

Commit

Permalink
Fix #62 #61 #60 #59
Browse files Browse the repository at this point in the history
  • Loading branch information
dridk committed Oct 2, 2017
1 parent b8d16fb commit 61b139d
Show file tree
Hide file tree
Showing 26 changed files with 338 additions and 172 deletions.
2 changes: 1 addition & 1 deletion src/app/docks/columns/columndockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ColumnDockWidget::ColumnDockWidget(QWidget * parent):
// emit changed signal when model changed
connect(qobject_cast<ColumnModel*>(mView->model()), &ColumnModel::itemChanged,[this](){emit changed();});

connect(mView,SIGNAL(filterItemCreated(FilterItem*)),this,SIGNAL(filterItemCreated(FilterItem*)));
connect(mView,SIGNAL(filterItemCreated(ConditionItem*)),this,SIGNAL(filterItemCreated(ConditionItem*)));

}
QStringList ColumnDockWidget::selectedColumns() const
Expand Down
2 changes: 1 addition & 1 deletion src/app/docks/columns/columndockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public Q_SLOTS:
void reset() override;

Q_SIGNALS:
void filterItemCreated(FilterItem * item);
void filterItemCreated(ConditionItem * item);


private:
Expand Down
2 changes: 1 addition & 1 deletion src/app/docks/columns/columnview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void ColumnView::contextMenuEvent(QContextMenuEvent *event)
dialog.setField(field);
if (dialog.exec())
{
emit filterItemCreated(dialog.createFilter());
emit filterItemCreated(dialog.createCondition());
}


Expand Down
2 changes: 1 addition & 1 deletion src/app/docks/columns/columnview.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ColumnView : public QTreeView
void load();

Q_SIGNALS:
void filterItemCreated(FilterItem * item);
void filterItemCreated(ConditionItem * item);

protected:
virtual void contextMenuEvent(QContextMenuEvent * event);
Expand Down
4 changes: 2 additions & 2 deletions src/app/docks/filters/allfilterdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ AllFilterDIalog::AllFilterDIalog(QWidget *parent)

}

FilterItem *AllFilterDIalog::filterItem() const
ConditionItem *AllFilterDIalog::filterItem() const
{
return mWidget->filterItem();
return mWidget->createCondition();
}

void AllFilterDIalog::fieldSelected()
Expand Down
2 changes: 1 addition & 1 deletion src/app/docks/filters/allfilterdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Q_OBJECT
public:
AllFilterDIalog(QWidget * parent = nullptr);

FilterItem * filterItem() const;
ConditionItem * filterItem() const;


protected Q_SLOTS:
Expand Down
21 changes: 12 additions & 9 deletions src/app/docks/filters/filterdelegate.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "filterdelegate.h"
#include "filterwidget.h"

FilterDelegate::FilterDelegate(QObject *parent)
:QStyledItemDelegate(parent)
Expand All @@ -10,16 +11,18 @@ FilterDelegate::FilterDelegate(QObject *parent)
QWidget * FilterDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
{

const FilterModel * m = qobject_cast<const FilterModel*>(index.model());

if (m->itemFromIndex(index)->type() == FilterModel::LogicType)
{
QComboBox * box = new QComboBox(parent);
box->setFrame(false);
box->addItems({"AND","OR"});
return box;

}
// const FilterModel * m = qobject_cast<const FilterModel*>(index.model());

// if (m->itemFromIndex(index)->type() == FilterModel::LogicType)
// {
// QComboBox * box = new QComboBox(parent);
// box->setFrame(false);
// box->addItems({"AND","OR"});
// return box;

// }



Expand All @@ -28,7 +31,7 @@ QWidget * FilterDelegate::createEditor(QWidget *parent, const QStyleOptionViewIt

void FilterDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
const FilterModel * m = qobject_cast<const FilterModel*>(index.model());
//const FilterModel * m = qobject_cast<const FilterModel*>(index.model());

// if (m->itemFromIndex(index)->type() == FilterModel::LogicType)
// {
Expand Down
4 changes: 1 addition & 3 deletions src/app/docks/filters/filterdelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
#include <QStyledItemDelegate>
#include <QComboBox>
#include <QPainter>
#include "filtermodel.h"


#include "abstractfieldwidget.h"
class FilterDelegate : public QStyledItemDelegate
{
public:
Expand Down
31 changes: 27 additions & 4 deletions src/app/docks/filters/filterdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ FilterDialog::FilterDialog(QWidget * parent)

connect(buttons,SIGNAL(accepted()),this,SLOT(accept()));
connect(buttons,SIGNAL(rejected()),this,SLOT(reject()));


}

void FilterDialog::setField(const cvar::Field &field)
Expand All @@ -29,7 +27,32 @@ void FilterDialog::setField(const cvar::Field &field)

}

FilterItem *FilterDialog::createFilter() const
const cvar::Field &FilterDialog::field() const
{
return mWidget->field();
}

void FilterDialog::setValue(const QVariant &value)
{
mWidget->setValue(value);
}

QVariant FilterDialog::value() const
{
return mWidget->value();
}

void FilterDialog::setCurrentOperator(Operator::Type type)
{
mWidget->setCurrentOperator(type);
}

Operator::Type FilterDialog::currentOperator()
{
return mWidget->currentOperator();
}

ConditionItem *FilterDialog::createCondition() const
{
return mWidget->filterItem();
return mWidget->createCondition();
}
10 changes: 9 additions & 1 deletion src/app/docks/filters/filterdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ class FilterDialog : public QDialog
public:
FilterDialog(QWidget * parent = nullptr);
void setField(const cvar::Field& field);
const cvar::Field& field() const;

void setValue(const QVariant& value);
QVariant value() const;

void setCurrentOperator(Operator::Type type);
Operator::Type currentOperator();

ConditionItem * createCondition() const;

FilterItem * createFilter() const;


private:
Expand Down
65 changes: 35 additions & 30 deletions src/app/docks/filters/filterdockwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ FilterDockWidget::FilterDockWidget(QWidget *parent)
setTitle("Filter");
setWidget(mView);

addAction(FIcon(0xf13b), "add condition", this, SLOT(addCondition()));
addAction(FIcon(0xf138), "add logic", this, SLOT(addLogic()));
addAction(FIcon(0xf114), "remove", this, SLOT(remove()));
mAddConditionAction = addAction(FIcon(0xf13b), "add condition", this, SLOT(addCondition()));
mAddLogicAction = addAction(FIcon(0xf138), "add logic", this, SLOT(addLogic()));
mRemAction = addAction(FIcon(0xf114), "remove", this, SLOT(remove()));

addActionSpacer();
QAction * saveAction = new QAction(FIcon(0xf11e),"open");
Expand All @@ -20,41 +20,22 @@ FilterDockWidget::FilterDockWidget(QWidget *parent)
saveAction->menu()->addSeparator();
saveAction->menu()->addAction("Save");
saveAction->menu()->addAction("Edit ...");


addAction(saveAction);



// create actions
// QAction *logicAction = new QAction(QIcon::fromTheme("list-add"), "add logic",this);
// QAction *condAction = new QAction(QIcon::fromTheme("list-add"), "add condition",this);
// QAction *delAction = new QAction(QIcon::fromTheme("list-remove"), "remove(s)",this);

// addAction(logicAction);
// addAction(condAction);
// addAction(delAction);

// // connect actions
// connect(logicAction,&QAction::triggered, [this](){mView->addLogic(); emit changed(); });
// connect(condAction,&QAction::triggered,[this](){mView->addCondition();emit changed();});
// connect(delAction,&QAction::triggered, [this](){mView->removeSelections();emit changed();});


updateActions();
connect(mView,SIGNAL(activated(QModelIndex)), this, SLOT(updateActions()));
connect(mView,SIGNAL(changed()),this,SIGNAL(changed()));

}


QString FilterDockWidget::condition() const
{
return mView->query();
}

void FilterDockWidget::addCondition(FilterItem *item)
void FilterDockWidget::addCondition(ConditionItem *item)
{
mView->addCondition(item);
emit changed();


}

void FilterDockWidget::addCondition()
Expand All @@ -66,8 +47,7 @@ void FilterDockWidget::addCondition()

void FilterDockWidget::addLogic()
{
mView->addLogic();
emit changed();
mView->addLogic(new LogicItem);


}
Expand All @@ -80,7 +60,32 @@ void FilterDockWidget::remove()
if (ret == QMessageBox::Ok)
{
mView->removeSelections();
emit changed();
}


}

void FilterDockWidget::updateActions()
{
if (!mView->currentItem())
return;

if (mView->currentItem() == mView->topLevelItem(0))
mRemAction->setDisabled(true);
else
mRemAction->setDisabled(false);


if (mView->currentItem()->type() == FilterView::ConditionType)
{
mAddConditionAction->setDisabled(true);
mAddLogicAction->setDisabled(true);
}

if (mView->currentItem()->type() == FilterView::LogicType)
{
mAddConditionAction->setEnabled(true);
mAddLogicAction->setEnabled(true);
}


Expand Down
10 changes: 9 additions & 1 deletion src/app/docks/filters/filterdockwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@ class FilterDockWidget : public BaseDockWidget


public Q_SLOTS:
void addCondition(FilterItem * item);
void addCondition(ConditionItem * item);
void addCondition();
void addLogic();
void remove();

protected Q_SLOTS:
void updateActions();


private:
FilterView * mView;
QAction * mAddConditionAction;
QAction * mAddLogicAction;
QAction * mRemAction;


};

#endif // CONDITIONDOCKWIDGET_H
61 changes: 30 additions & 31 deletions src/app/docks/filters/filteritem.cpp
Original file line number Diff line number Diff line change
@@ -1,65 +1,64 @@
#include "filteritem.h"
#include "filterview.h"

FilterItem::FilterItem(const cvar::Field &field, Operator::Type op, const QVariant &value)
:QStandardItem(), mField(field)
ConditionItem::ConditionItem(const cvar::Field &field, Operator::Type op, const QVariant &value)
:QTreeWidgetItem(FilterView::ConditionType), mField(field), mOperator(op), mValue(value)
{

setData(field.expression(), FieldRole);
setData(op, OperatorRole);
setData(value, ValueRole);
updateText();
setEditable(false);
}
updateItem();


}

void FilterItem::setField(const cvar::Field &f)
void ConditionItem::setField(const cvar::Field &f)
{
setData(f.expression(),FieldRole);
mField = f;
updateText();
updateItem();
}

void FilterItem::setOperator(Operator::Type op)
void ConditionItem::setOperator(Operator::Type op)
{
setData(op, OperatorRole);
updateText();
mOperator = op;
updateItem();
}

void FilterItem::setValue(const QVariant &value)
void ConditionItem::setValue(const QVariant &value)
{
setData(value, ValueRole);
updateText();
mValue = value;
updateItem();
}

int FilterItem::type() const
const cvar::Field& ConditionItem::field() const
{
return FilterModel::ConditionalType;
return mField;
}

const cvar::Field& FilterItem::field() const
QString ConditionItem::operatorName() const
{
return mField;
return Operator::symbol(mOperator);
}

QString FilterItem::operatorName() const
Operator::Type ConditionItem::currentOperator() const
{
return Operator::symbol(Operator::Type(data(OperatorRole).toInt()));
return mOperator;
}

Operator::Type FilterItem::operatorType() const
QVariant ConditionItem::value() const
{
return Operator::Type(data(OperatorRole).toInt());
return mValue;
}

QVariant FilterItem::value() const
QString ConditionItem::expression() const
{
return data(ValueRole);
return QString("%1 %2 %3").arg(mField.expression(), Operator::symbol(mOperator), mValue.toString());
}

void FilterItem::updateText()
void ConditionItem::updateItem()
{
setText(QString("%1 %2 %3").arg(field().expression()).arg(operatorName()).arg(value().toString()));
setData(QString("%1 %2 %3").arg(field().expression()).arg(operatorName()).arg(value().toString()), ConditionRole);
setText(0, field().name());
setText(1, operatorName());
setText(2, value().toString());

setToolTip(0, mField.description());


}
Loading

0 comments on commit 61b139d

Please sign in to comment.