diff options
-rw-r--r-- | desktop-widgets/filterwidget2.cpp | 39 | ||||
-rw-r--r-- | desktop-widgets/filterwidget2.h | 4 | ||||
-rw-r--r-- | desktop-widgets/filterwidget2.ui | 387 |
3 files changed, 241 insertions, 189 deletions
diff --git a/desktop-widgets/filterwidget2.cpp b/desktop-widgets/filterwidget2.cpp index 7b26c420e..c51bef29a 100644 --- a/desktop-widgets/filterwidget2.cpp +++ b/desktop-widgets/filterwidget2.cpp @@ -27,10 +27,16 @@ FilterWidget2::FilterWidget2(QWidget* parent) : ui.loadSetButton->setPopupMode(QToolButton::InstantPopup); + ui.presetTable->setModel(FilterPresetModel::instance()); + ui.presetTable->setSelectionBehavior(QAbstractItemView::SelectRows); + ui.presetTable->setSelectionMode(QAbstractItemView::SingleSelection); + connect(ui.clear, &QToolButton::clicked, this, &FilterWidget2::clearFilter); connect(ui.close, &QToolButton::clicked, this, &FilterWidget2::closeFilter); connect(ui.fullText, &QLineEdit::textChanged, this, &FilterWidget2::updateFilter); connect(ui.fulltextStringMode, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &FilterWidget2::updateFilter); + connect(ui.presetTable, &QTableView::clicked, this, &FilterWidget2::presetClicked); + connect(ui.presetTable->selectionModel(), &QItemSelectionModel::selectionChanged, this, &FilterWidget2::presetSelected); connect(&constraintModel, &FilterConstraintModel::rowsInserted, this, &FilterWidget2::constraintAdded); connect(&constraintModel, &FilterConstraintModel::rowsRemoved, this, &FilterWidget2::constraintRemoved); @@ -65,13 +71,22 @@ void FilterWidget2::updatePresetMenu() } ui.loadSetButton->setEnabled(true); for (int i = 0; i < count; ++i) { - QModelIndex idx = model->index(i, 0); + QModelIndex idx = model->index(i, FilterPresetModel::NAME); QString name = model->data(idx, Qt::DisplayRole).value<QString>(); - loadFilterPresetMenu->addAction(name, [this,i]() { loadPreset(i); }); + loadFilterPresetMenu->addAction(name, [this,i,model]() { selectPreset(i); }); } ui.loadSetButton->setMenu(loadFilterPresetMenu.get()); } +void FilterWidget2::selectPreset(int i) +{ + QAbstractItemModel *model = FilterPresetModel::instance(); + QItemSelectionModel *selectionModel = ui.presetTable->selectionModel(); + QModelIndex idx = model->index(i, 0); + selectionModel->reset(); + selectionModel->select(idx, QItemSelectionModel::Select | QItemSelectionModel::Rows); +} + void FilterWidget2::loadPreset(int index) { FilterData filter = filter_preset_get(index); @@ -103,6 +118,25 @@ void FilterWidget2::constraintRemoved(const QModelIndex &parent, int first, int updateFilter(); } +void FilterWidget2::presetClicked(const QModelIndex &index) +{ + if (!index.isValid()) + return; + + if (index.column() == FilterPresetModel::REMOVE) + Command::removeFilterPreset(index.row()); +} + +void FilterWidget2::presetSelected(const QItemSelection &selected, const QItemSelection &) +{ + if (selected.indexes().isEmpty()) + return clearFilter(); + const QModelIndex index = selected.indexes()[0]; + if (!index.isValid()) + return clearFilter(); + loadPreset(index.row()); +} + void FilterWidget2::constraintChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles) { // Note: this may appear strange, but we don't update the widget if we get @@ -126,6 +160,7 @@ void FilterWidget2::constraintsReset() void FilterWidget2::clearFilter() { ignoreSignal = true; // Prevent signals to force filter recalculation (TODO: check if necessary) + ui.presetTable->selectionModel()->reset(); // Note: we use reset(), because that doesn't emit signals. ui.fulltextStringMode->setCurrentIndex((int)StringFilterMode::STARTSWITH); ui.fullText->clear(); ignoreSignal = false; diff --git a/desktop-widgets/filterwidget2.h b/desktop-widgets/filterwidget2.h index 55d65fab2..a727c964c 100644 --- a/desktop-widgets/filterwidget2.h +++ b/desktop-widgets/filterwidget2.h @@ -35,6 +35,8 @@ private slots: void constraintChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles); void constraintsReset(); void updatePresetMenu(); + void presetClicked(const QModelIndex &index); + void presetSelected(const QItemSelection &selected, const QItemSelection &); void on_addSetButton_clicked(); private: @@ -47,6 +49,8 @@ private: FilterData createFilterData() const; void setFilterData(const FilterData &filterData); void loadPreset(int index); + void selectPreset(int i); + void clearFilterData(); std::unique_ptr<QMenu> loadFilterPresetMenu; }; diff --git a/desktop-widgets/filterwidget2.ui b/desktop-widgets/filterwidget2.ui index e83e6918d..d49f21fc7 100644 --- a/desktop-widgets/filterwidget2.ui +++ b/desktop-widgets/filterwidget2.ui @@ -19,200 +19,213 @@ <property name="windowTitle"> <string>Form</string> </property> - <layout class="QGridLayout" name="gridLayout_2"> - <item row="0" column="0"> - <widget class="QScrollArea" name="scrollArea"> - <property name="frameShape"> - <enum>QFrame::NoFrame</enum> + <layout class="QVBoxLayout" name="gridLayout_2"> + <item> + <widget class="QTabWidget" name="tabWidget"> + <property name="currentIndex"> + <number>0</number> </property> - <property name="frameShadow"> - <enum>QFrame::Plain</enum> - </property> - <property name="widgetResizable"> - <bool>true</bool> - </property> - <widget class="QWidget" name="scrollAreaWidgetContents"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>486</width> - <height>487</height> - </rect> + <widget class="QScrollArea" name="scrollArea"> + <attribute name="title"> + <string>Filter</string> + </attribute> + <property name="frameShape"> + <enum>QFrame::NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Plain</enum> </property> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <layout class="QGridLayout" name="constraintTable"> - <item row="0" column="0" colspan="2"> - <widget class="QLabel" name="title"> - <property name="font"> - <font> - <bold>true</bold> - </font> - </property> - <property name="text"> - <string>Filter</string> - </property> - </widget> - </item> - <item row="0" column="2" colspan="3"> - <layout class="QHBoxLayout" name="titleLineLayout"> - <item alignment="Qt::AlignLeft"> - <widget class="QToolButton" name="addConstraintButton"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Add constraint</string> - </property> - </widget> - </item> - <item> - <spacer name="titleLineSpacer1"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - </spacer> - </item> - <item> - <widget class="QToolButton" name="addSetButton"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Save set</string> - </property> - </widget> - </item> - <item> - <widget class="QToolButton" name="loadSetButton"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Load set</string> - </property> - </widget> - </item> - <item> - <spacer name="titleLineSpacer2"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - </spacer> - </item> - <item alignment="Qt::AlignLeft"> - <widget class="QToolButton" name="clear"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Reset</string> - </property> - <property name="icon"> - <iconset> - <normaloff>:edit-clear-icon</normaloff>:edit-clear-icon</iconset> - </property> - <property name="toolButtonStyle"> - <enum>Qt::ToolButtonTextBesideIcon</enum> - </property> - </widget> - </item> - <item alignment="Qt::AlignLeft"> - <widget class="QToolButton" name="close"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="text"> - <string>Close</string> - </property> - <property name="icon"> - <iconset> - <normaloff>:filter-close</normaloff>:filter-close</iconset> - </property> - <property name="toolButtonStyle"> - <enum>Qt::ToolButtonTextBesideIcon</enum> - </property> - </widget> - </item> - </layout> - </item> - <item row="1" column="0" colspan="2" alignment="Qt::AlignLeft"> - <widget class="QLabel" name="fullTextLabel"> - <property name="text"> - <string>Fulltext</string> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - </widget> - </item> - <item row="1" column="2" colspan="3" alignment="Qt::AlignLeft"> - <layout class="QHBoxLayout" name="fulltextLayout"> - <item> - <widget class="QComboBox" name="fulltextStringMode"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <item> + <property name="widgetResizable"> + <bool>true</bool> + </property> + <widget class="QWidget" name="scrollAreaWidgetContents"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>486</width> + <height>487</height> + </rect> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <layout class="QGridLayout" name="constraintTable"> + <item row="0" column="0" colspan="2"> + <widget class="QLabel" name="title"> + <property name="font"> + <font> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string>Filter</string> + </property> + </widget> + </item> + <item row="0" column="2" colspan="3"> + <layout class="QHBoxLayout" name="titleLineLayout"> + <item alignment="Qt::AlignLeft"> + <widget class="QToolButton" name="addConstraintButton"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Add constraint</string> + </property> + </widget> + </item> + <item> + <spacer name="titleLineSpacer1"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </spacer> + </item> + <item> + <widget class="QToolButton" name="addSetButton"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Save set</string> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="loadSetButton"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="text"> - <string>Substring</string> + <string>Load set</string> + </property> + </widget> + </item> + <item> + <spacer name="titleLineSpacer2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </spacer> + </item> + <item alignment="Qt::AlignLeft"> + <widget class="QToolButton" name="clear"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> </property> - </item> - <item> <property name="text"> - <string>Starts with</string> + <string>Reset</string> + </property> + <property name="icon"> + <iconset> + <normaloff>:edit-clear-icon</normaloff>:edit-clear-icon</iconset> + </property> + <property name="toolButtonStyle"> + <enum>Qt::ToolButtonTextBesideIcon</enum> + </property> + </widget> + </item> + <item alignment="Qt::AlignLeft"> + <widget class="QToolButton" name="close"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> </property> - </item> - <item> <property name="text"> - <string>Full word</string> - </property> - </item> - </widget> - </item> - <item row="1" column="2" colspan="3"> - <widget class="QLineEdit" name="fullText"/> - </item> - </layout> - </item> - </layout> - </item> - <item> - <spacer name="verticalSpacer"> - <property name="orientation"> - <enum>Qt::Vertical</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>20</width> - <height>40</height> - </size> - </property> - </spacer> - </item> - </layout> + <string>Close</string> + </property> + <property name="icon"> + <iconset> + <normaloff>:filter-close</normaloff>:filter-close</iconset> + </property> + <property name="toolButtonStyle"> + <enum>Qt::ToolButtonTextBesideIcon</enum> + </property> + </widget> + </item> + </layout> + </item> + <item row="1" column="0" colspan="2" alignment="Qt::AlignLeft"> + <widget class="QLabel" name="fullTextLabel"> + <property name="text"> + <string>Fulltext</string> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + <item row="1" column="2" colspan="3" alignment="Qt::AlignLeft"> + <layout class="QHBoxLayout" name="fulltextLayout"> + <item> + <widget class="QComboBox" name="fulltextStringMode"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <item> + <property name="text"> + <string>Substring</string> + </property> + </item> + <item> + <property name="text"> + <string>Starts with</string> + </property> + </item> + <item> + <property name="text"> + <string>Full word</string> + </property> + </item> + </widget> + </item> + <item row="1" column="2" colspan="3"> + <widget class="QLineEdit" name="fullText"/> + </item> + </layout> + </item> + </layout> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + </widget> + <widget class="QTableView" name="presetTable"> + <attribute name="title"> + <string>Filter sets</string> + </attribute> </widget> </widget> </item> |