From b8b3acbfd38669e95628ed5a56ae4f1e1b6fc3eb Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 22 Nov 2021 15:24:48 +0200 Subject: [PATCH] Improve for a search bar. --- ChangeLog.txt | 1 + src/app/tape/tmainwindow.cpp | 258 ++++++++-- src/app/tape/tmainwindow.h | 8 +- src/app/tape/tmainwindow.ui | 201 +++++++- src/app/tape/vtapesettings.cpp | 71 ++- src/app/tape/vtapesettings.h | 15 + .../dialogs/dialogfinalmeasurements.cpp | 209 +++++++- .../dialogs/dialogfinalmeasurements.h | 7 + .../dialogs/dialogfinalmeasurements.ui | 231 ++++++++- src/app/valentina/dialogs/dialoghistory.cpp | 211 +++++++- src/app/valentina/dialogs/dialoghistory.h | 11 +- src/app/valentina/dialogs/dialoghistory.ui | 213 +++++++- .../valentina/dialogs/dialogincrements.cpp | 404 ++++++++++++++-- src/app/valentina/dialogs/dialogincrements.h | 22 +- src/app/valentina/dialogs/dialogincrements.ui | 457 ++++++++++++++++-- .../16x16/actions/system-search.png | Bin 0 -> 719 bytes .../24x24/actions/system-search.png | Bin 0 -> 1112 bytes .../32x32/actions/system-search.png | Bin 0 -> 1561 bytes src/libs/vmisc/share/resources/theme.qrc | 3 + src/libs/vmisc/vtablesearch.cpp | 206 ++++++-- src/libs/vmisc/vtablesearch.h | 31 +- src/libs/vmisc/vvalentinasettings.cpp | 285 ++++++++++- src/libs/vmisc/vvalentinasettings.h | 60 +++ 23 files changed, 2663 insertions(+), 241 deletions(-) create mode 100644 src/libs/vmisc/share/resources/icons/win.icon.theme/16x16/actions/system-search.png create mode 100755 src/libs/vmisc/share/resources/icons/win.icon.theme/24x24/actions/system-search.png create mode 100755 src/libs/vmisc/share/resources/icons/win.icon.theme/32x32/actions/system-search.png diff --git a/ChangeLog.txt b/ChangeLog.txt index 5e1b03fc4..16efee267 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -23,6 +23,7 @@ - Remove tool from all visibility groups it in. - Option to disable the automatic search for updates. - [smart-pattern/valentina#153] To add text search bar in History window. +- Improve for a search bar. # Valentina 0.7.49 July 1, 2021 - Fix crash. diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 221e15325..697005d05 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -108,13 +108,13 @@ TMainWindow::TMainWindow(QWidget *parent) : VAbstractMainWindow(parent), ui(new Ui::TMainWindow), formulaBaseHeight(0), - gradation(new QTimer(this)) + gradation(new QTimer(this)), + m_searchHistory(new QMenu(this)) { ui->setupUi(this); VAbstractApplication::VApp()->Settings()->GetOsSeparator() ? setLocale(QLocale()) : setLocale(QLocale::c()); - ui->lineEditFind->setClearButtonEnabled(true); ui->lineEditName->setClearButtonEnabled(true); ui->lineEditFullName->setClearButtonEnabled(true); ui->lineEditCustomerName->setClearButtonEnabled(true); @@ -123,7 +123,7 @@ TMainWindow::TMainWindow(QWidget *parent) ui->lineEditFind->installEventFilter(this); ui->plainTextEditFormula->installEventFilter(this); - search = QSharedPointer(new VTableSearch(ui->tableWidget)); + m_search = QSharedPointer(new VTableSearch(ui->tableWidget)); ui->tabWidget->setVisible(false); ui->mainToolBar->setContextMenuPolicy(Qt::PreventContextMenu); @@ -159,6 +159,7 @@ TMainWindow::TMainWindow(QWidget *parent) //--------------------------------------------------------------------------------------------------------------------- TMainWindow::~TMainWindow() { + ui->lineEditFind->blockSignals(true); // prevents crash delete data; delete m; qDeleteAll(hackedWidgets); @@ -179,7 +180,7 @@ void TMainWindow::RetranslateTable() const int row = ui->tableWidget->currentRow(); RefreshTable(); ui->tableWidget->selectRow(row); - search->RefreshList(ui->lineEditFind->text()); + m_search->RefreshList(ui->lineEditFind->text()); } } @@ -600,6 +601,9 @@ void TMainWindow::changeEvent(QEvent *event) // retranslate designer form (single inheritance approach) ui->retranslateUi(this); + ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder()); + UpdateSearchControlsTooltips(); + UpdateWindowTitle(); InitMeasurementUnits(); @@ -1158,9 +1162,9 @@ void TMainWindow::Remove() MeasurementsWereSaved(false); - search->RemoveRow(row); + m_search->RemoveRow(row); RefreshData(); - search->RefreshList(ui->lineEditFind->text()); + m_search->RefreshList(ui->lineEditFind->text()); if (ui->tableWidget->rowCount() > 0) { @@ -1240,7 +1244,7 @@ void TMainWindow::MoveTop() m->MoveTop(nameField->data(Qt::UserRole).toString()); MeasurementsWereSaved(false); RefreshData(); - search->RefreshList(ui->lineEditFind->text()); + m_search->RefreshList(ui->lineEditFind->text()); ui->tableWidget->selectRow(0); ui->tableWidget->repaint(); // Force repain to fix paint artifacts on Mac OS X } @@ -1259,7 +1263,7 @@ void TMainWindow::MoveUp() m->MoveUp(nameField->data(Qt::UserRole).toString()); MeasurementsWereSaved(false); RefreshData(); - search->RefreshList(ui->lineEditFind->text()); + m_search->RefreshList(ui->lineEditFind->text()); ui->tableWidget->selectRow(row-1); ui->tableWidget->repaint(); // Force repain to fix paint artifacts on Mac OS X } @@ -1278,7 +1282,7 @@ void TMainWindow::MoveDown() m->MoveDown(nameField->data(Qt::UserRole).toString()); MeasurementsWereSaved(false); RefreshData(); - search->RefreshList(ui->lineEditFind->text()); + m_search->RefreshList(ui->lineEditFind->text()); ui->tableWidget->selectRow(row+1); ui->tableWidget->repaint(); // Force repain to fix paint artifacts on Mac OS X } @@ -1297,7 +1301,7 @@ void TMainWindow::MoveBottom() m->MoveBottom(nameField->data(Qt::UserRole).toString()); MeasurementsWereSaved(false); RefreshData(); - search->RefreshList(ui->lineEditFind->text()); + m_search->RefreshList(ui->lineEditFind->text()); ui->tableWidget->selectRow(ui->tableWidget->rowCount()-1); ui->tableWidget->repaint(); // Force repain to fix paint artifacts on Mac OS X } @@ -1348,7 +1352,7 @@ void TMainWindow::Fx() RefreshData(); - search->RefreshList(ui->lineEditFind->text()); + m_search->RefreshList(ui->lineEditFind->text()); ui->tableWidget->selectRow(row); } @@ -1373,9 +1377,9 @@ void TMainWindow::AddCustom() m->AddEmptyAfter(nameField->data(Qt::UserRole).toString(), name); } - search->AddRow(currentRow); + m_search->AddRow(currentRow); RefreshData(); - search->RefreshList(ui->lineEditFind->text()); + m_search->RefreshList(ui->lineEditFind->text()); ui->tableWidget->selectRow(currentRow); @@ -1408,7 +1412,7 @@ void TMainWindow::AddKnown() m->AddEmpty(name); } - search->AddRow(currentRow); + m_search->AddRow(currentRow); } } else @@ -1426,13 +1430,13 @@ void TMainWindow::AddKnown() { m->AddEmptyAfter(after, name); } - search->AddRow(currentRow); + m_search->AddRow(currentRow); after = name; } } RefreshData(); - search->RefreshList(ui->lineEditFind->text()); + m_search->RefreshList(ui->lineEditFind->text()); ui->tableWidget->selectRow(currentRow); @@ -1510,7 +1514,7 @@ void TMainWindow::ImportFromPattern() RefreshData(); - search->RefreshList(ui->lineEditFind->text()); + m_search->RefreshList(ui->lineEditFind->text()); ui->tableWidget->selectRow(currentRow); @@ -1567,7 +1571,7 @@ void TMainWindow::GradationChanged() gradation->stop(); const int row = ui->tableWidget->currentRow(); RefreshData(); - search->RefreshList(ui->lineEditFind->text()); + m_search->RefreshList(ui->lineEditFind->text()); ui->tableWidget->selectRow(row); } @@ -1810,7 +1814,7 @@ void TMainWindow::SaveMName(const QString &text) m->SetMName(nameField->text(), newName); MeasurementsWereSaved(false); RefreshData(); - search->RefreshList(ui->lineEditFind->text()); + m_search->RefreshList(ui->lineEditFind->text()); ui->tableWidget->blockSignals(true); ui->tableWidget->selectRow(row); @@ -1888,7 +1892,7 @@ void TMainWindow::SaveMValue() const QTextCursor cursor = ui->plainTextEditFormula->textCursor(); RefreshData(); - search->RefreshList(ui->lineEditFind->text()); + m_search->RefreshList(ui->lineEditFind->text()); ui->tableWidget->blockSignals(true); ui->tableWidget->selectRow(row); @@ -1913,7 +1917,7 @@ void TMainWindow::SaveMBaseValue(double value) MeasurementsWereSaved(false); RefreshData(); - search->RefreshList(ui->lineEditFind->text()); + m_search->RefreshList(ui->lineEditFind->text()); ui->tableWidget->blockSignals(true); ui->tableWidget->selectRow(row); @@ -1938,7 +1942,7 @@ void TMainWindow::SaveMShiftA(double value) MeasurementsWereSaved(false); RefreshData(); - search->RefreshList(ui->lineEditFind->text()); + m_search->RefreshList(ui->lineEditFind->text()); ui->tableWidget->blockSignals(true); ui->tableWidget->selectRow(row); @@ -1963,7 +1967,7 @@ void TMainWindow::SaveMShiftB(double value) MeasurementsWereSaved(false); RefreshData(); - search->RefreshList(ui->lineEditFind->text()); + m_search->RefreshList(ui->lineEditFind->text()); ui->tableWidget->blockSignals(true); ui->tableWidget->selectRow(row); @@ -1988,7 +1992,7 @@ void TMainWindow::SaveMShiftC(double value) MeasurementsWereSaved(false); RefreshData(); - search->RefreshList(ui->lineEditFind->text()); + m_search->RefreshList(ui->lineEditFind->text()); ui->tableWidget->blockSignals(true); ui->tableWidget->selectRow(row); @@ -2014,7 +2018,7 @@ void TMainWindow::SaveMCorrectionValue(double value) MeasurementsWereSaved(false); RefreshData(); - search->RefreshList(ui->lineEditFind->text()); + m_search->RefreshList(ui->lineEditFind->text()); ui->tableWidget->blockSignals(true); ui->tableWidget->selectRow(row); @@ -2112,7 +2116,7 @@ void TMainWindow::SaveMUnits() MeasurementsWereSaved(false); RefreshData(); - search->RefreshList(ui->lineEditFind->text()); + m_search->RefreshList(ui->lineEditFind->text()); ui->tableWidget->blockSignals(true); ui->tableWidget->selectRow(row); @@ -2138,7 +2142,7 @@ void TMainWindow::SaveMDimension() MeasurementsWereSaved(false); RefreshData(); - search->RefreshList(ui->lineEditFind->text()); + m_search->RefreshList(ui->lineEditFind->text()); ui->tableWidget->blockSignals(true); ui->tableWidget->selectRow(row); @@ -2553,18 +2557,7 @@ void TMainWindow::InitWindow() connect(ui->comboBoxPMSystem, QOverload::of(&QComboBox::currentIndexChanged), this, &TMainWindow::SavePMSystem); - connect(ui->lineEditFind, &QLineEdit::textChanged, this, [this] (const QString &term){search->Find(term);}); - connect(ui->toolButtonFindPrevious, &QToolButton::clicked, this, [this] (){search->FindPrevious();}); - connect(ui->toolButtonFindNext, &QToolButton::clicked, this, [this] (){search->FindNext();}); - - connect(search.data(), &VTableSearch::HasResult, this, [this] (bool state) - { - ui->toolButtonFindPrevious->setEnabled(state); - }); - connect(search.data(), &VTableSearch::HasResult, this, [this] (bool state) - { - ui->toolButtonFindNext->setEnabled(state); - }); + InitSearch(); ui->plainTextEditNotes->setPlainText(m->Notes()); connect(ui->plainTextEditNotes, &QPlainTextEdit::textChanged, this, &TMainWindow::SaveNotes); @@ -3473,6 +3466,11 @@ void TMainWindow::WriteSettings() settings->SetWindowState(saveState()); settings->SetToolbarsState(saveState(AppVersion())); + settings->SetTapeSearchOptionMatchCase(m_search->IsMatchCase()); + settings->SetTapeSearchOptionWholeWord(m_search->IsMatchWord()); + settings->SetTapeSearchOptionRegexp(m_search->IsMatchRegexp()); + settings->SetTapeSearchOptionUseUnicodeProperties(m_search->IsUseUnicodePreperties()); + settings->sync(); if (settings->status() == QSettings::AccessError) { @@ -3498,7 +3496,7 @@ void TMainWindow::UpdatePatternUnit() RefreshTable(); - search->RefreshList(ui->lineEditFind->text()); + m_search->RefreshList(ui->lineEditFind->text()); ui->tableWidget->selectRow(row); } @@ -3763,9 +3761,9 @@ void TMainWindow::ShowError(const QString &text) void TMainWindow::RefreshDataAfterImport() { const int currentRow = ui->tableWidget->currentRow(); - search->AddRow(currentRow); + m_search->AddRow(currentRow); RefreshData(); - search->RefreshList(ui->lineEditFind->text()); + m_search->RefreshList(ui->lineEditFind->text()); ui->tableWidget->selectRow(currentRow); ui->actionExportToCSV->setEnabled(true); @@ -4356,6 +4354,182 @@ void TMainWindow::InitMeasurementDimension() ui->comboBoxDimension->blockSignals(false); } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::InitSearch() +{ + VTapeSettings *settings = MApplication::VApp()->TapeSettings(); + m_search->SetUseUnicodePreperties(settings->GetTapeSearchOptionUseUnicodeProperties()); + m_search->SetMatchWord(settings->GetTapeSearchOptionWholeWord()); + m_search->SetMatchRegexp(settings->GetTapeSearchOptionRegexp()); + m_search->SetMatchCase(settings->GetTapeSearchOptionMatchCase()); + + ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder()); + + UpdateSearchControlsTooltips(); + + connect(ui->lineEditFind, &QLineEdit::textChanged, this, [this] (const QString &term){m_search->Find(term);}); + connect(ui->lineEditFind, &QLineEdit::editingFinished, this, [this]() + { + SaveSearchRequest(); + InitSearchHistory(); + m_search->Find(ui->lineEditFind->text()); + }); + connect(ui->toolButtonFindPrevious, &QToolButton::clicked, this, [this]() + { + SaveSearchRequest(); + InitSearchHistory(); + m_search->FindPrevious(); + ui->labelResults->setText(QString("%1/%2").arg(m_search->MatchIndex()+1).arg(m_search->MatchCount())); + }); + connect(ui->toolButtonFindNext, &QToolButton::clicked, this, [this]() + { + SaveSearchRequest(); + InitSearchHistory(); + m_search->FindNext(); + ui->labelResults->setText(QString("%1/%2").arg(m_search->MatchIndex()+1).arg(m_search->MatchCount())); + }); + + connect(m_search.data(), &VTableSearch::HasResult, this, [this] (bool state) + { + ui->toolButtonFindPrevious->setEnabled(state); + ui->toolButtonFindNext->setEnabled(state); + + if (state) + { + ui->labelResults->setText(QString("%1/%2").arg(m_search->MatchIndex()+1).arg(m_search->MatchCount())); + } + else + { + ui->labelResults->setText(tr("0 results")); + } + + QPalette palette; + + if (not state && not ui->lineEditFind->text().isEmpty()) + { + palette.setColor(QPalette::Text, Qt::red); + ui->lineEditFind->setPalette(palette); + + palette.setColor(QPalette::Active, ui->labelResults->foregroundRole(), Qt::red); + palette.setColor(QPalette::Inactive, ui->labelResults->foregroundRole(), Qt::red); + ui->labelResults->setPalette(palette); + } + else + { + ui->lineEditFind->setPalette(palette); + ui->labelResults->setPalette(palette); + } + }); + + connect(ui->toolButtonCaseSensitive, &QToolButton::toggled, this, [this](bool checked) + { + m_search->SetMatchCase(checked); + m_search->Find(ui->lineEditFind->text()); + ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder()); + }); + + connect(ui->toolButtonWholeWord, &QToolButton::toggled, this, [this](bool checked) + { + m_search->SetMatchWord(checked); + m_search->Find(ui->lineEditFind->text()); + ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder()); + }); + + connect(ui->toolButtonRegexp, &QToolButton::toggled, this, [this](bool checked) + { + m_search->SetMatchRegexp(checked); + + if (checked) + { + ui->toolButtonWholeWord->blockSignals(true); + ui->toolButtonWholeWord->setChecked(false); + ui->toolButtonWholeWord->blockSignals(false); + ui->toolButtonWholeWord->setEnabled(false); + + ui->toolButtonUseUnicodeProperties->setEnabled(true); + } + else + { + ui->toolButtonWholeWord->setEnabled(true); + ui->toolButtonUseUnicodeProperties->blockSignals(true); + ui->toolButtonUseUnicodeProperties->setChecked(false); + ui->toolButtonUseUnicodeProperties->blockSignals(false); + ui->toolButtonUseUnicodeProperties->setEnabled(false); + } + m_search->Find(ui->lineEditFind->text()); + ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder()); + }); + + connect(ui->toolButtonUseUnicodeProperties, &QToolButton::toggled, this, [this](bool checked) + { + m_search->SetUseUnicodePreperties(checked); + m_search->Find(ui->lineEditFind->text()); + }); + + m_searchHistory->setStyleSheet(QStringLiteral("QMenu { menu-scrollable: 1; }")); + InitSearchHistory(); + ui->pushButtonSearch->setMenu(m_searchHistory); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::InitSearchHistory() +{ + QStringList searchHistory = MApplication::VApp()->TapeSettings()->GetTapeSearchHistory(); + m_searchHistory->clear(); + for (const auto& term : searchHistory) + { + QAction *action = m_searchHistory->addAction(term); + action->setData(term); + connect(action, &QAction::triggered, this, [this]() + { + auto *action = qobject_cast(sender()); + if (action != nullptr) + { + QString term = action->data().toString(); + ui->lineEditFind->setText(term); + m_search->Find(term); + ui->lineEditFind->setFocus(); + } + }); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::SaveSearchRequest() +{ + QStringList searchHistory = MApplication::VApp()->TapeSettings()->GetTapeSearchHistory(); + QString term = ui->lineEditFind->text(); + if (term.isEmpty()) + { + return; + } + + searchHistory.removeAll(term); + searchHistory.prepend(term); + while (searchHistory.size() > VTableSearch::MaxHistoryRecords) + { + searchHistory.removeLast(); + } + MApplication::VApp()->TapeSettings()->SetTapeSearchHistory(searchHistory); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::UpdateSearchControlsTooltips() +{ + auto UpdateToolTip = [](QAbstractButton *button) + { + button->setToolTip(button->toolTip().arg(button->shortcut().toString(QKeySequence::NativeText))); + }; + + UpdateToolTip(ui->toolButtonCaseSensitive); + UpdateToolTip(ui->toolButtonWholeWord); + UpdateToolTip(ui->toolButtonRegexp); + UpdateToolTip(ui->toolButtonUseUnicodeProperties); + UpdateToolTip(ui->pushButtonSearch); + UpdateToolTip(ui->toolButtonFindPrevious); + UpdateToolTip(ui->toolButtonFindNext); +} + //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::RetranslateTableHeaders() { diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index b50e1d21c..aff3ae193 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -165,7 +165,7 @@ private: QComboBox *comboBoxUnits{nullptr}; int formulaBaseHeight; QSharedPointer> lock{nullptr}; - QSharedPointer search{}; + QSharedPointer m_search{}; QLabel *labelGradationDimensionA{nullptr}; QLabel *labelGradationDimensionB{nullptr}; QLabel *labelGradationDimensionC{nullptr}; @@ -173,6 +173,7 @@ private: bool isInitialized{false}; bool mIsReadOnly{false}; QTimer *gradation; + QMenu *m_searchHistory; QVector hackedWidgets{}; @@ -190,6 +191,11 @@ private: void InitMeasurementUnits(); void InitGender(QComboBox *gender); void InitMeasurementDimension(); + void InitSearch(); + + void InitSearchHistory(); + void SaveSearchRequest(); + void UpdateSearchControlsTooltips(); void RetranslateTableHeaders(); diff --git a/src/app/tape/tmainwindow.ui b/src/app/tape/tmainwindow.ui index f608b2a3b..0118536b3 100644 --- a/src/app/tape/tmainwindow.ui +++ b/src/app/tape/tmainwindow.ui @@ -61,23 +61,196 @@ - + + + + 0 + 0 + + + + <html><head/><body><p>Search history <span style=" color:#888a85;">%1</span></p></body></html> + - Find: + + + + + ../valentina/dialogs../valentina/dialogs + + + Alt+Down - false - - - <html><head/><body><p>Search measurements by term. </p><p>Prepend &quot;/r/&quot; to the front of the search string to search measurements by regex.</p></body></html> + true Search + + true + + + + + + + Qt::Vertical + + + + + + + 0 results + + + + + + + Qt::Vertical + + + + + + + + 24 + 24 + + + + + 14 + 75 + false + true + + + + <html><head/><body><p>Match Case <span style=" color:#888a85;">%1</span></p></body></html> + + + Cc + + + Alt+C + + + true + + + false + + + + + + + + 24 + 24 + + + + + 14 + 75 + true + + + + <html><head/><body><p>Match words <span style=" color:#888a85;">%1</span></p></body></html> + + + W + + + Alt+W + + + true + + + + + + + + 0 + 0 + + + + + 24 + 24 + + + + + 14 + 75 + true + + + + <html><head/><body><p>Match with regular expressions <span style=" color:#888a85;">%1</span></p></body></html> + + + .* + + + Alt+X + + + true + + + + + + + false + + + + 24 + 24 + + + + + 14 + 75 + true + + + + <html><head/><body><p>Use unicode properties <span style=" color:#888a85;">%1</span></p><p><br/><span style=" color:#888a85;">The meaning of the \w, \d, etc., character classes, as well as the meaning of their counterparts (\W, \D, etc.), is changed from matching ASCII characters only to matching any character with the corresponding Unicode property. For instance, \d is changed to match any character with the Unicode Nd (decimal digit) property; \w to match any character with either the Unicode L (letter) or N (digit) property, plus underscore, and so on. This option corresponds to the /u modifier in Perl regular expressions.</span></p></body></html> + + + U + + + Alt+U + + + true + + + + + + + Qt::Vertical + @@ -86,17 +259,17 @@ false - Find Previous + <html><head/><body><p>Find Previous <span style=" color:#888a85;">%1</span></p></body></html> ... - - .. + + ../valentina/dialogs../valentina/dialogs - Ctrl+Shift+G + Shift+F3 @@ -106,17 +279,17 @@ false - Find Next + <html><head/><body><p>Find Next %1</p></body></html> ... - - .. + + ../valentina/dialogs../valentina/dialogs - Ctrl+G + F3 false diff --git a/src/app/tape/vtapesettings.cpp b/src/app/tape/vtapesettings.cpp index 283becaac..7c9b80583 100644 --- a/src/app/tape/vtapesettings.cpp +++ b/src/app/tape/vtapesettings.cpp @@ -37,7 +37,16 @@ namespace { Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDataBaseGeometry, (QLatin1String("database/geometry"))) -} +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchHistoryTape, (QLatin1String("searchHistory/tape"))) + +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchOptionsTapeUseUnicodeProperties, + (QLatin1String("searchOptions/tapeUseUnicodeProperties"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchOptionsTapeWholeWord, + (QLatin1String("searchOptions/tapeWholeWord"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchOptionsTapeRegexp, (QLatin1String("searchOptions/tapeRegexp"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchOptionsTapeMatchCase, + (QLatin1String("searchOptions/tapeMatchCase"))) +} // namespace //--------------------------------------------------------------------------------------------------------------------- VTapeSettings::VTapeSettings(Format format, Scope scope, const QString &organization, const QString &application, @@ -57,3 +66,63 @@ void VTapeSettings::SetDataBaseGeometry(const QByteArray &value) { setValue(*settingDataBaseGeometry, value); } + +//--------------------------------------------------------------------------------------------------------------------- +auto VTapeSettings::GetTapeSearchHistory() const -> QStringList +{ + return value(*settingSearchHistoryTape).toStringList(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTapeSettings::SetTapeSearchHistory(const QStringList &history) +{ + setValue(*settingSearchHistoryTape, history); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VTapeSettings::GetTapeSearchOptionUseUnicodeProperties() const -> bool +{ + return value(*settingSearchOptionsTapeUseUnicodeProperties, false).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTapeSettings::SetTapeSearchOptionUseUnicodeProperties(bool value) +{ + setValue(*settingSearchOptionsTapeUseUnicodeProperties, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VTapeSettings::GetTapeSearchOptionWholeWord() const -> bool +{ + return value(*settingSearchOptionsTapeWholeWord, false).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTapeSettings::SetTapeSearchOptionWholeWord(bool value) +{ + setValue(*settingSearchOptionsTapeWholeWord, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VTapeSettings::GetTapeSearchOptionRegexp() const -> bool +{ + return value(*settingSearchOptionsTapeRegexp, false).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTapeSettings::SetTapeSearchOptionRegexp(bool value) +{ + setValue(*settingSearchOptionsTapeRegexp, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VTapeSettings::GetTapeSearchOptionMatchCase() const -> bool +{ + return value(*settingSearchOptionsTapeMatchCase, false).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTapeSettings::SetTapeSearchOptionMatchCase(bool value) +{ + setValue(*settingSearchOptionsTapeMatchCase, value); +} diff --git a/src/app/tape/vtapesettings.h b/src/app/tape/vtapesettings.h index 752267303..0543fe569 100644 --- a/src/app/tape/vtapesettings.h +++ b/src/app/tape/vtapesettings.h @@ -49,6 +49,21 @@ public: QByteArray GetDataBaseGeometry() const; void SetDataBaseGeometry(const QByteArray &value); + auto GetTapeSearchHistory() const -> QStringList; + void SetTapeSearchHistory(const QStringList &history); + + auto GetTapeSearchOptionUseUnicodeProperties() const -> bool; + void SetTapeSearchOptionUseUnicodeProperties(bool value); + + auto GetTapeSearchOptionWholeWord() const -> bool; + void SetTapeSearchOptionWholeWord(bool value); + + auto GetTapeSearchOptionRegexp() const -> bool; + void SetTapeSearchOptionRegexp(bool value); + + auto GetTapeSearchOptionMatchCase() const ->bool; + void SetTapeSearchOptionMatchCase(bool value); + private: Q_DISABLE_COPY(VTapeSettings) }; diff --git a/src/app/valentina/dialogs/dialogfinalmeasurements.cpp b/src/app/valentina/dialogs/dialogfinalmeasurements.cpp index 66fd5f3c8..64d2dd6a7 100644 --- a/src/app/valentina/dialogs/dialogfinalmeasurements.cpp +++ b/src/app/valentina/dialogs/dialogfinalmeasurements.cpp @@ -36,6 +36,7 @@ #include "../vpatterndb/calculator.h" #include "../vtools/dialogs/support/dialogeditwrongformula.h" #include "../core/vapplication.h" +#include #include #define DIALOG_MAX_FORMULA_HEIGHT 64 @@ -46,7 +47,8 @@ DialogFinalMeasurements::DialogFinalMeasurements(VPattern *doc, QWidget *parent) ui(new Ui::DialogFinalMeasurements), m_doc(doc), m_data(doc->GetCompleteData()), - m_measurements(doc->GetFinalMeasurements()) + m_measurements(doc->GetFinalMeasurements()), + m_searchHistory(new QMenu(this)) { ui->setupUi(this); @@ -55,11 +57,10 @@ DialogFinalMeasurements::DialogFinalMeasurements(VPattern *doc, QWidget *parent) #endif ui->lineEditName->setClearButtonEnabled(true); - ui->lineEditFind->setClearButtonEnabled(true); ui->lineEditFind->installEventFilter(this); - m_search = QSharedPointer(new VTableSearch(ui->tableWidget)); + InitSearch(); formulaBaseHeight = ui->plainTextEditFormula->height(); ui->plainTextEditFormula->installEventFilter(this); @@ -89,19 +90,6 @@ DialogFinalMeasurements::DialogFinalMeasurements(VPattern *doc, QWidget *parent) connect(ui->plainTextEditDescription, &QPlainTextEdit::textChanged, this, &DialogFinalMeasurements::SaveDescription); connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogFinalMeasurements::SaveFormula); - connect(ui->lineEditFind, &QLineEdit::textEdited, this, [this](const QString &term){m_search->Find(term);}); - connect(ui->toolButtonFindPrevious, &QToolButton::clicked, this, [this](){m_search->FindPrevious();}); - connect(ui->toolButtonFindNext, &QToolButton::clicked, this, [this](){m_search->FindNext();}); - - connect(m_search.data(), &VTableSearch::HasResult, this, [this] (bool state) - { - ui->toolButtonFindPrevious->setEnabled(state); - }); - - connect(m_search.data(), &VTableSearch::HasResult, this, [this] (bool state) - { - ui->toolButtonFindNext->setEnabled(state); - }); if (ui->tableWidget->rowCount() > 0) { @@ -112,6 +100,7 @@ DialogFinalMeasurements::DialogFinalMeasurements(VPattern *doc, QWidget *parent) //--------------------------------------------------------------------------------------------------------------------- DialogFinalMeasurements::~DialogFinalMeasurements() { + ui->lineEditFind->blockSignals(true); // prevents crash delete ui; } @@ -122,6 +111,12 @@ void DialogFinalMeasurements::closeEvent(QCloseEvent *event) ui->lineEditName->blockSignals(true); ui->plainTextEditDescription->blockSignals(true); + VValentinaSettings *settings = VAbstractValApplication::VApp()->ValentinaSettings(); + settings->SetFinalMeasurementsSearchOptionMatchCase(m_search->IsMatchCase()); + settings->SetFinalMeasurementsSearchOptionWholeWord(m_search->IsMatchWord()); + settings->SetFinalMeasurementsSearchOptionRegexp(m_search->IsMatchRegexp()); + settings->SetFinalMeasurementsSearchOptionUseUnicodeProperties(m_search->IsUseUnicodePreperties()); + QDialog::closeEvent(event); } @@ -132,6 +127,8 @@ void DialogFinalMeasurements::changeEvent(QEvent *event) { // retranslate designer form (single inheritance approach) ui->retranslateUi(this); + ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder()); + UpdateSearchControlsTooltips(); FullUpdateFromFile(); } // remember to call base class implementation @@ -721,3 +718,183 @@ qreal DialogFinalMeasurements::EvalFormula(const QString &formula, bool &ok) ok = true; return result; } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFinalMeasurements::InitSearch() +{ + m_search = QSharedPointer(new VTableSearch(ui->tableWidget)); + + VValentinaSettings *settings = VAbstractValApplication::VApp()->ValentinaSettings(); + m_search->SetUseUnicodePreperties(settings->GetFinalMeasurementsSearchOptionUseUnicodeProperties()); + m_search->SetMatchWord(settings->GetFinalMeasurementsSearchOptionWholeWord()); + m_search->SetMatchRegexp(settings->GetFinalMeasurementsSearchOptionRegexp()); + m_search->SetMatchCase(settings->GetFinalMeasurementsSearchOptionMatchCase()); + + ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder()); + + UpdateSearchControlsTooltips(); + + connect(ui->lineEditFind, &QLineEdit::textEdited, this, [this](const QString &term){m_search->Find(term);}); + connect(ui->lineEditFind, &QLineEdit::editingFinished, this, [this]() + { + SaveSearchRequest(); + InitSearchHistory(); + m_search->Find(ui->lineEditFind->text()); + }); + connect(ui->toolButtonFindPrevious, &QToolButton::clicked, this, [this]() + { + SaveSearchRequest(); + InitSearchHistory(); + m_search->FindPrevious(); + ui->labelResults->setText(QString("%1/%2").arg(m_search->MatchIndex()+1).arg(m_search->MatchCount())); + }); + connect(ui->toolButtonFindNext, &QToolButton::clicked, this, [this]() + { + SaveSearchRequest(); + InitSearchHistory(); + m_search->FindNext(); + ui->labelResults->setText(QString("%1/%2").arg(m_search->MatchIndex()+1).arg(m_search->MatchCount())); + }); + + connect(m_search.data(), &VTableSearch::HasResult, this, [this] (bool state) + { + ui->toolButtonFindPrevious->setEnabled(state); + ui->toolButtonFindNext->setEnabled(state); + + if (state) + { + ui->labelResults->setText(QString("%1/%2").arg(m_search->MatchIndex()+1).arg(m_search->MatchCount())); + } + else + { + ui->labelResults->setText(tr("0 results")); + } + + QPalette palette; + + if (not state && not ui->lineEditFind->text().isEmpty()) + { + palette.setColor(QPalette::Text, Qt::red); + ui->lineEditFind->setPalette(palette); + + palette.setColor(QPalette::Active, ui->labelResults->foregroundRole(), Qt::red); + palette.setColor(QPalette::Inactive, ui->labelResults->foregroundRole(), Qt::red); + ui->labelResults->setPalette(palette); + } + else + { + ui->lineEditFind->setPalette(palette); + ui->labelResults->setPalette(palette); + } + }); + + connect(ui->toolButtonCaseSensitive, &QToolButton::toggled, this, [this](bool checked) + { + m_search->SetMatchCase(checked); + m_search->Find(ui->lineEditFind->text()); + ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder()); + }); + + connect(ui->toolButtonWholeWord, &QToolButton::toggled, this, [this](bool checked) + { + m_search->SetMatchWord(checked); + m_search->Find(ui->lineEditFind->text()); + ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder()); + }); + + connect(ui->toolButtonRegexp, &QToolButton::toggled, this, [this](bool checked) + { + m_search->SetMatchRegexp(checked); + + if (checked) + { + ui->toolButtonWholeWord->blockSignals(true); + ui->toolButtonWholeWord->setChecked(false); + ui->toolButtonWholeWord->blockSignals(false); + ui->toolButtonWholeWord->setEnabled(false); + + ui->toolButtonUseUnicodeProperties->setEnabled(true); + } + else + { + ui->toolButtonWholeWord->setEnabled(true); + ui->toolButtonUseUnicodeProperties->blockSignals(true); + ui->toolButtonUseUnicodeProperties->setChecked(false); + ui->toolButtonUseUnicodeProperties->blockSignals(false); + ui->toolButtonUseUnicodeProperties->setEnabled(false); + } + m_search->Find(ui->lineEditFind->text()); + ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder()); + }); + + connect(ui->toolButtonUseUnicodeProperties, &QToolButton::toggled, this, [this](bool checked) + { + m_search->SetUseUnicodePreperties(checked); + m_search->Find(ui->lineEditFind->text()); + }); + + m_searchHistory->setStyleSheet(QStringLiteral("QMenu { menu-scrollable: 1; }")); + InitSearchHistory(); + ui->pushButtonSearch->setMenu(m_searchHistory); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFinalMeasurements::InitSearchHistory() +{ + QStringList searchHistory = + VAbstractValApplication::VApp()->ValentinaSettings()->GetFinalMeasurementsSearchHistory(); + m_searchHistory->clear(); + for (const auto& term : searchHistory) + { + QAction *action = m_searchHistory->addAction(term); + action->setData(term); + connect(action, &QAction::triggered, this, [this]() + { + auto *action = qobject_cast(sender()); + if (action != nullptr) + { + QString term = action->data().toString(); + ui->lineEditFind->setText(term); + m_search->Find(term); + ui->lineEditFind->setFocus(); + } + }); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFinalMeasurements::SaveSearchRequest() +{ + QStringList searchHistory = + VAbstractValApplication::VApp()->ValentinaSettings()->GetFinalMeasurementsSearchHistory(); + QString term = ui->lineEditFind->text(); + if (term.isEmpty()) + { + return; + } + + searchHistory.removeAll(term); + searchHistory.prepend(term); + while (searchHistory.size() > VTableSearch::MaxHistoryRecords) + { + searchHistory.removeLast(); + } + VAbstractValApplication::VApp()->ValentinaSettings()->SetFinalMeasurementsSearchHistory(searchHistory); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogFinalMeasurements::UpdateSearchControlsTooltips() +{ + auto UpdateToolTip = [](QAbstractButton *button) + { + button->setToolTip(button->toolTip().arg(button->shortcut().toString(QKeySequence::NativeText))); + }; + + UpdateToolTip(ui->toolButtonCaseSensitive); + UpdateToolTip(ui->toolButtonWholeWord); + UpdateToolTip(ui->toolButtonRegexp); + UpdateToolTip(ui->toolButtonUseUnicodeProperties); + UpdateToolTip(ui->pushButtonSearch); + UpdateToolTip(ui->toolButtonFindPrevious); + UpdateToolTip(ui->toolButtonFindNext); +} diff --git a/src/app/valentina/dialogs/dialogfinalmeasurements.h b/src/app/valentina/dialogs/dialogfinalmeasurements.h index 0563f69e3..c7408b70f 100644 --- a/src/app/valentina/dialogs/dialogfinalmeasurements.h +++ b/src/app/valentina/dialogs/dialogfinalmeasurements.h @@ -79,6 +79,8 @@ private: int formulaBaseHeight{0}; bool m_isInitialized{false}; + QMenu *m_searchHistory; + void FillFinalMeasurements(bool freshCall = false); void ShowUnits(); @@ -91,6 +93,11 @@ private: void UpdateTree(); qreal EvalFormula(const QString &formula, bool &ok); + + void InitSearch(); + void InitSearchHistory(); + void SaveSearchRequest(); + void UpdateSearchControlsTooltips(); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/valentina/dialogs/dialogfinalmeasurements.ui b/src/app/valentina/dialogs/dialogfinalmeasurements.ui index 28342a077..90a889ea0 100644 --- a/src/app/valentina/dialogs/dialogfinalmeasurements.ui +++ b/src/app/valentina/dialogs/dialogfinalmeasurements.ui @@ -19,46 +19,240 @@ - - - 0 - + - + + + + 0 + 0 + + + + <html><head/><body><p>Search history <span style=" color:#888a85;">%1</span></p></body></html> + - Find: + + + + + .. + + + Alt+Down - - <html><head/><body><p>Search final measurements by term. </p><p>Prepend &quot;/r/&quot; to the front of the search string to search final measurements by regex.</p></body></html> + + true Search + + true + + + + + + + Qt::Vertical + + + + + + + 0 results + + + + + + + Qt::Vertical + + + + + + + + 24 + 24 + + + + + 14 + 75 + false + true + + + + <html><head/><body><p>Match Case <span style=" color:#888a85;">%1</span></p></body></html> + + + Cc + + + Alt+C + + + true + + + false + + + + + + + + 24 + 24 + + + + + 14 + 75 + true + + + + <html><head/><body><p>Match words <span style=" color:#888a85;">%1</span></p></body></html> + + + W + + + Alt+W + + + true + + + + + + + + 0 + 0 + + + + + 24 + 24 + + + + + 14 + 75 + true + + + + <html><head/><body><p>Match with regular expressions <span style=" color:#888a85;">%1</span></p></body></html> + + + .* + + + Alt+X + + + true + + + + + + + false + + + + 24 + 24 + + + + + 14 + 75 + true + + + + <html><head/><body><p>Use unicode properties <span style=" color:#888a85;">%1</span></p><p><br/><span style=" color:#888a85;">The meaning of the \w, \d, etc., character classes, as well as the meaning of their counterparts (\W, \D, etc.), is changed from matching ASCII characters only to matching any character with the corresponding Unicode property. For instance, \d is changed to match any character with the Unicode Nd (decimal digit) property; \w to match any character with either the Unicode L (letter) or N (digit) property, plus underscore, and so on. This option corresponds to the /u modifier in Perl regular expressions.</span></p></body></html> + + + U + + + Alt+U + + + true + + + + + + + Qt::Vertical + + + false + + + <html><head/><body><p>Find Previous <span style=" color:#888a85;">%1</span></p></body></html> + ... - - :/icons/win.icon.theme/16x16/actions/go-previous.png:/icons/win.icon.theme/16x16/actions/go-previous.png + + .. + + + Shift+F3 + + false + + + <html><head/><body><p>Find Next %1</p></body></html> + ... - - :/icons/win.icon.theme/16x16/actions/go-next.png:/icons/win.icon.theme/16x16/actions/go-next.png + + .. + + + F3 + + + false @@ -100,12 +294,12 @@ false - - 120 - 70 + + 120 + false @@ -118,12 +312,12 @@ false - - 25 - 8 + + 25 + false @@ -450,7 +644,6 @@ - diff --git a/src/app/valentina/dialogs/dialoghistory.cpp b/src/app/valentina/dialogs/dialoghistory.cpp index 66d0338a2..20fc03cf7 100644 --- a/src/app/valentina/dialogs/dialoghistory.cpp +++ b/src/app/valentina/dialogs/dialoghistory.cpp @@ -41,6 +41,7 @@ #include "../xml/vpattern.h" #include "../vmisc/diagnostic.h" #include "../vmisc/vtablesearch.h" +#include "../vmisc/vvalentinasettings.h" #include #include @@ -54,8 +55,10 @@ * @param parent parent widget */ DialogHistory::DialogHistory(VContainer *data, VPattern *doc, QWidget *parent) - :DialogTool(data, 0, parent), ui(new Ui::DialogHistory), doc(doc), cursorRow(0), - cursorToolRecordRow(0) + :DialogTool(data, 0, parent), + ui(new Ui::DialogHistory), + doc(doc), + m_searchHistory(new QMenu(this)) { ui->setupUi(this); @@ -74,26 +77,13 @@ DialogHistory::DialogHistory(VContainer *data, VPattern *doc, QWidget *parent) connect(doc, &VPattern::patternChanged, this, &DialogHistory::UpdateHistory); ShowPoint(); - m_search = QSharedPointer(new VTableSearch(ui->tableWidget)); - - connect(ui->lineEditFind, &QLineEdit::textEdited, this, [this](const QString &term){m_search->Find(term);}); - connect(ui->toolButtonFindPrevious, &QToolButton::clicked, this, [this](){m_search->FindPrevious();}); - connect(ui->toolButtonFindNext, &QToolButton::clicked, this, [this](){m_search->FindNext();}); - - connect(m_search.data(), &VTableSearch::HasResult, this, [this] (bool state) - { - ui->toolButtonFindPrevious->setEnabled(state); - }); - - connect(m_search.data(), &VTableSearch::HasResult, this, [this] (bool state) - { - ui->toolButtonFindNext->setEnabled(state); - }); + InitSearch(); } //--------------------------------------------------------------------------------------------------------------------- DialogHistory::~DialogHistory() { + ui->lineEditFind->blockSignals(true); // prevents crash delete ui; } @@ -554,6 +544,13 @@ void DialogHistory::closeEvent(QCloseEvent *event) QTableWidgetItem *item = ui->tableWidget->item(cursorToolRecordRow, 0); quint32 id = qvariant_cast(item->data(Qt::UserRole)); emit ShowHistoryTool(id, false); + + VValentinaSettings *settings = VAbstractValApplication::VApp()->ValentinaSettings(); + settings->SetHistorySearchOptionMatchCase(m_search->IsMatchCase()); + settings->SetHistorySearchOptionWholeWord(m_search->IsMatchWord()); + settings->SetHistorySearchOptionRegexp(m_search->IsMatchRegexp()); + settings->SetHistorySearchOptionUseUnicodeProperties(m_search->IsUseUnicodePreperties()); + DialogTool::closeEvent(event); } @@ -589,6 +586,8 @@ void DialogHistory::RetranslateUi() cursorRow = currentRow; cellClicked(cursorRow, 0); + ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder()); + UpdateSearchControlsTooltips(); } //--------------------------------------------------------------------------------------------------------------------- @@ -611,3 +610,181 @@ int DialogHistory::CursorRow() const } return ui->tableWidget->rowCount()-1; } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogHistory::InitSearch() +{ + m_search = QSharedPointer(new VTableSearch(ui->tableWidget)); + + VValentinaSettings *settings = VAbstractValApplication::VApp()->ValentinaSettings(); + m_search->SetUseUnicodePreperties(settings->GetHistorySearchOptionUseUnicodeProperties()); + m_search->SetMatchWord(settings->GetHistorySearchOptionWholeWord()); + m_search->SetMatchRegexp(settings->GetHistorySearchOptionRegexp()); + m_search->SetMatchCase(settings->GetHistorySearchOptionMatchCase()); + + ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder()); + + UpdateSearchControlsTooltips(); + + connect(ui->lineEditFind, &QLineEdit::textEdited, this, [this](const QString &term){m_search->Find(term);}); + connect(ui->lineEditFind, &QLineEdit::editingFinished, this, [this]() + { + SaveSearchRequest(); + InitSearchHistory(); + m_search->Find(ui->lineEditFind->text()); + }); + connect(ui->toolButtonFindPrevious, &QToolButton::clicked, this, [this]() + { + SaveSearchRequest(); + InitSearchHistory(); + m_search->FindPrevious(); + ui->labelResults->setText(QString("%1/%2").arg(m_search->MatchIndex()+1).arg(m_search->MatchCount())); + }); + connect(ui->toolButtonFindNext, &QToolButton::clicked, this, [this]() + { + SaveSearchRequest(); + InitSearchHistory(); + m_search->FindNext(); + ui->labelResults->setText(QString("%1/%2").arg(m_search->MatchIndex()+1).arg(m_search->MatchCount())); + }); + + connect(m_search.data(), &VTableSearch::HasResult, this, [this] (bool state) + { + ui->toolButtonFindPrevious->setEnabled(state); + ui->toolButtonFindNext->setEnabled(state); + + if (state) + { + ui->labelResults->setText(QString("%1/%2").arg(m_search->MatchIndex()+1).arg(m_search->MatchCount())); + } + else + { + ui->labelResults->setText(tr("0 results")); + } + + QPalette palette; + + if (not state && not ui->lineEditFind->text().isEmpty()) + { + palette.setColor(QPalette::Text, Qt::red); + ui->lineEditFind->setPalette(palette); + + palette.setColor(QPalette::Active, ui->labelResults->foregroundRole(), Qt::red); + palette.setColor(QPalette::Inactive, ui->labelResults->foregroundRole(), Qt::red); + ui->labelResults->setPalette(palette); + } + else + { + ui->lineEditFind->setPalette(palette); + ui->labelResults->setPalette(palette); + } + }); + + connect(ui->toolButtonCaseSensitive, &QToolButton::toggled, this, [this](bool checked) + { + m_search->SetMatchCase(checked); + m_search->Find(ui->lineEditFind->text()); + ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder()); + }); + + connect(ui->toolButtonWholeWord, &QToolButton::toggled, this, [this](bool checked) + { + m_search->SetMatchWord(checked); + m_search->Find(ui->lineEditFind->text()); + ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder()); + }); + + connect(ui->toolButtonRegexp, &QToolButton::toggled, this, [this](bool checked) + { + m_search->SetMatchRegexp(checked); + + if (checked) + { + ui->toolButtonWholeWord->blockSignals(true); + ui->toolButtonWholeWord->setChecked(false); + ui->toolButtonWholeWord->blockSignals(false); + ui->toolButtonWholeWord->setEnabled(false); + + ui->toolButtonUseUnicodeProperties->setEnabled(true); + } + else + { + ui->toolButtonWholeWord->setEnabled(true); + ui->toolButtonUseUnicodeProperties->blockSignals(true); + ui->toolButtonUseUnicodeProperties->setChecked(false); + ui->toolButtonUseUnicodeProperties->blockSignals(false); + ui->toolButtonUseUnicodeProperties->setEnabled(false); + } + m_search->Find(ui->lineEditFind->text()); + ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder()); + }); + + connect(ui->toolButtonUseUnicodeProperties, &QToolButton::toggled, this, [this](bool checked) + { + m_search->SetUseUnicodePreperties(checked); + m_search->Find(ui->lineEditFind->text()); + }); + + m_searchHistory->setStyleSheet(QStringLiteral("QMenu { menu-scrollable: 1; }")); + InitSearchHistory(); + ui->pushButtonSearch->setMenu(m_searchHistory); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogHistory::InitSearchHistory() +{ + QStringList searchHistory = VAbstractValApplication::VApp()->ValentinaSettings()->GetHistorySearchHistory(); + m_searchHistory->clear(); + for (const auto& term : searchHistory) + { + QAction *action = m_searchHistory->addAction(term); + action->setData(term); + connect(action, &QAction::triggered, this, [this]() + { + auto *action = qobject_cast(sender()); + if (action != nullptr) + { + QString term = action->data().toString(); + ui->lineEditFind->setText(term); + m_search->Find(term); + ui->lineEditFind->setFocus(); + } + }); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogHistory::SaveSearchRequest() +{ + QStringList searchHistory = VAbstractValApplication::VApp()->ValentinaSettings()->GetHistorySearchHistory(); + QString term = ui->lineEditFind->text(); + if (term.isEmpty()) + { + return; + } + + searchHistory.removeAll(term); + searchHistory.prepend(term); + while (searchHistory.size() > VTableSearch::MaxHistoryRecords) + { + searchHistory.removeLast(); + } + VAbstractValApplication::VApp()->ValentinaSettings()->SetHistorySearchHistory(searchHistory); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogHistory::UpdateSearchControlsTooltips() +{ + auto UpdateToolTip = [](QAbstractButton *button) + { + button->setToolTip(button->toolTip().arg(button->shortcut().toString(QKeySequence::NativeText))); + }; + + UpdateToolTip(ui->toolButtonCaseSensitive); + UpdateToolTip(ui->toolButtonWholeWord); + UpdateToolTip(ui->toolButtonRegexp); + UpdateToolTip(ui->toolButtonUseUnicodeProperties); + UpdateToolTip(ui->pushButtonSearch); + UpdateToolTip(ui->toolButtonFindPrevious); + UpdateToolTip(ui->toolButtonFindNext); +} diff --git a/src/app/valentina/dialogs/dialoghistory.h b/src/app/valentina/dialogs/dialoghistory.h index a8dedb14d..d1c557312 100644 --- a/src/app/valentina/dialogs/dialoghistory.h +++ b/src/app/valentina/dialogs/dialoghistory.h @@ -87,12 +87,14 @@ private: VPattern *doc; /** @brief cursorRow save number of row where is cursor */ - qint32 cursorRow; + qint32 cursorRow{0}; /** @brief cursorToolRecordRow save number of row selected record */ - qint32 cursorToolRecordRow; + qint32 cursorToolRecordRow{0}; QSharedPointer m_search{}; + QMenu *m_searchHistory; + void FillTable(); HistoryRecord Record(const VToolRecord &tool) const; void InitialTable(); @@ -101,6 +103,11 @@ private: quint32 AttrUInt(const QDomElement &domElement, const QString &name) const; void RetranslateUi(); int CursorRow() const; + + void InitSearch(); + void InitSearchHistory(); + void SaveSearchRequest(); + void UpdateSearchControlsTooltips(); }; #endif // DIALOGHISTORY_H diff --git a/src/app/valentina/dialogs/dialoghistory.ui b/src/app/valentina/dialogs/dialoghistory.ui index dd2d00878..43bd2b5fd 100644 --- a/src/app/valentina/dialogs/dialoghistory.ui +++ b/src/app/valentina/dialogs/dialoghistory.ui @@ -9,8 +9,8 @@ 0 0 - 488 - 420 + 701 + 694 @@ -25,11 +25,27 @@ - + - + + + + 0 + 0 + + + + <html><head/><body><p>Search history <span style=" color:#888a85;">%1</span></p></body></html> + - Find: + + + + + .. + + + Alt+Down @@ -38,12 +54,169 @@ true - - <html><head/><body><p>Search measurements by term. </p><p>Prepend &quot;/r/&quot; to the front of the search string to search history records by regex.</p></body></html> - Search + + true + + + + + + + Qt::Vertical + + + + + + + 0 results + + + + + + + Qt::Vertical + + + + + + + + 24 + 24 + + + + + 14 + 75 + false + true + + + + <html><head/><body><p>Match Case <span style=" color:#888a85;">%1</span></p></body></html> + + + Cc + + + Alt+C + + + true + + + false + + + + + + + + 24 + 24 + + + + + 14 + 75 + true + + + + <html><head/><body><p>Match words <span style=" color:#888a85;">%1</span></p></body></html> + + + W + + + Alt+W + + + true + + + + + + + + 0 + 0 + + + + + 24 + 24 + + + + + 14 + 75 + true + + + + <html><head/><body><p>Match with regular expressions <span style=" color:#888a85;">%1</span></p></body></html> + + + .* + + + Alt+X + + + true + + + + + + + false + + + + 24 + 24 + + + + + 14 + 75 + true + + + + <html><head/><body><p>Use unicode properties <span style=" color:#888a85;">%1</span></p><p><br/><span style=" color:#888a85;">The meaning of the \w, \d, etc., character classes, as well as the meaning of their counterparts (\W, \D, etc.), is changed from matching ASCII characters only to matching any character with the corresponding Unicode property. For instance, \d is changed to match any character with the Unicode Nd (decimal digit) property; \w to match any character with either the Unicode L (letter) or N (digit) property, plus underscore, and so on. This option corresponds to the /u modifier in Perl regular expressions.</span></p></body></html> + + + U + + + Alt+U + + + true + + + + + + + Qt::Vertical + @@ -52,17 +225,17 @@ false - Find Previous + <html><head/><body><p>Find Previous <span style=" color:#888a85;">%1</span></p></body></html> ... - - ../../tape../../tape + + .. - Ctrl+Shift+G + Shift+F3 @@ -72,17 +245,17 @@ false - Find Next + <html><head/><body><p>Find Next %1</p></body></html> ... - - ../../tape../../tape + + .. - Ctrl+G + F3 false @@ -136,8 +309,14 @@ + lineEditFind + pushButtonSearch + toolButtonCaseSensitive + toolButtonWholeWord + toolButtonRegexp + toolButtonFindPrevious + toolButtonFindNext tableWidget - buttonBox diff --git a/src/app/valentina/dialogs/dialogincrements.cpp b/src/app/valentina/dialogs/dialogincrements.cpp index adf88c226..cadd09717 100644 --- a/src/app/valentina/dialogs/dialogincrements.cpp +++ b/src/app/valentina/dialogs/dialogincrements.cpp @@ -61,12 +61,8 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par data(data), doc(doc), m_completeData(doc->GetCompleteData()), - formulaBaseHeight(0), - formulaBaseHeightPC(0), - search(), - searchPC(), - hasChanges(false), - renameList() + m_searchHistory(new QMenu(this)), + m_searchHistoryPC(new QMenu(this)) { ui->setupUi(this); @@ -75,15 +71,13 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par #endif ui->lineEditName->setClearButtonEnabled(true); - ui->lineEditFind->setClearButtonEnabled(true); ui->lineEditNamePC->setClearButtonEnabled(true); - ui->lineEditFindPC->setClearButtonEnabled(true); ui->lineEditFind->installEventFilter(this); ui->lineEditFindPC->installEventFilter(this); - search = QSharedPointer(new VTableSearch(ui->tableWidgetIncrement)); - searchPC = QSharedPointer(new VTableSearch(ui->tableWidgetPC)); + m_search = QSharedPointer(new VTableSearch(ui->tableWidgetIncrement)); + m_searchPC = QSharedPointer(new VTableSearch(ui->tableWidgetPC)); formulaBaseHeight = ui->plainTextEditFormula->height(); ui->plainTextEditFormula->installEventFilter(this); @@ -137,34 +131,10 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par connect(ui->plainTextEditDescriptionPC, &QPlainTextEdit::textChanged, this, &DialogIncrements::SaveIncrDescription); connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogIncrements::SaveIncrFormula); connect(ui->plainTextEditFormulaPC, &QPlainTextEdit::textChanged, this, &DialogIncrements::SaveIncrFormula); - connect(ui->lineEditFind, &QLineEdit::textEdited, this, [this](const QString &term){search->Find(term);}); - connect(ui->lineEditFindPC, &QLineEdit::textEdited, this, [this](const QString &term){searchPC->Find(term);}); - connect(ui->toolButtonFindPrevious, &QToolButton::clicked, this, [this](){search->FindPrevious();}); - connect(ui->toolButtonFindPreviousPC, &QToolButton::clicked, this, [this](){searchPC->FindPrevious();}); - connect(ui->toolButtonFindNext, &QToolButton::clicked, this, [this](){search->FindNext();}); - connect(ui->toolButtonFindNextPC, &QToolButton::clicked, this, [this](){searchPC->FindNext();}); connect(ui->pushButtonRefresh, &QPushButton::clicked, this, &DialogIncrements::RefreshPattern); connect(ui->pushButtonRefreshPC, &QPushButton::clicked, this, &DialogIncrements::RefreshPattern); - connect(search.data(), &VTableSearch::HasResult, this, [this] (bool state) - { - ui->toolButtonFindPrevious->setEnabled(state); - }); - - connect(searchPC.data(), &VTableSearch::HasResult, this, [this] (bool state) - { - ui->toolButtonFindPreviousPC->setEnabled(state); - }); - - connect(search.data(), &VTableSearch::HasResult, this, [this] (bool state) - { - ui->toolButtonFindNext->setEnabled(state); - }); - - connect(searchPC.data(), &VTableSearch::HasResult, this, [this] (bool state) - { - ui->toolButtonFindNextPC->setEnabled(state); - }); + InitSearch(); if (ui->tableWidgetIncrement->rowCount() > 0) { @@ -627,8 +597,8 @@ void DialogIncrements::LocalUpdateTree() ui->tableWidgetPC->selectRow(row); ui->tableWidgetPC->blockSignals(false); - search->RefreshList(ui->lineEditFind->text()); - searchPC->RefreshList(ui->lineEditFindPC->text()); + m_search->RefreshList(ui->lineEditFind->text()); + m_searchPC->RefreshList(ui->lineEditFindPC->text()); } //--------------------------------------------------------------------------------------------------------------------- @@ -813,6 +783,344 @@ void DialogIncrements::AddNewIncrement(IncrementType type) table->repaint(); // Force repain to fix paint artifacts on Mac OS X } +//--------------------------------------------------------------------------------------------------------------------- +void DialogIncrements::InitSearch() +{ + VValentinaSettings *settings = VAbstractValApplication::VApp()->ValentinaSettings(); + + m_search->SetUseUnicodePreperties(settings->GetIncrementsSearchOptionUseUnicodeProperties()); + m_search->SetMatchWord(settings->GetIncrementsSearchOptionWholeWord()); + m_search->SetMatchRegexp(settings->GetIncrementsSearchOptionRegexp()); + m_search->SetMatchCase(settings->GetIncrementsSearchOptionMatchCase()); + + m_searchPC->SetUseUnicodePreperties(settings->GetPreviewCalculationsSearchOptionUseUnicodeProperties()); + m_searchPC->SetMatchWord(settings->GetPreviewCalculationsSearchOptionWholeWord()); + m_searchPC->SetMatchRegexp(settings->GetPreviewCalculationsSearchOptionRegexp()); + m_searchPC->SetMatchCase(settings->GetPreviewCalculationsSearchOptionMatchCase()); + + ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder()); + ui->lineEditFindPC->setPlaceholderText(m_searchPC->SearchPlaceholder()); + + UpdateSearchControlsTooltips(); + + connect(ui->lineEditFind, &QLineEdit::textEdited, this, [this](const QString &term){m_search->Find(term);}); + connect(ui->lineEditFind, &QLineEdit::editingFinished, this, [this]() + { + SaveIncrementsSearchRequest(); + InitIncrementsSearchHistory(); + m_search->Find(ui->lineEditFind->text()); + }); + connect(ui->lineEditFindPC, &QLineEdit::textEdited, this, [this](const QString &term){m_searchPC->Find(term);}); + connect(ui->lineEditFindPC, &QLineEdit::editingFinished, this, [this]() + { + SavePreviewCalculationsSearchRequest(); + InitPreviewCalculationsSearchHistory(); + m_searchPC->Find(ui->lineEditFindPC->text()); + }); + + connect(ui->toolButtonFindPrevious, &QToolButton::clicked, this, [this]() + { + SaveIncrementsSearchRequest(); + InitPreviewCalculationsSearchHistory(); + m_search->FindPrevious(); + ui->labelResults->setText(QString("%1/%2").arg(m_search->MatchIndex()+1).arg(m_search->MatchCount())); + }); + connect(ui->toolButtonFindPreviousPC, &QToolButton::clicked, this, [this]() + { + SavePreviewCalculationsSearchRequest(); + InitPreviewCalculationsSearchHistory(); + m_searchPC->FindPrevious(); + ui->labelResultsPC->setText(QString("%1/%2").arg(m_searchPC->MatchIndex()+1).arg(m_searchPC->MatchCount())); + }); + connect(ui->toolButtonFindNext, &QToolButton::clicked, this, [this]() + { + SaveIncrementsSearchRequest(); + InitIncrementsSearchHistory(); + m_search->FindNext(); + ui->labelResults->setText(QString("%1/%2").arg(m_search->MatchIndex()+1).arg(m_search->MatchCount())); + }); + connect(ui->toolButtonFindNextPC, &QToolButton::clicked, this, [this]() + { + SavePreviewCalculationsSearchRequest(); + InitPreviewCalculationsSearchHistory(); + m_searchPC->FindNext(); + ui->labelResultsPC->setText(QString("%1/%2").arg(m_searchPC->MatchIndex()+1).arg(m_searchPC->MatchCount())); + }); + + connect(m_search.data(), &VTableSearch::HasResult, this, [this] (bool state) + { + ui->toolButtonFindPrevious->setEnabled(state); + ui->toolButtonFindNext->setEnabled(state); + + if (state) + { + ui->labelResults->setText(QString("%1/%2").arg(m_search->MatchIndex()+1).arg(m_search->MatchCount())); + } + else + { + ui->labelResults->setText(tr("0 results")); + } + + QPalette palette; + + if (not state && not ui->lineEditFind->text().isEmpty()) + { + palette.setColor(QPalette::Text, Qt::red); + ui->lineEditFind->setPalette(palette); + + palette.setColor(QPalette::Active, ui->labelResults->foregroundRole(), Qt::red); + palette.setColor(QPalette::Inactive, ui->labelResults->foregroundRole(), Qt::red); + ui->labelResults->setPalette(palette); + } + else + { + ui->lineEditFind->setPalette(palette); + ui->labelResults->setPalette(palette); + } + }); + + connect(m_searchPC.data(), &VTableSearch::HasResult, this, [this] (bool state) + { + ui->toolButtonFindPreviousPC->setEnabled(state); + ui->toolButtonFindNextPC->setEnabled(state); + + if (state) + { + ui->labelResultsPC->setText(QString("%1/%2").arg(m_searchPC->MatchIndex()+1).arg(m_searchPC->MatchCount())); + } + else + { + ui->labelResultsPC->setText(tr("0 results")); + } + + QPalette palette; + + if (not state && not ui->lineEditFindPC->text().isEmpty()) + { + palette.setColor(QPalette::Text, Qt::red); + ui->lineEditFindPC->setPalette(palette); + + palette.setColor(QPalette::Active, ui->labelResultsPC->foregroundRole(), Qt::red); + palette.setColor(QPalette::Inactive, ui->labelResultsPC->foregroundRole(), Qt::red); + ui->labelResultsPC->setPalette(palette); + } + else + { + ui->lineEditFindPC->setPalette(palette); + ui->labelResultsPC->setPalette(palette); + } + }); + + connect(ui->toolButtonCaseSensitive, &QToolButton::toggled, this, [this](bool checked) + { + m_search->SetMatchCase(checked); + m_search->Find(ui->lineEditFind->text()); + ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder()); + }); + + connect(ui->toolButtonCaseSensitivePC, &QToolButton::toggled, this, [this](bool checked) + { + m_searchPC->SetMatchCase(checked); + m_searchPC->Find(ui->lineEditFindPC->text()); + ui->lineEditFindPC->setPlaceholderText(m_searchPC->SearchPlaceholder()); + }); + + connect(ui->toolButtonWholeWord, &QToolButton::toggled, this, [this](bool checked) + { + m_search->SetMatchWord(checked); + m_search->Find(ui->lineEditFind->text()); + ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder()); + }); + + connect(ui->toolButtonWholeWordPC, &QToolButton::toggled, this, [this](bool checked) + { + m_searchPC->SetMatchWord(checked); + m_searchPC->Find(ui->lineEditFindPC->text()); + ui->lineEditFindPC->setPlaceholderText(m_searchPC->SearchPlaceholder()); + }); + + connect(ui->toolButtonRegexp, &QToolButton::toggled, this, [this](bool checked) + { + m_search->SetMatchRegexp(checked); + + if (checked) + { + ui->toolButtonWholeWord->blockSignals(true); + ui->toolButtonWholeWord->setChecked(false); + ui->toolButtonWholeWord->blockSignals(false); + ui->toolButtonWholeWord->setEnabled(false); + + ui->toolButtonUseUnicodeProperties->setEnabled(true); + } + else + { + ui->toolButtonWholeWord->setEnabled(true); + ui->toolButtonUseUnicodeProperties->blockSignals(true); + ui->toolButtonUseUnicodeProperties->setChecked(false); + ui->toolButtonUseUnicodeProperties->blockSignals(false); + ui->toolButtonUseUnicodeProperties->setEnabled(false); + } + m_search->Find(ui->lineEditFind->text()); + ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder()); + }); + + connect(ui->toolButtonRegexpPC, &QToolButton::toggled, this, [this](bool checked) + { + m_searchPC->SetMatchRegexp(checked); + + if (checked) + { + ui->toolButtonWholeWordPC->blockSignals(true); + ui->toolButtonWholeWordPC->setChecked(false); + ui->toolButtonWholeWordPC->blockSignals(false); + ui->toolButtonWholeWordPC->setEnabled(false); + + ui->toolButtonUseUnicodePropertiesPC->setEnabled(true); + } + else + { + ui->toolButtonWholeWordPC->setEnabled(true); + ui->toolButtonUseUnicodePropertiesPC->blockSignals(true); + ui->toolButtonUseUnicodePropertiesPC->setChecked(false); + ui->toolButtonUseUnicodePropertiesPC->blockSignals(false); + ui->toolButtonUseUnicodePropertiesPC->setEnabled(false); + } + m_searchPC->Find(ui->lineEditFindPC->text()); + ui->lineEditFindPC->setPlaceholderText(m_searchPC->SearchPlaceholder()); + }); + + connect(ui->toolButtonUseUnicodeProperties, &QToolButton::toggled, this, [this](bool checked) + { + m_search->SetUseUnicodePreperties(checked); + m_search->Find(ui->lineEditFind->text()); + }); + + connect(ui->toolButtonUseUnicodePropertiesPC, &QToolButton::toggled, this, [this](bool checked) + { + m_searchPC->SetUseUnicodePreperties(checked); + m_searchPC->Find(ui->lineEditFindPC->text()); + }); + + m_searchHistory->setStyleSheet(QStringLiteral("QMenu { menu-scrollable: 1; }")); + m_searchHistoryPC->setStyleSheet(QStringLiteral("QMenu { menu-scrollable: 1; }")); + + InitIncrementsSearchHistory(); + InitPreviewCalculationsSearchHistory(); + + ui->pushButtonSearch->setMenu(m_searchHistory); + ui->pushButtonSearchPC->setMenu(m_searchHistoryPC); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogIncrements::InitIncrementsSearchHistory() +{ + QStringList searchHistory = VAbstractValApplication::VApp()->ValentinaSettings()->GetIncrementsSearchHistory(); + m_searchHistory->clear(); + for (const auto& term : searchHistory) + { + QAction *action = m_searchHistory->addAction(term); + action->setData(term); + connect(action, &QAction::triggered, this, [this]() + { + auto *action = qobject_cast(sender()); + if (action != nullptr) + { + QString term = action->data().toString(); + ui->lineEditFind->setText(term); + m_search->Find(term); + ui->lineEditFind->setFocus(); + } + }); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogIncrements::InitPreviewCalculationsSearchHistory() +{ + QStringList searchHistory = + VAbstractValApplication::VApp()->ValentinaSettings()->GetPreviewCalculationsSearchHistory(); + m_searchHistoryPC->clear(); + for (const auto& term : searchHistory) + { + QAction *action = m_searchHistoryPC->addAction(term); + action->setData(term); + connect(action, &QAction::triggered, this, [this]() + { + auto *action = qobject_cast(sender()); + if (action != nullptr) + { + QString term = action->data().toString(); + ui->lineEditFindPC->setText(term); + m_searchPC->Find(term); + ui->lineEditFindPC->setFocus(); + } + }); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogIncrements::SaveIncrementsSearchRequest() +{ + QStringList searchHistory = VAbstractValApplication::VApp()->ValentinaSettings()->GetIncrementsSearchHistory(); + QString term = ui->lineEditFind->text(); + if (term.isEmpty()) + { + return; + } + + searchHistory.removeAll(term); + searchHistory.prepend(term); + while (searchHistory.size() > VTableSearch::MaxHistoryRecords) + { + searchHistory.removeLast(); + } + VAbstractValApplication::VApp()->ValentinaSettings()->SetIncrementsSearchHistory(searchHistory); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogIncrements::SavePreviewCalculationsSearchRequest() +{ + QStringList searchHistory = VAbstractValApplication::VApp()->ValentinaSettings()->GetPreviewCalculationsSearchHistory(); + QString term = ui->lineEditFindPC->text(); + if (term.isEmpty()) + { + return; + } + + searchHistory.removeAll(term); + searchHistory.prepend(term); + while (searchHistory.size() > VTableSearch::MaxHistoryRecords) + { + searchHistory.removeLast(); + } + VAbstractValApplication::VApp()->ValentinaSettings()->SetPreviewCalculationsSearchHistory(searchHistory); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogIncrements::UpdateSearchControlsTooltips() +{ + auto UpdateToolTip = [](QAbstractButton *button) + { + button->setToolTip(button->toolTip().arg(button->shortcut().toString(QKeySequence::NativeText))); + }; + + UpdateToolTip(ui->toolButtonCaseSensitive); + UpdateToolTip(ui->toolButtonWholeWord); + UpdateToolTip(ui->toolButtonRegexp); + UpdateToolTip(ui->toolButtonUseUnicodeProperties); + UpdateToolTip(ui->pushButtonSearch); + UpdateToolTip(ui->toolButtonFindPrevious); + UpdateToolTip(ui->toolButtonFindNext); + + UpdateToolTip(ui->toolButtonCaseSensitivePC); + UpdateToolTip(ui->toolButtonWholeWordPC); + UpdateToolTip(ui->toolButtonRegexpPC); + UpdateToolTip(ui->toolButtonUseUnicodePropertiesPC); + UpdateToolTip(ui->pushButtonSearchPC); + UpdateToolTip(ui->toolButtonFindPreviousPC); + UpdateToolTip(ui->toolButtonFindNextPC); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update information in tables form file @@ -841,8 +1149,8 @@ void DialogIncrements::FullUpdateFromFile() FillRadiusesArcs(); FillAnglesCurves(); - search->RefreshList(ui->lineEditFind->text()); - searchPC->RefreshList(ui->lineEditFindPC->text()); + m_search->RefreshList(ui->lineEditFind->text()); + m_searchPC->RefreshList(ui->lineEditFindPC->text()); ui->tableWidgetIncrement->selectRow(incrementRow); ui->tableWidgetPC->selectRow(pcRow); @@ -1412,6 +1720,18 @@ void DialogIncrements::closeEvent(QCloseEvent *event) disconnect(this->doc, &VPattern::FullUpdateFromFile, this, &DialogIncrements::FullUpdateFromFile); + VValentinaSettings *settings = VAbstractValApplication::VApp()->ValentinaSettings(); + + settings->SetIncrementsSearchOptionMatchCase(m_search->IsMatchCase()); + settings->SetIncrementsSearchOptionWholeWord(m_search->IsMatchWord()); + settings->SetIncrementsSearchOptionRegexp(m_search->IsMatchRegexp()); + settings->SetIncrementsSearchOptionUseUnicodeProperties(m_search->IsUseUnicodePreperties()); + + settings->SetPreviewCalculationsSearchOptionMatchCase(m_searchPC->IsMatchCase()); + settings->SetPreviewCalculationsSearchOptionWholeWord(m_searchPC->IsMatchWord()); + settings->SetPreviewCalculationsSearchOptionRegexp(m_searchPC->IsMatchRegexp()); + settings->SetPreviewCalculationsSearchOptionUseUnicodeProperties(m_searchPC->IsUseUnicodePreperties()); + emit UpdateProperties(); emit DialogClosed(QDialog::Accepted); event->accept(); @@ -1428,6 +1748,10 @@ void DialogIncrements::changeEvent(QEvent *event) ui->toolButtonAdd->setMenu(InitVarTypeMenu(ui->toolButtonAdd->menu(), true /*increments tab*/)); ui->toolButtonAddPC->setMenu(InitVarTypeMenu(ui->toolButtonAddPC->menu(), false /*preview calculations tab*/)); + ui->lineEditFind->setPlaceholderText(m_search->SearchPlaceholder()); + ui->lineEditFindPC->setPlaceholderText(m_searchPC->SearchPlaceholder()); + UpdateSearchControlsTooltips(); + FullUpdateFromFile(); } // remember to call base class implementation @@ -1508,6 +1832,8 @@ void DialogIncrements::ShowIncrementDetails() //--------------------------------------------------------------------------------------------------------------------- DialogIncrements::~DialogIncrements() { + ui->lineEditFind->blockSignals(true); // prevents crash + ui->lineEditFindPC->blockSignals(true); // prevents crash delete ui; } diff --git a/src/app/valentina/dialogs/dialogincrements.h b/src/app/valentina/dialogs/dialogincrements.h index eb80a056c..418da6189 100644 --- a/src/app/valentina/dialogs/dialogincrements.h +++ b/src/app/valentina/dialogs/dialogincrements.h @@ -96,15 +96,18 @@ private: /** @brief m_completeData need to show all internal variables */ VContainer m_completeData; - int formulaBaseHeight; - int formulaBaseHeightPC; + int formulaBaseHeight{0}; + int formulaBaseHeightPC{0}; - QSharedPointer search; - QSharedPointer searchPC; + QSharedPointer m_search{}; + QSharedPointer m_searchPC{}; - bool hasChanges; + bool hasChanges{false}; - QVector> renameList; + QVector> renameList{}; + + QMenu *m_searchHistory; + QMenu *m_searchHistoryPC; template void FillTable(const QMap &varTable, QTableWidget *table); @@ -148,6 +151,13 @@ private: QMenu *InitVarTypeMenu(QMenu *menu, bool incrementTab); void AddNewIncrement(IncrementType type); + + void InitSearch(); + void InitIncrementsSearchHistory(); + void InitPreviewCalculationsSearchHistory(); + void SaveIncrementsSearchRequest(); + void SavePreviewCalculationsSearchRequest(); + void UpdateSearchControlsTooltips(); }; #endif // DIALOGINCREMENTS_H diff --git a/src/app/valentina/dialogs/dialogincrements.ui b/src/app/valentina/dialogs/dialogincrements.ui index 2b7129469..0d67753d3 100644 --- a/src/app/valentina/dialogs/dialogincrements.ui +++ b/src/app/valentina/dialogs/dialogincrements.ui @@ -51,45 +51,239 @@ - - 0 - - + + + + 0 + 0 + + + + <html><head/><body><p>Search history <span style=" color:#888a85;">%1</span></p></body></html> + - Find: + + + + + .. + + + Alt+Down - - <html><head/><body><p>Search increments by term. </p><p>Prepend &quot;/r/&quot; to the front of the search string to search increments by regex.</p></body></html> + + true Search + + true + + + + + + + Qt::Vertical + + + + + + + 0 results + + + + + + + Qt::Vertical + + + + + + + + 24 + 24 + + + + + 14 + 75 + false + true + + + + <html><head/><body><p>Match Case <span style=" color:#888a85;">%1</span></p></body></html> + + + Cc + + + Alt+C + + + true + + + false + + + + + + + + 24 + 24 + + + + + 14 + 75 + true + + + + <html><head/><body><p>Match words <span style=" color:#888a85;">%1</span></p></body></html> + + + W + + + Alt+W + + + true + + + + + + + + 0 + 0 + + + + + 24 + 24 + + + + + 14 + 75 + true + + + + <html><head/><body><p>Match with regular expressions <span style=" color:#888a85;">%1</span></p></body></html> + + + .* + + + Alt+X + + + true + + + + + + + false + + + + 24 + 24 + + + + + 14 + 75 + true + + + + <html><head/><body><p>Use unicode properties <span style=" color:#888a85;">%1</span></p><p><br/><span style=" color:#888a85;">The meaning of the \w, \d, etc., character classes, as well as the meaning of their counterparts (\W, \D, etc.), is changed from matching ASCII characters only to matching any character with the corresponding Unicode property. For instance, \d is changed to match any character with the Unicode Nd (decimal digit) property; \w to match any character with either the Unicode L (letter) or N (digit) property, plus underscore, and so on. This option corresponds to the /u modifier in Perl regular expressions.</span></p></body></html> + + + U + + + Alt+U + + + true + + + + + + + Qt::Vertical + + + false + + + <html><head/><body><p>Find Previous <span style=" color:#888a85;">%1</span></p></body></html> + ... - - :/icons/win.icon.theme/16x16/actions/go-previous.png:/icons/win.icon.theme/16x16/actions/go-previous.png + + .. + + + Shift+F3 + + false + + + <html><head/><body><p>Find Next %1</p></body></html> + ... - - :/icons/win.icon.theme/16x16/actions/go-next.png:/icons/win.icon.theme/16x16/actions/go-next.png + + .. + + + F3 + + + false @@ -131,12 +325,12 @@ false - - 120 - 70 + + 120 + false @@ -149,12 +343,12 @@ false - - 25 - 8 + + 25 + false @@ -499,45 +693,239 @@ - - 0 - - + + + + 0 + 0 + + + + <html><head/><body><p>Search history <span style=" color:#888a85;">%1</span></p></body></html> + - Find: + + + + + .. + + + Alt+Down - - <html><head/><body><p>Search preview calculations by term. </p><p>Prepend &quot;/r/&quot; to the front of the search string to search preview calculations by regex.</p></body></html> + + true Search + + true + + + + + + + Qt::Vertical + + + + + + + 0 results + + + + + + + Qt::Vertical + + + + + + + + 24 + 24 + + + + + 14 + 75 + false + true + + + + <html><head/><body><p>Match Case <span style=" color:#888a85;">%1</span></p></body></html> + + + Cc + + + Alt+C + + + true + + + false + + + + + + + + 24 + 24 + + + + + 14 + 75 + true + + + + <html><head/><body><p>Match words <span style=" color:#888a85;">%1</span></p></body></html> + + + W + + + Alt+W + + + true + + + + + + + + 0 + 0 + + + + + 24 + 24 + + + + + 14 + 75 + true + + + + <html><head/><body><p>Match with regular expressions <span style=" color:#888a85;">%1</span></p></body></html> + + + .* + + + Alt+X + + + true + + + + + + + false + + + + 24 + 24 + + + + + 14 + 75 + true + + + + <html><head/><body><p>Use unicode properties <span style=" color:#888a85;">%1</span></p><p><br/><span style=" color:#888a85;">The meaning of the \w, \d, etc., character classes, as well as the meaning of their counterparts (\W, \D, etc.), is changed from matching ASCII characters only to matching any character with the corresponding Unicode property. For instance, \d is changed to match any character with the Unicode Nd (decimal digit) property; \w to match any character with either the Unicode L (letter) or N (digit) property, plus underscore, and so on. This option corresponds to the /u modifier in Perl regular expressions.</span></p></body></html> + + + U + + + Alt+U + + + true + + + + + + + Qt::Vertical + + + false + + + <html><head/><body><p>Find Previous <span style=" color:#888a85;">%1</span></p></body></html> + ... - - :/icons/win.icon.theme/16x16/actions/go-previous.png:/icons/win.icon.theme/16x16/actions/go-previous.png + + .. + + + Shift+F3 + + false + + + <html><head/><body><p>Find Next %1</p></body></html> + ... - - :/icons/win.icon.theme/16x16/actions/go-next.png:/icons/win.icon.theme/16x16/actions/go-next.png + + .. + + + F3 + + + false @@ -579,12 +967,12 @@ false - - 120 - 70 + + 120 + false @@ -597,12 +985,12 @@ false - - 25 - 8 + + 25 + false @@ -1208,7 +1596,6 @@ tableWidgetSplines - diff --git a/src/libs/vmisc/share/resources/icons/win.icon.theme/16x16/actions/system-search.png b/src/libs/vmisc/share/resources/icons/win.icon.theme/16x16/actions/system-search.png new file mode 100644 index 0000000000000000000000000000000000000000..e91d24c3463819c5e6d77553c653325ef30b4e7b GIT binary patch literal 719 zcmV;=0xPx#AY({UO#lFTCIA3{ga82g0001h=l}q9FaQARU;qF* zm;eA5aGbhPJOBUy33hNnX8-^I5C8xG5CB}pt-}BS00v@9M??Ss00000`9r&Z00009 za7bBm000tn000tn0p4aGcmMza<4Ht8R5;7c)89)|VI0Tt{SkpdT@;ulA-Jm;PU<2w z4L8KfFkz6;MIJ~5kKo4aV(xIcF###Eh z#-4Hqf0JiTR<%{ylzW&Pdnq=%Fw}OZikXP@Kef#&`zj?3cH{y!Pk;}J6%xxS zLN5|n+Q%q3B2ilJMZDnWSNpQOPB8X~6XG56%O!pT;pcPDn&r`S(c{>AT>Vd}60VbH zv~xEUPXn>|Jdu|lk*_`BxH!c25*xl?oHU@QL4=M`OpRC3*C-TLNEDPg$TQg3U*)1n z8qSOz)5eZ=va{62wgau&7CjljdHDgU)DLDBzA+JghodjTu0!^$>pE?}&D_Eg)3b|= zJbZ;9->0zBnE|ZIxK{jKoBS5H8o_ct@Sg&+^Pib~^oEN!qtvvFuva^)%rkWlQ`b7c zK}!#Ylik`&>q2jqvj9QzQ7@{Pgg%U?Jm{-C*(XUcN+iz002ovPDHLkV1g}y BF0uds literal 0 HcmV?d00001 diff --git a/src/libs/vmisc/share/resources/icons/win.icon.theme/24x24/actions/system-search.png b/src/libs/vmisc/share/resources/icons/win.icon.theme/24x24/actions/system-search.png new file mode 100755 index 0000000000000000000000000000000000000000..bd5946e0962ae316aa42bd6acca06bb336c08dd2 GIT binary patch literal 1112 zcmV-e1gHCnP)7_+J$yobp`s`~A)R{rxw6 zKA&F{MP#$t%~&kSi zR7@xxJAS_(qA0daPCk4%GBV$+j6giuPz5r)tspAf=aE|<&gc6-C&a792>d7!GQ${4eO!>*~iDvBbN zBvBRwLBi3A6F9&R4irOCN;>BpmFDmoaQE&f$mL!xr!yHP5a^X5Kq7=P(SW#xC@{{DU@ z5{Y~}FfhQf+3cBse>KqO^COpg>A8J-WIP;xKiqWn>Salic%iVfwY|MXp0B)^Xln2< zNfJMwo}T{N>-A!5YwP@g@)ITqLQQ>reVxs26Lz+DUiAh7hpE2`pI-5}zZ|^Pr)sMD zU}|dWNiZ11Y4<@mA(jEytW`YWTkfp&K4`z*{Kd^sF#GE7;{Cq9(6hn=w6(TgT3%j` zbar-{o12>_0?I+hEh?XZ2|xp&TCt50-P8>7V(*~zUR`a?hn*embbfyRm#(fZme1!; z1ymBZU@8EU5xt-pbZzgTG*Dkx`$2bC=R#9cQ*LQ#>B4|=Q2+)twKU;XYkRx98JE-X zqoS0w_4W1tAbkb>1Dyi*j8Bxh&Hw-aB6?I2D? eNY%?PN(TTo*alb-Q_5Tb0000qCN}W}p{*9( zROpJofGh%9Q>qpA_p&o{fA)ddcBPG3sP?5j$#?FZJ2!JabIv{Y4#5BRUpG|39H-mu z_WAw(wz|5yT8uF)FE206&(F=o7%jy07{qKGB@h5M3JoOS|q$32H1W-VN z3IHlX$cYfr0YRCnI-se!Nt>RY)+Qz{1PKnTpv?{5?bZAH`oaJZEH5u#R|K8`*tKgH_@zopqDx{E7QE)|9=gzHLwruf-LZOWV96$a(R8>`1ZFX-~IOl>8N-c}#neCJd zA#4c2IsZdK2H1j#w)oH1q~Kp0`9 zAcPbI08&ceLJEX{#A31R($dnSTrRiq6vX3kFbren+tHER@#VN=jC0NffLyHrAp~ZO z*{LDaB9wB@StgUBk?YqM0AR*2jEw^T030~*cJk7tOXn_rbMZHeSdvo4EJ7F|lo84p zB}`Dt1ffiD#sxw$ef8@1`RmuOpFeWsNOE1?;cqsg`T0384CB#kEXFmb7W6f@=!)u) zlrg~=lYF%T1jd+I#K_IYX6nYUuc@PI5|1_&j4%_>2zv38l8Ch(^e025aKdMvMi4 z9m~md_VwyY_x857)*aWbT^sA^=}AmYO_dDrmk`?y3X8DJPLUG;%I#D+?YR~;SE5qU z%y=@@>)Be<5)20Y~waH{^r{CAy z5eWFT;o;%2mX?-hHmc_VJTEoH5;mM^O8`I_2#zQrcPu7bGMRL!H5hm`6bg}%k&z$0 zUa!bzv+D*Z1&|j-hDpIzC}Xz`i*>B5dhHrNJO5L3!r00000 LNkvXXu0mjf^a|Y0 literal 0 HcmV?d00001 diff --git a/src/libs/vmisc/share/resources/theme.qrc b/src/libs/vmisc/share/resources/theme.qrc index ce2d67a93..7078b3c94 100644 --- a/src/libs/vmisc/share/resources/theme.qrc +++ b/src/libs/vmisc/share/resources/theme.qrc @@ -105,5 +105,8 @@ icons/win.icon.theme/16x16/actions/object-rotate-right.png icons/win.icon.theme/24x24/actions/object-rotate-right.png icons/win.icon.theme/32x32/actions/object-rotate-right.png + icons/win.icon.theme/16x16/actions/system-search.png + icons/win.icon.theme/24x24/actions/system-search.png + icons/win.icon.theme/32x32/actions/system-search.png diff --git a/src/libs/vmisc/vtablesearch.cpp b/src/libs/vmisc/vtablesearch.cpp index ca01817c9..d63d402a7 100644 --- a/src/libs/vmisc/vtablesearch.cpp +++ b/src/libs/vmisc/vtablesearch.cpp @@ -36,12 +36,12 @@ #include "../vmisc/def.h" +const int VTableSearch::MaxHistoryRecords = 10; + //--------------------------------------------------------------------------------------------------------------------- VTableSearch::VTableSearch(QTableWidget *table, QObject *parent) : QObject(parent), - table(table), - searchIndex(-1), - searchList() + table(table) { } @@ -94,44 +94,94 @@ void VTableSearch::ShowNext(int newIndex) } //--------------------------------------------------------------------------------------------------------------------- -QList VTableSearch::FindTableItems(const QString& term) +auto VTableSearch::FindTableItems(QString term) -> QList { if (term.isEmpty()) { return {}; } - if (term.startsWith(QChar('/'))) + QRegularExpression::PatternOptions options = QRegularExpression::NoPatternOption; + + if (not m_matchCase) { - QRegularExpression qre(QStringLiteral("^/(?[^/]+)/(?.+)$")); - QScopedPointer match(new QRegularExpressionMatch()); - if (!term.contains(qre, match.data())) - { - return QList(); - } + options |= QRegularExpression::CaseInsensitiveOption; + } - auto searchType = match->capturedRef(QStringLiteral("searchType")); - auto searchString = match->capturedRef(QStringLiteral("searchString")); - if (searchType == QChar('r')) - { - QString reSearchString = ".*" % searchString % ".*"; -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) - return table->findItems(reSearchString, Qt::MatchRegExp); -#else - return table->findItems(reSearchString, Qt::MatchRegularExpression); -#endif - } + if (m_matchWord) + { + options |= QRegularExpression::UseUnicodePropertiesOption; + term = "\\b" % term % "\\b"; + } + if (m_matchRegexp && m_useUnicodePreperties) + { + options |= QRegularExpression::UseUnicodePropertiesOption; + } + + QRegularExpression re(term, options); + + if(not re.isValid()) + { return {}; } - return table->findItems(term, Qt::MatchContains); + QList list; + + for (int r=0; rrowCount(); ++r) + { + for (int c=0; ccolumnCount(); ++c) + { + QTableWidgetItem *cell = table->item(r, c); + if (cell != nullptr) + { + QString text = cell->text(); + QRegularExpressionMatch match = re.match(text); + if (match.hasMatch()) + { + list.append(cell); + } + } + } + } + return list; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VTableSearch::FindCurrentMatchIndex() const -> int +{ + if (searchList.isEmpty()) + { + return 0; + } + + QList selectedItems = table->selectedItems(); + if (selectedItems.isEmpty()) + { + return 0; + } + + QTableWidgetItem* selectedItem = selectedItems.first(); + + for (int i=0; irow()>= selectedItem->row() && item->column()>= selectedItem->column()) + { + return i; + } + } + + return 0; } //--------------------------------------------------------------------------------------------------------------------- void VTableSearch::Find(const QString &term) { - SCASSERT(table != nullptr) + if(table == nullptr) + { + return; + } Clear(); @@ -144,13 +194,16 @@ void VTableSearch::Find(const QString &term) item->setBackground(Qt::yellow); } - searchIndex = 0; + searchIndex = FindCurrentMatchIndex(); QTableWidgetItem *item = searchList.at(searchIndex); item->setBackground(Qt::red); table->scrollToItem(item); emit HasResult(true); + return; } + + emit HasResult(false); } //--------------------------------------------------------------------------------------------------------------------- @@ -191,7 +244,7 @@ void VTableSearch::RemoveRow(int row) if (row <= indexRow) { - for (auto item : qAsConst(searchList)) + for (auto *item : qAsConst(searchList)) { if (item->row() == row) { @@ -213,7 +266,7 @@ void VTableSearch::AddRow(int row) if (row <= indexRow) { - for (auto item : qAsConst(searchList)) + for (auto *item : qAsConst(searchList)) { if (item->row() == row) { @@ -232,7 +285,7 @@ void VTableSearch::RefreshList(const QString &term) if (not searchList.isEmpty()) { - for (auto item : qAsConst(searchList)) + for (auto *item : qAsConst(searchList)) { item->setBackground(Qt::yellow); } @@ -257,3 +310,100 @@ void VTableSearch::RefreshList(const QString &term) emit HasResult(false); } } + +//--------------------------------------------------------------------------------------------------------------------- +void VTableSearch::SetMatchCase(bool value) +{ + m_matchCase = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VTableSearch::IsMatchCase() const -> bool +{ + return m_matchCase; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTableSearch::SetMatchWord(bool value) +{ + m_matchWord = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VTableSearch::IsMatchWord() const -> bool +{ + return m_matchWord; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTableSearch::SetMatchRegexp(bool value) +{ + m_matchRegexp = value; + m_matchWord = false; + + if (not m_matchRegexp) + { + m_useUnicodePreperties = false; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VTableSearch::IsMatchRegexp() const -> bool +{ + return m_matchRegexp; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VTableSearch::SetUseUnicodePreperties(bool value) +{ + m_useUnicodePreperties = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VTableSearch::IsUseUnicodePreperties() const -> bool +{ + return m_useUnicodePreperties; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VTableSearch::MatchIndex() const -> int +{ + return searchIndex; +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VTableSearch::MatchCount() const -> int +{ + return searchList.size(); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VTableSearch::SearchPlaceholder() const -> QString +{ + if (m_matchCase && not m_matchWord && not m_matchRegexp) + { + return tr("Match case"); + } + + if (not m_matchCase && m_matchWord && not m_matchRegexp) + { + return tr("Words"); + } + + if (not m_matchCase && m_matchRegexp) + { + return tr("Regex"); + } + + if (m_matchCase && m_matchWord) + { + return tr("Match case and words"); + } + + if (m_matchCase && m_matchRegexp) + { + return tr("Match case and regex"); + } + + return tr("Search"); +} diff --git a/src/libs/vmisc/vtablesearch.h b/src/libs/vmisc/vtablesearch.h index fb839e596..314aaf93f 100644 --- a/src/libs/vmisc/vtablesearch.h +++ b/src/libs/vmisc/vtablesearch.h @@ -48,6 +48,25 @@ public: void AddRow(int row); void RefreshList(const QString &term); + void SetMatchCase(bool value); + auto IsMatchCase() const -> bool; + + void SetMatchWord(bool value); + auto IsMatchWord() const -> bool; + + void SetMatchRegexp(bool value); + auto IsMatchRegexp() const -> bool; + + void SetUseUnicodePreperties(bool value); + auto IsUseUnicodePreperties() const -> bool; + + auto MatchIndex() const -> int; + auto MatchCount() const -> int; + + auto SearchPlaceholder() const -> QString; + + static const int MaxHistoryRecords; + signals: void HasResult(bool state); @@ -55,12 +74,18 @@ private: Q_DISABLE_COPY(VTableSearch) QTableWidget *table; - int searchIndex; - QList searchList; + int searchIndex{-1}; + QList searchList{}; + + bool m_matchCase{false}; + bool m_matchWord{false}; + bool m_matchRegexp{false}; + bool m_useUnicodePreperties{false}; void Clear(); void ShowNext(int newIndex); - QList FindTableItems(const QString& term); + auto FindTableItems(QString term) -> QList; + auto FindCurrentMatchIndex() const -> int; }; #endif // VTABLESEARCH_H diff --git a/src/libs/vmisc/vvalentinasettings.cpp b/src/libs/vmisc/vvalentinasettings.cpp index 6aa8baa18..070658471 100644 --- a/src/libs/vmisc/vvalentinasettings.cpp +++ b/src/libs/vmisc/vvalentinasettings.cpp @@ -93,7 +93,50 @@ Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDockWidgetToolOptionsActive, Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingDockWidgetPatternMessagesActive, (QLatin1String("dockWidget/patternMessagesActive"))) Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingPatternMessagesFontSize, (QLatin1String("font/patternMessagesSize"))) -} + +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchHistoryHistory, (QLatin1String("searchHistory/history"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchHistoryIncrements, (QLatin1String("searchHistory/increments"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchHistoryPreviewCalculations, + (QLatin1String("searchHistory/previewCalculations"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchHistoryFinalMeasurements, + (QLatin1String("searchHistory/finalMeasurements"))) + +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchOptionsHistoryUseUnicodeProperties, + (QLatin1String("searchOptions/historyUseUnicodeProperties"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchOptionsHistoryWholeWord, + (QLatin1String("searchOptions/historyWholeWord"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchOptionsHistoryRegexp, + (QLatin1String("searchOptions/historyRegexp"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchOptionsHistoryMatchCase, + (QLatin1String("searchOptions/historyMatchCase"))) + +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchOptionsIncrementsUseUnicodeProperties, + (QLatin1String("searchOptions/incrementsUseUnicodeProperties"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchOptionsIncrementsWholeWord, + (QLatin1String("searchOptions/incrementsWholeWord"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchOptionsIncrementsRegexp, + (QLatin1String("searchOptions/incrementsRegexp"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchOptionsIncrementsMatchCase, + (QLatin1String("searchOptions/incrementsMatchCase"))) + +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchOptionsPreviewCalculationsUseUnicodeProperties, + (QLatin1String("searchOptions/previewCalculationsUseUnicodeProperties"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchOptionsPreviewCalculationsWholeWord, + (QLatin1String("searchOptions/previewCalculationsWholeWord"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchOptionsPreviewCalculationsRegexp, + (QLatin1String("searchOptions/previewCalculationsRegexp"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchOptionsPreviewCalculationsMatchCase, + (QLatin1String("searchOptions/previewCalculationsMatchCase"))) + +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchOptionsFinalMeasurementsUseUnicodeProperties, + (QLatin1String("searchOptions/finalMeasurementsUseUnicodeProperties"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchOptionsFinalMeasurementsWholeWord, + (QLatin1String("searchOptions/finalMeasurementsWholeWord"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchOptionsFinalMeasurementsRegexp, + (QLatin1String("searchOptions/finalMeasurementsRegexp"))) +Q_GLOBAL_STATIC_WITH_ARGS(const QString, settingSearchOptionsFinalMeasurementsMatchCase, + (QLatin1String("searchOptions/finalMeasurementsMatchCase"))) +} // namespace //--------------------------------------------------------------------------------------------------------------------- VValentinaSettings::VValentinaSettings(Format format, Scope scope, const QString &organization, const QString &application, @@ -653,6 +696,246 @@ void VValentinaSettings::SetDetailExportFormat(qint8 format) setValue(*settingDetailExportFormat, format); } +//--------------------------------------------------------------------------------------------------------------------- +auto VValentinaSettings::GetHistorySearchHistory() const -> QStringList +{ + return value(*settingSearchHistoryHistory).toStringList(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VValentinaSettings::SetHistorySearchHistory(const QStringList &history) +{ + setValue(*settingSearchHistoryHistory, history); +} + +//--------------------------------------------------------------------------------------------------------------------- +QStringList VValentinaSettings::GetIncrementsSearchHistory() const +{ + return value(*settingSearchHistoryIncrements).toStringList(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VValentinaSettings::SetIncrementsSearchHistory(const QStringList &history) +{ + setValue(*settingSearchHistoryIncrements, history); +} + +//--------------------------------------------------------------------------------------------------------------------- +QStringList VValentinaSettings::GetPreviewCalculationsSearchHistory() const +{ + return value(*settingSearchHistoryPreviewCalculations).toStringList(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VValentinaSettings::SetPreviewCalculationsSearchHistory(const QStringList &history) +{ + setValue(*settingSearchHistoryPreviewCalculations, history); +} + +//--------------------------------------------------------------------------------------------------------------------- +QStringList VValentinaSettings::GetFinalMeasurementsSearchHistory() const +{ + return value(*settingSearchHistoryFinalMeasurements).toStringList(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VValentinaSettings::SetFinalMeasurementsSearchHistory(const QStringList &history) +{ + setValue(*settingSearchHistoryFinalMeasurements, history); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VValentinaSettings::GetHistorySearchOptionUseUnicodeProperties() const -> bool +{ + return value(*settingSearchOptionsHistoryUseUnicodeProperties, false).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VValentinaSettings::SetHistorySearchOptionUseUnicodeProperties(bool value) +{ + setValue(*settingSearchOptionsHistoryUseUnicodeProperties, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VValentinaSettings::GetHistorySearchOptionWholeWord() const -> bool +{ + return value(*settingSearchOptionsHistoryWholeWord, false).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VValentinaSettings::SetHistorySearchOptionWholeWord(bool value) +{ + setValue(*settingSearchOptionsHistoryWholeWord, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VValentinaSettings::GetHistorySearchOptionRegexp() const -> bool +{ + return value(*settingSearchOptionsHistoryRegexp, false).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VValentinaSettings::SetHistorySearchOptionRegexp(bool value) +{ + setValue(*settingSearchOptionsHistoryRegexp, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VValentinaSettings::GetHistorySearchOptionMatchCase() const -> bool +{ + return value(*settingSearchOptionsHistoryMatchCase, false).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VValentinaSettings::SetHistorySearchOptionMatchCase(bool value) +{ + setValue(*settingSearchOptionsHistoryMatchCase, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VValentinaSettings::GetIncrementsSearchOptionUseUnicodeProperties() const -> bool +{ + return value(*settingSearchOptionsIncrementsUseUnicodeProperties, false).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VValentinaSettings::SetIncrementsSearchOptionUseUnicodeProperties(bool value) +{ + setValue(*settingSearchOptionsIncrementsUseUnicodeProperties, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VValentinaSettings::GetIncrementsSearchOptionWholeWord() const -> bool +{ + return value(*settingSearchOptionsIncrementsWholeWord, false).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VValentinaSettings::SetIncrementsSearchOptionWholeWord(bool value) +{ + setValue(*settingSearchOptionsIncrementsWholeWord, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VValentinaSettings::GetIncrementsSearchOptionRegexp() const -> bool +{ + return value(*settingSearchOptionsIncrementsRegexp, false).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VValentinaSettings::SetIncrementsSearchOptionRegexp(bool value) +{ + setValue(*settingSearchOptionsIncrementsRegexp, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VValentinaSettings::GetIncrementsSearchOptionMatchCase() const -> bool +{ + return value(*settingSearchOptionsIncrementsMatchCase, false).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VValentinaSettings::SetIncrementsSearchOptionMatchCase(bool value) +{ + setValue(*settingSearchOptionsIncrementsMatchCase, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VValentinaSettings::GetPreviewCalculationsSearchOptionUseUnicodeProperties() const -> bool +{ + return value(*settingSearchOptionsPreviewCalculationsUseUnicodeProperties, false).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VValentinaSettings::SetPreviewCalculationsSearchOptionUseUnicodeProperties(bool value) +{ + setValue(*settingSearchOptionsPreviewCalculationsUseUnicodeProperties, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VValentinaSettings::GetPreviewCalculationsSearchOptionWholeWord() const -> bool +{ + return value(*settingSearchOptionsPreviewCalculationsWholeWord, false).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VValentinaSettings::SetPreviewCalculationsSearchOptionWholeWord(bool value) +{ + setValue(*settingSearchOptionsPreviewCalculationsWholeWord, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VValentinaSettings::GetPreviewCalculationsSearchOptionRegexp() const -> bool +{ + return value(*settingSearchOptionsPreviewCalculationsRegexp, false).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VValentinaSettings::SetPreviewCalculationsSearchOptionRegexp(bool value) +{ + setValue(*settingSearchOptionsPreviewCalculationsRegexp, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VValentinaSettings::GetPreviewCalculationsSearchOptionMatchCase() const -> bool +{ + return value(*settingSearchOptionsPreviewCalculationsMatchCase, false).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VValentinaSettings::SetPreviewCalculationsSearchOptionMatchCase(bool value) +{ + setValue(*settingSearchOptionsPreviewCalculationsMatchCase, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VValentinaSettings::GetFinalMeasurementsSearchOptionUseUnicodeProperties() const -> bool +{ + return value(*settingSearchOptionsFinalMeasurementsUseUnicodeProperties, false).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VValentinaSettings::SetFinalMeasurementsSearchOptionUseUnicodeProperties(bool value) +{ + setValue(*settingSearchOptionsFinalMeasurementsUseUnicodeProperties, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VValentinaSettings::GetFinalMeasurementsSearchOptionWholeWord() const -> bool +{ + return value(*settingSearchOptionsFinalMeasurementsWholeWord, false).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VValentinaSettings::SetFinalMeasurementsSearchOptionWholeWord(bool value) +{ + setValue(*settingSearchOptionsFinalMeasurementsWholeWord, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VValentinaSettings::GetFinalMeasurementsSearchOptionRegexp() const -> bool +{ + return value(*settingSearchOptionsFinalMeasurementsRegexp, false).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VValentinaSettings::SetFinalMeasurementsSearchOptionRegexp(bool value) +{ + setValue(*settingSearchOptionsFinalMeasurementsRegexp, value); +} + +//--------------------------------------------------------------------------------------------------------------------- +auto VValentinaSettings::GetFinalMeasurementsSearchOptionMatchCase() const -> bool +{ + return value(*settingSearchOptionsFinalMeasurementsMatchCase, false).toBool(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VValentinaSettings::SetFinalMeasurementsSearchOptionMatchCase(bool value) +{ + setValue(*settingSearchOptionsFinalMeasurementsMatchCase, value); +} + //--------------------------------------------------------------------------------------------------------------------- template T VValentinaSettings::GetCachedValue(T &cache, const QString &setting, T defValue, T valueMin, T valueMax) const diff --git a/src/libs/vmisc/vvalentinasettings.h b/src/libs/vmisc/vvalentinasettings.h index 1a79d33d7..e1c42d3ce 100644 --- a/src/libs/vmisc/vvalentinasettings.h +++ b/src/libs/vmisc/vvalentinasettings.h @@ -170,6 +170,66 @@ public: auto GetDetailExportFormat() const -> qint8; void SetDetailExportFormat(qint8 format); + auto GetHistorySearchHistory() const -> QStringList; + void SetHistorySearchHistory(const QStringList &history); + + auto GetIncrementsSearchHistory() const -> QStringList; + void SetIncrementsSearchHistory(const QStringList &history); + + auto GetPreviewCalculationsSearchHistory() const -> QStringList; + void SetPreviewCalculationsSearchHistory(const QStringList &history); + + auto GetFinalMeasurementsSearchHistory() const -> QStringList; + void SetFinalMeasurementsSearchHistory(const QStringList &history); + + auto GetHistorySearchOptionUseUnicodeProperties() const -> bool; + void SetHistorySearchOptionUseUnicodeProperties(bool value); + + auto GetHistorySearchOptionWholeWord() const -> bool; + void SetHistorySearchOptionWholeWord(bool value); + + auto GetHistorySearchOptionRegexp() const -> bool; + void SetHistorySearchOptionRegexp(bool value); + + auto GetHistorySearchOptionMatchCase() const ->bool; + void SetHistorySearchOptionMatchCase(bool value); + + auto GetIncrementsSearchOptionUseUnicodeProperties() const -> bool; + void SetIncrementsSearchOptionUseUnicodeProperties(bool value); + + auto GetIncrementsSearchOptionWholeWord() const -> bool; + void SetIncrementsSearchOptionWholeWord(bool value); + + auto GetIncrementsSearchOptionRegexp() const -> bool; + void SetIncrementsSearchOptionRegexp(bool value); + + auto GetIncrementsSearchOptionMatchCase() const ->bool; + void SetIncrementsSearchOptionMatchCase(bool value); + + auto GetPreviewCalculationsSearchOptionUseUnicodeProperties() const -> bool; + void SetPreviewCalculationsSearchOptionUseUnicodeProperties(bool value); + + auto GetPreviewCalculationsSearchOptionWholeWord() const -> bool; + void SetPreviewCalculationsSearchOptionWholeWord(bool value); + + auto GetPreviewCalculationsSearchOptionRegexp() const -> bool; + void SetPreviewCalculationsSearchOptionRegexp(bool value); + + auto GetPreviewCalculationsSearchOptionMatchCase() const ->bool; + void SetPreviewCalculationsSearchOptionMatchCase(bool value); + + auto GetFinalMeasurementsSearchOptionUseUnicodeProperties() const -> bool; + void SetFinalMeasurementsSearchOptionUseUnicodeProperties(bool value); + + auto GetFinalMeasurementsSearchOptionWholeWord() const -> bool; + void SetFinalMeasurementsSearchOptionWholeWord(bool value); + + auto GetFinalMeasurementsSearchOptionRegexp() const -> bool; + void SetFinalMeasurementsSearchOptionRegexp(bool value); + + auto GetFinalMeasurementsSearchOptionMatchCase() const ->bool; + void SetFinalMeasurementsSearchOptionMatchCase(bool value); + private: Q_DISABLE_COPY(VValentinaSettings)