mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
filter: create a primitive "create filter preset" dialog
The dialog asks the user for a name and warns if the name already exists, i.e. an old filter preset will be overwritten. Possibly, this should contain an auto-completion facility in the case that the user wants to overwrite old presets. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
2f5223035a
commit
581eb1f563
7 changed files with 194 additions and 24 deletions
|
@ -16,6 +16,7 @@ add_subdirectory(preferences)
|
|||
|
||||
set (SUBSURFACE_UI
|
||||
about.ui
|
||||
addfilterpreset.ui
|
||||
btdeviceselectiondialog.ui
|
||||
configuredivecomputerdialog.ui
|
||||
divecomponentselection.ui
|
||||
|
|
87
desktop-widgets/addfilterpreset.ui
Normal file
87
desktop-widgets/addfilterpreset.ui
Normal file
|
@ -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>
|
|
@ -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);
|
||||
}
|
||||
|
||||
FilterData FilterWidget2::createFilterData() const
|
||||
{
|
||||
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;
|
||||
filterData.fulltextStringMode = (StringFilterMode)ui.fulltextStringMode->currentIndex();
|
||||
filterData.fullText = ui.fullText->text();
|
||||
filterData.constraints = constraintModel.getConstraints();
|
||||
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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -57,6 +57,46 @@
|
|||
</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>
|
||||
<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">
|
||||
|
@ -97,26 +137,6 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<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="titleLineSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2" alignment="Qt::AlignLeft">
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Reference in a new issue