From dcbfc2240dc8b535525e5b2d2c49b2724ec0ed58 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 1 Aug 2015 14:25:05 +0300 Subject: [PATCH] Return selected names. Add them to the table. --HG-- branch : feature --- src/app/tape/dialogs/dialogmdatabase.cpp | 25 +++++++++++++ src/app/tape/dialogs/dialogmdatabase.h | 2 ++ src/app/tape/tmainwindow.cpp | 46 +++++++++++++++++++++--- src/libs/vformat/vmeasurements.cpp | 19 ++++++---- src/libs/vformat/vmeasurements.h | 6 ++-- src/libs/vpatterndb/vtranslatevars.cpp | 6 ++++ src/libs/vpatterndb/vtranslatevars.h | 1 + 7 files changed, 91 insertions(+), 14 deletions(-) diff --git a/src/app/tape/dialogs/dialogmdatabase.cpp b/src/app/tape/dialogs/dialogmdatabase.cpp index 939b00ddd..bd5a5ccc8 100644 --- a/src/app/tape/dialogs/dialogmdatabase.cpp +++ b/src/app/tape/dialogs/dialogmdatabase.cpp @@ -64,6 +64,31 @@ DialogMDataBase::~DialogMDataBase() delete ui; } +//--------------------------------------------------------------------------------------------------------------------- +QStringList DialogMDataBase::GetNewNames() const +{ + if (selectMode) + { + QStringList newNames; + QTreeWidgetItemIterator it(ui->treeWidget, + QTreeWidgetItemIterator::NoChildren | QTreeWidgetItemIterator::Checked ); + while (*it) + { + const QString name = (*it)->data(0, Qt::UserRole).toString(); + if (not list.contains(name)) + { + newNames.append(name); + } + ++it; + } + return newNames; + } + else + { + return QStringList(); + } +} + //--------------------------------------------------------------------------------------------------------------------- void DialogMDataBase::UpdateChecks(QTreeWidgetItem *item, int column) { diff --git a/src/app/tape/dialogs/dialogmdatabase.h b/src/app/tape/dialogs/dialogmdatabase.h index e56f93b5f..71fa6b5cf 100644 --- a/src/app/tape/dialogs/dialogmdatabase.h +++ b/src/app/tape/dialogs/dialogmdatabase.h @@ -47,6 +47,8 @@ public: explicit DialogMDataBase(QWidget *parent = 0); ~DialogMDataBase(); + QStringList GetNewNames() const; + private slots: void UpdateChecks(QTreeWidgetItem *item, int column); void ShowDescription(QTreeWidgetItem *item, int column); diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 29bcde66a..65d139fd8 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -645,9 +645,6 @@ void TMainWindow::Fx() //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::AddCustom() { - ui->tableWidget->setFocus(Qt::OtherFocusReason); - ui->tableWidget->blockSignals(true); - qint32 num = 1; QString name; do @@ -661,7 +658,6 @@ void TMainWindow::AddCustom() if (ui->tableWidget->currentRow() == -1) { currentRow = ui->tableWidget->rowCount(); - ui->tableWidget->insertRow( currentRow ); m->AddEmpty(name); } else @@ -673,7 +669,6 @@ void TMainWindow::AddCustom() RefreshData(); - ui->tableWidget->blockSignals(false); ui->tableWidget->selectRow(currentRow); MeasurementsWasSaved(false); @@ -685,7 +680,48 @@ void TMainWindow::AddKnown() DialogMDataBase *dialog = new DialogMDataBase(m->ListKnown(), this); if (dialog->exec() == QDialog::Accepted) { + qint32 currentRow; + const QStringList list = dialog->GetNewNames(); + if (ui->tableWidget->currentRow() == -1) + { + currentRow = ui->tableWidget->rowCount() + list.size() - 1; + for (int i = 0; i < list.size(); ++i) + { + if (mType == MeasurementsType::Individual) + { + m->AddEmpty(list.at(i), qApp->TrVars()->MFormula(list.at(i))); + } + else + { + m->AddEmpty(list.at(i)); + } + } + } + else + { + currentRow = ui->tableWidget->currentRow() + list.size(); + QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), 0); + QString after = nameField->text(); + for (int i = 0; i < list.size(); ++i) + { + if (mType == MeasurementsType::Individual) + { + m->AddEmptyAfter(after, list.at(i), qApp->TrVars()->MFormula(list.at(i))); + } + else + { + m->AddEmptyAfter(after, list.at(i)); + } + after = list.at(i); + } + } + + RefreshData(); + + ui->tableWidget->selectRow(currentRow); + + MeasurementsWasSaved(false); } delete dialog; } diff --git a/src/libs/vformat/vmeasurements.cpp b/src/libs/vformat/vmeasurements.cpp index 5bacfb511..1a086881d 100644 --- a/src/libs/vformat/vmeasurements.cpp +++ b/src/libs/vformat/vmeasurements.cpp @@ -104,18 +104,18 @@ void VMeasurements::setXMLContent(const QString &fileName) } //--------------------------------------------------------------------------------------------------------------------- -void VMeasurements::AddEmpty(const QString &name) +void VMeasurements::AddEmpty(const QString &name, const QString &formula) { - const QDomElement element = MakeEmpty(name); + const QDomElement element = MakeEmpty(name, formula); const QDomNodeList list = elementsByTagName(TagBodyMeasurements); list.at(0).appendChild(element); } //--------------------------------------------------------------------------------------------------------------------- -void VMeasurements::AddEmptyAfter(const QString &after, const QString &name) +void VMeasurements::AddEmptyAfter(const QString &after, const QString &name, const QString &formula) { - const QDomElement element = MakeEmpty(name); + const QDomElement element = MakeEmpty(name, formula); const QDomElement sibling = FindM(after); const QDomNodeList list = elementsByTagName(TagBodyMeasurements); @@ -622,7 +622,7 @@ qreal VMeasurements::UniqueTagAttr(const QString &tag, const QString &attr, qrea } //--------------------------------------------------------------------------------------------------------------------- -QDomElement VMeasurements::MakeEmpty(const QString &name) +QDomElement VMeasurements::MakeEmpty(const QString &name, const QString &formula) { QDomElement element = createElement(TagMeasurement); @@ -636,7 +636,14 @@ QDomElement VMeasurements::MakeEmpty(const QString &name) } else { - SetAttribute(element, AttrValue, QString("0")); + if (formula.isEmpty()) + { + SetAttribute(element, AttrValue, QString("0")); + } + else + { + SetAttribute(element, AttrValue, formula); + } SetAttribute(element, AttrDescription, QString("")); SetAttribute(element, AttrFullName, QString("")); } diff --git a/src/libs/vformat/vmeasurements.h b/src/libs/vformat/vmeasurements.h index 5918d304c..6a91305c1 100644 --- a/src/libs/vformat/vmeasurements.h +++ b/src/libs/vformat/vmeasurements.h @@ -45,8 +45,8 @@ public: void setXMLContent(const QString &fileName); - void AddEmpty(const QString &name); - void AddEmptyAfter(const QString &after, const QString &name); + void AddEmpty(const QString &name, const QString &formula = QString()); + void AddEmptyAfter(const QString &after, const QString &name, const QString &formula = QString()); void Remove(const QString &name); void MoveUp(const QString &name); void MoveDown(const QString &name); @@ -133,7 +133,7 @@ private: qreal UniqueTagAttr(const QString &tag, const QString &attr, qreal defValue) const; - QDomElement MakeEmpty(const QString &name); + QDomElement MakeEmpty(const QString &name, const QString &formula); QDomElement FindM(const QString &name) const; MeasurementsType ReadType() const; diff --git a/src/libs/vpatterndb/vtranslatevars.cpp b/src/libs/vpatterndb/vtranslatevars.cpp index 4d38bccdf..1e9f9827c 100644 --- a/src/libs/vpatterndb/vtranslatevars.cpp +++ b/src/libs/vpatterndb/vtranslatevars.cpp @@ -399,6 +399,12 @@ QString VTranslateVars::MNumber(const QString &measurement) const return numbers.value(measurement); } +//--------------------------------------------------------------------------------------------------------------------- +QString VTranslateVars::MFormula(const QString &measurement) const +{ + return formulas.value(measurement); +} + //--------------------------------------------------------------------------------------------------------------------- QString VTranslateVars::GuiText(const QString &measurement) const { diff --git a/src/libs/vpatterndb/vtranslatevars.h b/src/libs/vpatterndb/vtranslatevars.h index 05416ca01..718215625 100644 --- a/src/libs/vpatterndb/vtranslatevars.h +++ b/src/libs/vpatterndb/vtranslatevars.h @@ -49,6 +49,7 @@ public: QString MToUser(const QString &measurement) const; QString MNumber(const QString &measurement) const; + QString MFormula(const QString &measurement) const; QString GuiText(const QString &measurement) const; QString Description(const QString &measurement) const; QString PostfixOperator(const QString &name) const;