Resolved issue #364. Add Search feature to Measurement dialogs.
--HG-- branch : develop
This commit is contained in:
parent
8dc048a47b
commit
902fe178e5
|
@ -12,7 +12,8 @@ SOURCES += \
|
|||
$$PWD/dialogs/tapeconfigdialog.cpp \
|
||||
$$PWD/dialogs/configpages/tapeconfigurationpage.cpp \
|
||||
$$PWD/dialogs/configpages/tapepathpage.cpp \
|
||||
$$PWD/vlitepattern.cpp
|
||||
$$PWD/vlitepattern.cpp \
|
||||
$$PWD/vtablesearch.cpp
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/tmainwindow.h \
|
||||
|
@ -25,7 +26,8 @@ HEADERS += \
|
|||
$$PWD/dialogs/tapeconfigdialog.h \
|
||||
$$PWD/dialogs/configpages/tapeconfigurationpage.h \
|
||||
$$PWD/dialogs/configpages/tapepathpage.h \
|
||||
$$PWD/vlitepattern.h
|
||||
$$PWD/vlitepattern.h \
|
||||
$$PWD/vtablesearch.h
|
||||
|
||||
FORMS += \
|
||||
$$PWD/tmainwindow.ui \
|
||||
|
|
|
@ -68,9 +68,11 @@ TMainWindow::TMainWindow(QWidget *parent)
|
|||
gradationSizes(nullptr),
|
||||
comboBoxUnits(nullptr),
|
||||
formulaBaseHeight(0),
|
||||
lock(nullptr)
|
||||
lock(nullptr),
|
||||
search()
|
||||
{
|
||||
ui->setupUi(this);
|
||||
search = QSharedPointer<VTableSearch>(new VTableSearch(ui->tableWidget));
|
||||
ui->tabWidget->setVisible(false);
|
||||
|
||||
ui->mainToolBar->setContextMenuPolicy(Qt::PreventContextMenu);
|
||||
|
@ -350,6 +352,24 @@ void TMainWindow::OpenTemplate()
|
|||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TMainWindow::Find(const QString &term)
|
||||
{
|
||||
search->Find(term);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TMainWindow::FindPrevious()
|
||||
{
|
||||
search->FindPrevious();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TMainWindow::FindNext()
|
||||
{
|
||||
search->FindNext();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TMainWindow::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
|
@ -602,7 +622,9 @@ void TMainWindow::Remove()
|
|||
|
||||
MeasurementsWasSaved(false);
|
||||
|
||||
search->RemoveRow(row);
|
||||
RefreshData();
|
||||
search->RefreshList(ui->lineEditFind->text());
|
||||
|
||||
if (ui->tableWidget->rowCount() > 0)
|
||||
{
|
||||
|
@ -668,6 +690,7 @@ void TMainWindow::MoveUp()
|
|||
m->MoveUp(nameField->text());
|
||||
MeasurementsWasSaved(false);
|
||||
RefreshData();
|
||||
search->RefreshList(ui->lineEditFind->text());
|
||||
ui->tableWidget->selectRow(row-1);
|
||||
}
|
||||
|
||||
|
@ -685,6 +708,7 @@ void TMainWindow::MoveDown()
|
|||
m->MoveDown(nameField->text());
|
||||
MeasurementsWasSaved(false);
|
||||
RefreshData();
|
||||
search->RefreshList(ui->lineEditFind->text());
|
||||
ui->tableWidget->selectRow(row+1);
|
||||
}
|
||||
|
||||
|
@ -719,6 +743,8 @@ void TMainWindow::Fx()
|
|||
|
||||
RefreshData();
|
||||
|
||||
search->RefreshList(ui->lineEditFind->text());
|
||||
|
||||
ui->tableWidget->selectRow(row);
|
||||
}
|
||||
delete dialog;
|
||||
|
@ -749,7 +775,9 @@ void TMainWindow::AddCustom()
|
|||
m->AddEmptyAfter(nameField->text(), name);
|
||||
}
|
||||
|
||||
search->AddRow(currentRow);
|
||||
RefreshData();
|
||||
search->RefreshList(ui->lineEditFind->text());
|
||||
|
||||
ui->tableWidget->selectRow(currentRow);
|
||||
|
||||
|
@ -778,6 +806,8 @@ void TMainWindow::AddKnown()
|
|||
{
|
||||
m->AddEmpty(list.at(i));
|
||||
}
|
||||
|
||||
search->AddRow(currentRow);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -795,11 +825,13 @@ void TMainWindow::AddKnown()
|
|||
{
|
||||
m->AddEmptyAfter(after, list.at(i));
|
||||
}
|
||||
search->AddRow(currentRow);
|
||||
after = list.at(i);
|
||||
}
|
||||
}
|
||||
|
||||
RefreshData();
|
||||
search->RefreshList(ui->lineEditFind->text());
|
||||
|
||||
ui->tableWidget->selectRow(currentRow);
|
||||
|
||||
|
@ -888,6 +920,8 @@ void TMainWindow::ImportFromPattern()
|
|||
|
||||
RefreshData();
|
||||
|
||||
search->RefreshList(ui->lineEditFind->text());
|
||||
|
||||
ui->tableWidget->selectRow(currentRow);
|
||||
|
||||
MeasurementsWasSaved(false);
|
||||
|
@ -899,6 +933,7 @@ void TMainWindow::ChangedSize(const QString &text)
|
|||
const int row = ui->tableWidget->currentRow();
|
||||
data->SetSize(text.toInt());
|
||||
RefreshData();
|
||||
search->RefreshList(ui->lineEditFind->text());
|
||||
ui->tableWidget->selectRow(row);
|
||||
}
|
||||
|
||||
|
@ -908,6 +943,7 @@ void TMainWindow::ChangedHeight(const QString &text)
|
|||
const int row = ui->tableWidget->currentRow();
|
||||
data->SetHeight(text.toInt());
|
||||
RefreshData();
|
||||
search->RefreshList(ui->lineEditFind->text());
|
||||
ui->tableWidget->selectRow(row);
|
||||
}
|
||||
|
||||
|
@ -1052,6 +1088,7 @@ void TMainWindow::SaveMName()
|
|||
m->SetMName(nameField->text(), newName);
|
||||
MeasurementsWasSaved(false);
|
||||
RefreshData();
|
||||
search->RefreshList(ui->lineEditFind->text());
|
||||
|
||||
ui->tableWidget->blockSignals(true);
|
||||
ui->tableWidget->selectRow(row);
|
||||
|
@ -1121,6 +1158,7 @@ void TMainWindow::SaveMValue()
|
|||
const QTextCursor cursor = ui->plainTextEditFormula->textCursor();
|
||||
|
||||
RefreshData();
|
||||
search->RefreshList(ui->lineEditFind->text());
|
||||
|
||||
ui->tableWidget->blockSignals(true);
|
||||
ui->tableWidget->selectRow(row);
|
||||
|
@ -1145,6 +1183,7 @@ void TMainWindow::SaveMBaseValue(double value)
|
|||
MeasurementsWasSaved(false);
|
||||
|
||||
RefreshData();
|
||||
search->RefreshList(ui->lineEditFind->text());
|
||||
|
||||
ui->tableWidget->blockSignals(true);
|
||||
ui->tableWidget->selectRow(row);
|
||||
|
@ -1167,6 +1206,7 @@ void TMainWindow::SaveMSizeIncrease(double value)
|
|||
MeasurementsWasSaved(false);
|
||||
|
||||
RefreshData();
|
||||
search->RefreshList(ui->lineEditFind->text());
|
||||
|
||||
ui->tableWidget->blockSignals(true);
|
||||
ui->tableWidget->selectRow(row);
|
||||
|
@ -1189,6 +1229,7 @@ void TMainWindow::SaveMHeightIncrease(double value)
|
|||
MeasurementsWasSaved(false);
|
||||
|
||||
RefreshData();
|
||||
search->RefreshList(ui->lineEditFind->text());
|
||||
|
||||
ui->tableWidget->selectRow(row);
|
||||
}
|
||||
|
@ -1446,6 +1487,10 @@ void TMainWindow::InitWindow()
|
|||
connect(ui->toolButtonExpr, &QToolButton::clicked, this, &TMainWindow::Fx);
|
||||
}
|
||||
|
||||
connect(ui->lineEditFind, &QLineEdit::textEdited, this, &TMainWindow::Find);
|
||||
connect(ui->toolButtonFindPrevious, &QToolButton::clicked, this, &TMainWindow::FindPrevious);
|
||||
connect(ui->toolButtonFindNext, &QToolButton::clicked, this, &TMainWindow::FindNext);
|
||||
|
||||
ui->plainTextEditNotes->setPlainText(m->Notes());
|
||||
connect(ui->plainTextEditNotes, &QPlainTextEdit::textChanged, this, &TMainWindow::SaveNotes);
|
||||
|
||||
|
@ -1660,6 +1705,7 @@ void TMainWindow::SetDefaultSize(int value)
|
|||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void TMainWindow::RefreshData()
|
||||
{
|
||||
data->ClearUniqueNames();
|
||||
data->ClearVariables(VarType::Measurement);
|
||||
m->ReadMeasurements();
|
||||
|
||||
|
@ -1799,6 +1845,10 @@ void TMainWindow::MFields(bool enabled)
|
|||
ui->pushButtonGrow->setEnabled(enabled);
|
||||
ui->toolButtonExpr->setEnabled(enabled);
|
||||
}
|
||||
|
||||
ui->lineEditFind->setEnabled(enabled);
|
||||
ui->toolButtonFindPrevious->setEnabled(enabled);
|
||||
ui->toolButtonFindNext->setEnabled(enabled);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -1985,6 +2035,8 @@ void TMainWindow::UpdatePatternUnit()
|
|||
ShowUnits();
|
||||
RefreshTable();
|
||||
|
||||
search->RefreshList(ui->lineEditFind->text());
|
||||
|
||||
ui->tableWidget->selectRow(row);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "../vmisc/def.h"
|
||||
#include "../vmisc/vlockguard.h"
|
||||
#include "../vformat/vmeasurements.h"
|
||||
#include "vtablesearch.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
|
@ -113,10 +114,11 @@ private slots:
|
|||
void SaveMFullName();
|
||||
|
||||
void NewWindow();
|
||||
|
||||
void Preferences();
|
||||
|
||||
void PatternUnitChanged(int index);
|
||||
void Find(const QString &term);
|
||||
void FindPrevious();
|
||||
void FindNext();
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(TMainWindow)
|
||||
|
@ -132,6 +134,7 @@ private:
|
|||
QComboBox *comboBoxUnits;
|
||||
int formulaBaseHeight;
|
||||
VLockGuardPtr<char> lock;
|
||||
QSharedPointer<VTableSearch> search;
|
||||
|
||||
void SetupMenu();
|
||||
void InitWindow();
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>536</width>
|
||||
<height>694</height>
|
||||
<height>726</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -43,6 +43,69 @@
|
|||
<string>Measurements</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="labelFind">
|
||||
<property name="text">
|
||||
<string>Find:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEditFind">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButtonFindPrevious">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Find Previous</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="go-previous">
|
||||
<normaloff/>
|
||||
</iconset>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+Shift+G</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButtonFindNext">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Find Next</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="go-next">
|
||||
<normaloff/>
|
||||
</iconset>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+G</string>
|
||||
</property>
|
||||
<property name="autoExclusive">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableWidget" name="tableWidget">
|
||||
<property name="sizePolicy">
|
||||
|
|
208
src/app/tape/vtablesearch.cpp
Normal file
208
src/app/tape/vtablesearch.cpp
Normal file
|
@ -0,0 +1,208 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file vtablesearch.cpp
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 15 9, 2015
|
||||
**
|
||||
** @brief
|
||||
** @copyright
|
||||
** This source code is part of the Valentine project, a pattern making
|
||||
** program, whose allow create and modeling patterns of clothing.
|
||||
** Copyright (C) 2015 Valentina project
|
||||
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
||||
**
|
||||
** Valentina is free software: you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation, either version 3 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** Valentina is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
|
||||
#include "vtablesearch.h"
|
||||
#include "../vmisc/def.h"
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
VTableSearch::VTableSearch(QTableWidget *table)
|
||||
:table(table),
|
||||
searchIndex(-1),
|
||||
searchList()
|
||||
{
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTableSearch::Clear()
|
||||
{
|
||||
SCASSERT(table != nullptr);
|
||||
|
||||
foreach(QTableWidgetItem *item, searchList)
|
||||
{
|
||||
if (item->row() % 2 != 0 && table->alternatingRowColors())
|
||||
{
|
||||
item->setBackground(QPalette().alternateBase());
|
||||
}
|
||||
else
|
||||
{
|
||||
item->setBackground(QPalette().base());
|
||||
}
|
||||
}
|
||||
searchIndex = -1;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTableSearch::ShowNext(int newIndex)
|
||||
{
|
||||
if (not searchList.isEmpty())
|
||||
{
|
||||
QTableWidgetItem *item = searchList.at(searchIndex);
|
||||
item->setBackground(Qt::yellow);
|
||||
|
||||
item = searchList.at(newIndex);
|
||||
item->setBackground(Qt::red);
|
||||
table->scrollToItem(item);
|
||||
searchIndex = newIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTableSearch::Find(const QString &term)
|
||||
{
|
||||
SCASSERT(table != nullptr);
|
||||
|
||||
const QList<QTableWidgetItem *> list = table->findItems(term, Qt::MatchContains);
|
||||
|
||||
if (list.isEmpty() || term.isEmpty())
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
Clear();
|
||||
|
||||
searchList = list;
|
||||
foreach(QTableWidgetItem *item, searchList)
|
||||
{
|
||||
item->setBackground(Qt::yellow);
|
||||
}
|
||||
|
||||
searchIndex = 0;
|
||||
QTableWidgetItem *item = searchList.at(searchIndex);
|
||||
item->setBackground(Qt::red);
|
||||
table->scrollToItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTableSearch::FindPrevious()
|
||||
{
|
||||
int newIndex = searchIndex - 1;
|
||||
|
||||
if (newIndex < 0)
|
||||
{
|
||||
newIndex = searchList.size() - 1;
|
||||
}
|
||||
|
||||
ShowNext(newIndex);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTableSearch::FindNext()
|
||||
{
|
||||
int newIndex = searchIndex + 1;
|
||||
|
||||
if (newIndex >= searchList.size())
|
||||
{
|
||||
newIndex = 0;
|
||||
}
|
||||
|
||||
ShowNext(newIndex);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTableSearch::RemoveRow(int row)
|
||||
{
|
||||
if (searchIndex < 0 || searchIndex >= searchList.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const int indexRow = searchList.at(searchIndex)->row();
|
||||
|
||||
if (row <= indexRow)
|
||||
{
|
||||
foreach(QTableWidgetItem *item, searchList)
|
||||
{
|
||||
if (item->row() == row)
|
||||
{
|
||||
--searchIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTableSearch::AddRow(int row)
|
||||
{
|
||||
if (searchIndex < 0 || searchIndex >= searchList.size())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const int indexRow = searchList.at(searchIndex)->row();
|
||||
|
||||
if (row <= indexRow)
|
||||
{
|
||||
foreach(QTableWidgetItem *item, searchList)
|
||||
{
|
||||
if (item->row() == row)
|
||||
{
|
||||
++searchIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
void VTableSearch::RefreshList(const QString &term)
|
||||
{
|
||||
SCASSERT(table != nullptr);
|
||||
|
||||
if (term.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
searchList = table->findItems(term, Qt::MatchContains);
|
||||
|
||||
foreach(QTableWidgetItem *item, searchList)
|
||||
{
|
||||
item->setBackground(Qt::yellow);
|
||||
}
|
||||
|
||||
if (not searchList.isEmpty())
|
||||
{
|
||||
if (searchIndex < 0)
|
||||
{
|
||||
searchIndex = searchList.size() - 1;
|
||||
}
|
||||
else if (searchIndex >= searchList.size())
|
||||
{
|
||||
searchIndex = 0;
|
||||
}
|
||||
|
||||
QTableWidgetItem *item = searchList.at(searchIndex);
|
||||
item->setBackground(Qt::red);
|
||||
table->scrollToItem(item);
|
||||
}
|
||||
}
|
58
src/app/tape/vtablesearch.h
Normal file
58
src/app/tape/vtablesearch.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
/************************************************************************
|
||||
**
|
||||
** @file vtablesearch.h
|
||||
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
||||
** @date 15 9, 2015
|
||||
**
|
||||
** @brief
|
||||
** @copyright
|
||||
** This source code is part of the Valentine project, a pattern making
|
||||
** program, whose allow create and modeling patterns of clothing.
|
||||
** Copyright (C) 2015 Valentina project
|
||||
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
||||
**
|
||||
** Valentina is free software: you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation, either version 3 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** Valentina is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
||||
**
|
||||
*************************************************************************/
|
||||
|
||||
#ifndef VTABLESEARCH_H
|
||||
#define VTABLESEARCH_H
|
||||
|
||||
#include <QList>
|
||||
#include <QTableWidget>
|
||||
|
||||
class VTableSearch
|
||||
{
|
||||
public:
|
||||
VTableSearch(QTableWidget *table);
|
||||
|
||||
void Find(const QString &term);
|
||||
void FindPrevious();
|
||||
void FindNext();
|
||||
void RemoveRow(int row);
|
||||
void AddRow(int row);
|
||||
void RefreshList(const QString &term);
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(VTableSearch)
|
||||
|
||||
QTableWidget *table;
|
||||
int searchIndex;
|
||||
QList<QTableWidgetItem *> searchList;
|
||||
|
||||
void Clear();
|
||||
void ShowNext(int newIndex);
|
||||
};
|
||||
|
||||
#endif // VTABLESEARCH_H
|
Loading…
Reference in New Issue
Block a user