aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--desktop-widgets/CMakeLists.txt1
-rw-r--r--desktop-widgets/addfilterpreset.ui87
-rw-r--r--desktop-widgets/filterwidget2.cpp29
-rw-r--r--desktop-widgets/filterwidget2.h2
-rw-r--r--desktop-widgets/filterwidget2.ui58
-rw-r--r--desktop-widgets/simplewidgets.cpp26
-rw-r--r--desktop-widgets/simplewidgets.h13
7 files changed, 193 insertions, 23 deletions
diff --git a/desktop-widgets/CMakeLists.txt b/desktop-widgets/CMakeLists.txt
index a9a6a59a7..4a3259318 100644
--- a/desktop-widgets/CMakeLists.txt
+++ b/desktop-widgets/CMakeLists.txt
@@ -16,6 +16,7 @@ add_subdirectory(preferences)
set (SUBSURFACE_UI
about.ui
+ addfilterpreset.ui
btdeviceselectiondialog.ui
configuredivecomputerdialog.ui
divecomponentselection.ui
diff --git a/desktop-widgets/addfilterpreset.ui b/desktop-widgets/addfilterpreset.ui
new file mode 100644
index 000000000..120c5e547
--- /dev/null
+++ b/desktop-widgets/addfilterpreset.ui
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>AddFilterPresetDialog</class>
+ <widget class="QDialog" name="AddFilterPresetDialog">
+ <property name="windowModality">
+ <enum>Qt::WindowModal</enum>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>211</width>
+ <height>127</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Save filter set</string>
+ </property>
+ <property name="windowIcon">
+ <iconset>
+ <normalon>:subsurface-icon</normalon>
+ </iconset>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <property name="spacing">
+ <number>1</number>
+ </property>
+ <property name="leftMargin">
+ <number>3</number>
+ </property>
+ <property name="topMargin">
+ <number>3</number>
+ </property>
+ <property name="rightMargin">
+ <number>3</number>
+ </property>
+ <property name="bottomMargin">
+ <number>3</number>
+ </property>
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>Save filter set</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QLineEdit" name="name"/>
+ </item>
+ <item>
+ <widget class="QLabel" name="duplicateWarning">
+ <property name="text">
+ <string>Warning: this will overwrite an existing filter set.</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources>
+ <include location="../subsurface.qrc"/>
+ </resources>
+ <connections/>
+</ui>
diff --git a/desktop-widgets/filterwidget2.cpp b/desktop-widgets/filterwidget2.cpp
index f1cd3263d..490892cc1 100644
--- a/desktop-widgets/filterwidget2.cpp
+++ b/desktop-widgets/filterwidget2.cpp
@@ -2,9 +2,11 @@
#include "desktop-widgets/filterconstraintwidget.h"
#include "desktop-widgets/simplewidgets.h"
#include "desktop-widgets/mainwindow.h"
+#include "commands/command.h"
#include "core/qthelper.h"
#include "core/divelist.h"
#include "core/settings/qPrefUnit.h"
+#include "core/filterpreset.h"
#include <QDoubleSpinBox>
@@ -100,19 +102,38 @@ void FilterWidget2::closeFilter()
MainWindow::instance()->setApplicationState(ApplicationState::Default);
}
-void FilterWidget2::updateFilter()
+FilterData FilterWidget2::createFilterData() const
{
- if (ignoreSignal)
- return;
-
FilterData filterData;
filterData.fulltextStringMode = (StringFilterMode)ui.fulltextStringMode->currentIndex();
filterData.fullText = ui.fullText->text();
filterData.constraints = constraintModel.getConstraints();
+ return filterData;
+}
+
+void FilterWidget2::updateFilter()
+{
+ if (ignoreSignal)
+ return;
+
+ FilterData filterData = createFilterData();
validFilter = filterData.validFilter();
DiveFilter::instance()->setFilter(filterData);
}
+void FilterWidget2::on_addSetButton_clicked()
+{
+ AddFilterPresetDialog dialog(this);
+ QString name = dialog.doit();
+ if (name.isEmpty())
+ return;
+ int idx = filter_preset_id(name);
+ if (idx >= 0)
+ Command::editFilterPreset(idx, createFilterData());
+ else
+ Command::createFilterPreset(name, createFilterData());
+}
+
void FilterWidget2::showEvent(QShowEvent *event)
{
QWidget::showEvent(event);
diff --git a/desktop-widgets/filterwidget2.h b/desktop-widgets/filterwidget2.h
index 462200bf8..334b9737c 100644
--- a/desktop-widgets/filterwidget2.h
+++ b/desktop-widgets/filterwidget2.h
@@ -33,6 +33,7 @@ private slots:
void constraintRemoved(const QModelIndex &parent, int first, int last);
void constraintChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
void constraintsReset();
+ void on_addSetButton_clicked();
private:
bool ignoreSignal;
@@ -41,6 +42,7 @@ private:
bool validFilter;
void addConstraint(filter_constraint_type type);
std::vector<std::unique_ptr<FilterConstraintWidget>> constraintWidgets;
+ FilterData createFilterData() const;
};
#endif
diff --git a/desktop-widgets/filterwidget2.ui b/desktop-widgets/filterwidget2.ui
index f6b3d65f6..ca5d7693a 100644
--- a/desktop-widgets/filterwidget2.ui
+++ b/desktop-widgets/filterwidget2.ui
@@ -58,7 +58,7 @@
<item row="0" column="2" colspan="3">
<layout class="QHBoxLayout" name="titleLineLayout">
<item alignment="Qt::AlignLeft">
- <widget class="QToolButton" name="clear">
+ <widget class="QToolButton" name="addConstraintButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
@@ -66,19 +66,39 @@
</sizepolicy>
</property>
<property name="text">
- <string>Reset</string>
+ <string>Add constraint</string>
</property>
- <property name="icon">
- <iconset>
- <normaloff>:edit-clear-icon</normaloff>:edit-clear-icon</iconset>
+ </widget>
+ </item>
+ <item>
+ <spacer name="titleLineSpacer1">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
</property>
- <property name="toolButtonStyle">
- <enum>Qt::ToolButtonTextBesideIcon</enum>
+ </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>
+ <spacer name="titleLineSpacer2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </spacer>
+ </item>
<item alignment="Qt::AlignLeft">
- <widget class="QToolButton" name="close">
+ <widget class="QToolButton" name="clear">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
@@ -86,11 +106,11 @@
</sizepolicy>
</property>
<property name="text">
- <string>Close</string>
+ <string>Reset</string>
</property>
<property name="icon">
<iconset>
- <normaloff>:filter-close</normaloff>:filter-close</iconset>
+ <normaloff>:edit-clear-icon</normaloff>:edit-clear-icon</iconset>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum>
@@ -98,7 +118,7 @@
</widget>
</item>
<item alignment="Qt::AlignLeft">
- <widget class="QToolButton" name="addConstraintButton">
+ <widget class="QToolButton" name="close">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
@@ -106,16 +126,16 @@
</sizepolicy>
</property>
<property name="text">
- <string>Add constraint</string>
+ <string>Close</string>
</property>
- </widget>
- </item>
- <item>
- <spacer name="titleLineSpacer">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
+ <property name="icon">
+ <iconset>
+ <normaloff>:filter-close</normaloff>:filter-close</iconset>
</property>
- </spacer>
+ <property name="toolButtonStyle">
+ <enum>Qt::ToolButtonTextBesideIcon</enum>
+ </property>
+ </widget>
</item>
</layout>
</item>
diff --git a/desktop-widgets/simplewidgets.cpp b/desktop-widgets/simplewidgets.cpp
index b18c43bf5..153d3239e 100644
--- a/desktop-widgets/simplewidgets.cpp
+++ b/desktop-widgets/simplewidgets.cpp
@@ -12,6 +12,7 @@
#include <QClipboard>
#include "core/file.h"
+#include "core/filterpreset.h"
#include "core/divesite.h"
#include "desktop-widgets/mainwindow.h"
#include "core/qthelper.h"
@@ -478,6 +479,31 @@ void DiveComponentSelection::buttonClicked(QAbstractButton *button)
}
}
+AddFilterPresetDialog::AddFilterPresetDialog(QWidget *parent)
+{
+ ui.setupUi(this);
+ connect(ui.name, &QLineEdit::textChanged, this, &AddFilterPresetDialog::nameChanged);
+ connect(ui.buttonBox, &QDialogButtonBox::accepted, this, &AddFilterPresetDialog::accept);
+ connect(ui.buttonBox, &QDialogButtonBox::rejected, this, &AddFilterPresetDialog::reject);
+ nameChanged(ui.name->text());
+}
+
+void AddFilterPresetDialog::nameChanged(const QString &text)
+{
+ QString trimmed = text.trimmed();
+ bool isEmpty = trimmed.isEmpty();
+ bool exists = !isEmpty && filter_preset_id(trimmed) >= 0;
+ ui.duplicateWarning->setVisible(exists);
+ ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!isEmpty);
+}
+
+QString AddFilterPresetDialog::doit()
+{
+ if (exec() == QDialog::Accepted)
+ return ui.name->text().trimmed();
+ return QString();
+}
+
TextHyperlinkEventFilter::TextHyperlinkEventFilter(QTextEdit *txtEdit) : QObject(txtEdit),
textEdit(txtEdit),
scrollView(textEdit->viewport())
diff --git a/desktop-widgets/simplewidgets.h b/desktop-widgets/simplewidgets.h
index 6075aa660..d68c14bd4 100644
--- a/desktop-widgets/simplewidgets.h
+++ b/desktop-widgets/simplewidgets.h
@@ -20,6 +20,7 @@ class FilterModelBase;
#include "ui_urldialog.h"
#include "ui_divecomponentselection.h"
#include "ui_listfilter.h"
+#include "ui_addfilterpreset.h"
#include "core/exif.h"
#include "core/dive.h"
@@ -138,6 +139,18 @@ private:
struct dive_components *what;
};
+class AddFilterPresetDialog : public QDialog {
+ Q_OBJECT
+public:
+ explicit AddFilterPresetDialog(QWidget *parent);
+ QString doit(); // returns name of filter preset or empty string if user cancelled the dialog
+private
+slots:
+ void nameChanged(const QString &text);
+private:
+ Ui::AddFilterPresetDialog ui;
+};
+
class TextHyperlinkEventFilter : public QObject {
Q_OBJECT
public: