From 17e99b4cb4abde3caf530ba4039cdd445d9b5e48 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 22 Jul 2015 10:01:34 +0300 Subject: [PATCH] Move up and move down. --HG-- branch : feature --- src/app/tape/tmainwindow.cpp | 39 +++++++++++++++++++++++++++++- src/app/tape/tmainwindow.h | 3 +++ src/libs/vformat/vmeasurements.cpp | 30 +++++++++++++++++++++++ src/libs/vformat/vmeasurements.h | 2 ++ 4 files changed, 73 insertions(+), 1 deletion(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index 97375e639..eaa378102 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -373,6 +373,42 @@ void TMainWindow::Remove() RefreshData(); } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::MoveUp() +{ + const int row = ui->tableWidget->currentRow(); + + if (row == -1) + { + return; + } + + QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), 0); + m->MoveUp(nameField->text()); + + MeasurementsWasSaved(false); + + RefreshData(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::MoveDown() +{ + const int row = ui->tableWidget->currentRow(); + + if (row == -1) + { + return; + } + + QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), 0); + m->MoveDown(nameField->text()); + + MeasurementsWasSaved(false); + + RefreshData(); +} + //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::AddCustom() { @@ -429,7 +465,6 @@ void TMainWindow::AddCustom() AddCell("0", currentRow, 5); // in heights } - //ui->toolButtonRemove->setEnabled(true); ui->tableWidget->blockSignals(false); ui->tableWidget->selectRow(currentRow); @@ -674,6 +709,8 @@ void TMainWindow::InitWindow() ui->actionSaveAs->setEnabled(true); connect(ui->toolButtonRemove, &QToolButton::clicked, this, &TMainWindow::Remove); + connect(ui->toolButtonUp, &QToolButton::clicked, this, &TMainWindow::MoveUp); + connect(ui->toolButtonDown, &QToolButton::clicked, this, &TMainWindow::MoveDown); InitTable(); } diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index b537539b4..93bdb327e 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -70,7 +70,10 @@ private slots: void SaveBirthDate(const QDate & date); void SaveNotes(); void ReadOnly(bool ro); + void Remove(); + void MoveUp(); + void MoveDown(); void AddCustom(); void AddKnown(); diff --git a/src/libs/vformat/vmeasurements.cpp b/src/libs/vformat/vmeasurements.cpp index 63880ba60..7d0735b8a 100644 --- a/src/libs/vformat/vmeasurements.cpp +++ b/src/libs/vformat/vmeasurements.cpp @@ -127,6 +127,36 @@ void VMeasurements::Remove(const QString &name) list.at(0).removeChild(FindM(name)); } +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurements::MoveUp(const QString &name) +{ + const QDomElement node = FindM(name); + if (not node.isNull()) + { + const QDomElement prSibling = node.previousSiblingElement(TagMeasurement); + if (not prSibling.isNull()) + { + const QDomNodeList list = elementsByTagName(TagBodyMeasurements); + list.at(0).insertBefore(node, prSibling); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VMeasurements::MoveDown(const QString &name) +{ + const QDomElement node = FindM(name); + if (not node.isNull()) + { + const QDomElement nextSibling = node.nextSiblingElement(TagMeasurement); + if (not nextSibling.isNull()) + { + const QDomNodeList list = elementsByTagName(TagBodyMeasurements); + list.at(0).insertAfter(node, nextSibling); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- MeasurementsType VMeasurements::Type() const { diff --git a/src/libs/vformat/vmeasurements.h b/src/libs/vformat/vmeasurements.h index 2121eaca5..50df498d7 100644 --- a/src/libs/vformat/vmeasurements.h +++ b/src/libs/vformat/vmeasurements.h @@ -46,6 +46,8 @@ public: void AddEmpty(const QString &name); void AddEmptyAfter(const QString &after, const QString &name); void Remove(const QString &name); + void MoveUp(const QString &name); + void MoveDown(const QString &name); MeasurementsType Type() const; Unit MUnit() const;