Move up and move down.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2015-07-22 10:01:34 +03:00
parent a74bfd9c42
commit 17e99b4cb4
4 changed files with 73 additions and 1 deletions

View File

@ -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();
}

View File

@ -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();

View File

@ -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
{

View File

@ -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;