Save attributes.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2015-07-22 12:44:31 +03:00
parent 17e99b4cb4
commit 180af51f99
8 changed files with 296 additions and 34 deletions

View File

@ -32,6 +32,7 @@
#include "dialogs/dialogabouttape.h" #include "dialogs/dialogabouttape.h"
#include "dialogs/dialognewmeasurements.h" #include "dialogs/dialognewmeasurements.h"
#include "../vpatterndb/calculator.h" #include "../vpatterndb/calculator.h"
#include "../ifc/ifcdef.h"
#include <QFileDialog> #include <QFileDialog>
#include <QFileInfo> #include <QFileInfo>
@ -419,7 +420,7 @@ void TMainWindow::AddCustom()
QString name; QString name;
do do
{ {
name = QString("@" + tr("M_%1")).arg(num); name = QString(CustomSign + tr("M_%1")).arg(num);
num++; num++;
} while (data->IsUnique(name) == false); } while (data->IsUnique(name) == false);
@ -519,9 +520,9 @@ void TMainWindow::ShowMData()
if (mType == MeasurementsType::Standard) if (mType == MeasurementsType::Standard)
{ {
ui->labelCalculatedValue->setText(QString().setNum(data->GetTableValue(nameField->text(), mType))); ui->labelCalculatedValue->setText(QString().setNum(data->GetTableValue(nameField->text(), mType)));
ui->doubleSpinBoxBaseValue->setValue(meash->GetBase()); ui->spinBoxBaseValue->setValue(static_cast<int>(meash->GetBase()));
ui->doubleSpinBoxInSizes->setValue(meash->GetKsize()); ui->spinBoxInSizes->setValue(static_cast<int>(meash->GetKsize()));
ui->doubleSpinBoxInHeights->setValue(meash->GetKheight()); ui->spinBoxInHeights->setValue(static_cast<int>(meash->GetKheight()));
} }
else else
{ {
@ -540,6 +541,7 @@ void TMainWindow::ShowMData()
if (not meash->IsCustom()) if (not meash->IsCustom())
{ {
ui->plainTextEditDescription->setEnabled(false);
ui->lineEditName->setEnabled(false); ui->lineEditName->setEnabled(false);
} }
} }
@ -573,6 +575,157 @@ void TMainWindow::DeployFormula()
setUpdatesEnabled(true); setUpdatesEnabled(true);
} }
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SaveMName()
{
const int row = ui->tableWidget->currentRow();
if (row == -1)
{
return;
}
QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), 0);
QSharedPointer<VMeasurement> meash = data->GetVariable<VMeasurement>(nameField->text());
QString newName = ui->lineEditName->text();
if (meash->IsCustom())
{
newName = CustomSign + newName;
}
if (data->IsUnique(newName))
{
m->SetMName(nameField->text(), newName);
MeasurementsWasSaved(false);
RefreshData();
ui->tableWidget->selectRow(row);
ui->tableWidget->resizeColumnsToContents();
ui->tableWidget->resizeRowsToContents();
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
}
else
{
ui->lineEditName->setText(ClearCustomName(nameField->text()));
}
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SaveMValue()
{
const int row = ui->tableWidget->currentRow();
if (row == -1)
{
return;
}
QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), 0);
m->SetMValue(nameField->text(), ui->plainTextEditFormula->toPlainText());
MeasurementsWasSaved(false);
RefreshData();
ui->tableWidget->selectRow(row);
ui->tableWidget->resizeColumnsToContents();
ui->tableWidget->resizeRowsToContents();
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SaveMBaseValue(int value)
{
const int row = ui->tableWidget->currentRow();
if (row == -1)
{
return;
}
QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), 0);
m->SetMBaseValue(nameField->text(), value);
MeasurementsWasSaved(false);
RefreshData();
ui->tableWidget->selectRow(row);
ui->tableWidget->resizeColumnsToContents();
ui->tableWidget->resizeRowsToContents();
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SaveMSizeIncrease(int value)
{
const int row = ui->tableWidget->currentRow();
if (row == -1)
{
return;
}
QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), 0);
m->SetMSizeIncrease(nameField->text(), value);
MeasurementsWasSaved(false);
RefreshData();
ui->tableWidget->selectRow(row);
ui->tableWidget->resizeColumnsToContents();
ui->tableWidget->resizeRowsToContents();
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SaveMHeightIncrease(int value)
{
const int row = ui->tableWidget->currentRow();
if (row == -1)
{
return;
}
QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), 0);
m->SetMHeightIncrease(nameField->text(), value);
MeasurementsWasSaved(false);
RefreshData();
ui->tableWidget->selectRow(row);
ui->tableWidget->resizeColumnsToContents();
ui->tableWidget->resizeRowsToContents();
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SaveMDescription()
{
const int row = ui->tableWidget->currentRow();
if (row == -1)
{
return;
}
QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), 0);
m->SetMDescription(nameField->text(), ui->plainTextEditDescription->toPlainText());
MeasurementsWasSaved(false);
RefreshData();
ui->tableWidget->selectRow(row);
ui->tableWidget->resizeColumnsToContents();
ui->tableWidget->resizeRowsToContents();
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SetupMenu() void TMainWindow::SetupMenu()
{ {
@ -656,6 +809,13 @@ void TMainWindow::InitWindow()
SetDefaultSize(static_cast<int>(data->size())); SetDefaultSize(static_cast<int>(data->size()));
connect(gradationSizes, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged), connect(gradationSizes, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
this, &TMainWindow::ChangedSize); this, &TMainWindow::ChangedSize);
connect(ui->spinBoxBaseValue, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
&TMainWindow::SaveMBaseValue);
connect(ui->spinBoxInHeights, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
&TMainWindow::SaveMSizeIncrease);
connect(ui->spinBoxInHeights, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
&TMainWindow::SaveMHeightIncrease);
} }
else else
{ {
@ -669,11 +829,11 @@ void TMainWindow::InitWindow()
// Tab Measurements // Tab Measurements
delete ui->labelBaseValue; delete ui->labelBaseValue;
delete ui->doubleSpinBoxBaseValue; delete ui->spinBoxBaseValue;
delete ui->labelInSizes; delete ui->labelInSizes;
delete ui->doubleSpinBoxInSizes; delete ui->spinBoxInSizes;
delete ui->labelInHeights; delete ui->labelInHeights;
delete ui->doubleSpinBoxInHeights; delete ui->spinBoxInHeights;
// Tab Information // Tab Information
delete ui->labelBaseSize; delete ui->labelBaseSize;
@ -701,6 +861,8 @@ void TMainWindow::InitWindow()
connect(ui->dateEditBirthDate, &QDateEdit::dateChanged, this, &TMainWindow::SaveBirthDate); connect(ui->dateEditBirthDate, &QDateEdit::dateChanged, this, &TMainWindow::SaveBirthDate);
connect(ui->plainTextEditNotes, &QPlainTextEdit::textChanged, this, &TMainWindow::SaveNotes); connect(ui->plainTextEditNotes, &QPlainTextEdit::textChanged, this, &TMainWindow::SaveNotes);
connect(ui->pushButtonGrow, &QPushButton::clicked, this, &TMainWindow::DeployFormula); connect(ui->pushButtonGrow, &QPushButton::clicked, this, &TMainWindow::DeployFormula);
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &TMainWindow::SaveMValue);
} }
ui->actionAddCustom->setEnabled(true); ui->actionAddCustom->setEnabled(true);
@ -712,6 +874,9 @@ void TMainWindow::InitWindow()
connect(ui->toolButtonUp, &QToolButton::clicked, this, &TMainWindow::MoveUp); connect(ui->toolButtonUp, &QToolButton::clicked, this, &TMainWindow::MoveUp);
connect(ui->toolButtonDown, &QToolButton::clicked, this, &TMainWindow::MoveDown); connect(ui->toolButtonDown, &QToolButton::clicked, this, &TMainWindow::MoveDown);
connect(ui->lineEditName, &QLineEdit::editingFinished, this, &TMainWindow::SaveMName);
connect(ui->plainTextEditDescription, &QPlainTextEdit::textChanged, this, &TMainWindow::SaveMDescription);
InitTable(); InitTable();
} }
@ -939,9 +1104,9 @@ void TMainWindow::MFields(bool enabled)
if (mType == MeasurementsType::Standard) if (mType == MeasurementsType::Standard)
{ {
ui->doubleSpinBoxBaseValue->setEnabled(enabled); ui->spinBoxBaseValue->setEnabled(enabled);
ui->doubleSpinBoxInSizes->setEnabled(enabled); ui->spinBoxInSizes->setEnabled(enabled);
ui->doubleSpinBoxInHeights->setEnabled(enabled); ui->spinBoxInHeights->setEnabled(enabled);
} }
else else
{ {
@ -955,7 +1120,7 @@ void TMainWindow::MFields(bool enabled)
QString TMainWindow::ClearCustomName(const QString &name) const QString TMainWindow::ClearCustomName(const QString &name) const
{ {
QString clear = name; QString clear = name;
const int index = clear.indexOf("@"); const int index = clear.indexOf(CustomSign);
if (index == 0) if (index == 0)
{ {
clear.remove(0, 1); clear.remove(0, 1);

View File

@ -85,6 +85,13 @@ private slots:
void DeployFormula(); void DeployFormula();
void SaveMName();
void SaveMValue();
void SaveMBaseValue(int value);
void SaveMSizeIncrease(int value);
void SaveMHeightIncrease(int value);
void SaveMDescription();
private: private:
Q_DISABLE_COPY(TMainWindow) Q_DISABLE_COPY(TMainWindow)
Ui::TMainWindow *ui; Ui::TMainWindow *ui;

View File

@ -219,13 +219,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxBaseValue">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="7" column="0"> <item row="7" column="0">
<widget class="QLabel" name="labelInSizes"> <widget class="QLabel" name="labelInSizes">
<property name="text"> <property name="text">
@ -233,13 +226,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxInSizes">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="8" column="0"> <item row="8" column="0">
<widget class="QLabel" name="labelInHeights"> <widget class="QLabel" name="labelInHeights">
<property name="text"> <property name="text">
@ -247,13 +233,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="8" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBoxInHeights">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="9" column="0"> <item row="9" column="0">
<widget class="QLabel" name="label_7"> <widget class="QLabel" name="label_7">
<property name="text"> <property name="text">
@ -347,6 +326,45 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="8" column="1">
<widget class="QSpinBox" name="spinBoxInHeights">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimum">
<number>-1000</number>
</property>
<property name="maximum">
<number>1000</number>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QSpinBox" name="spinBoxInSizes">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimum">
<number>-1000</number>
</property>
<property name="maximum">
<number>1000</number>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QSpinBox" name="spinBoxBaseValue">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimum">
<number>-1000</number>
</property>
<property name="maximum">
<number>1000</number>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

View File

@ -28,6 +28,8 @@
#include "ifcdef.h" #include "ifcdef.h"
const QString CustomSign = QStringLiteral("@");
#define DefWidth 1.2//mm #define DefWidth 1.2//mm
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -32,6 +32,8 @@
#include <QtGlobal> #include <QtGlobal>
#include "../vmisc/def.h" #include "../vmisc/def.h"
extern const QString CustomSign;
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
extern Q_CORE_EXPORT int qt_ntfs_permission_lookup; extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;
#include <windows.h> #include <windows.h>

View File

@ -313,6 +313,66 @@ void VMeasurements::SetReadOnly(bool ro)
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void VMeasurements::SetMName(const QString &name, const QString &text)
{
QDomElement node = FindM(name);
if (not node.isNull())
{
SetAttribute(node, AttrName, text);
}
}
//---------------------------------------------------------------------------------------------------------------------
void VMeasurements::SetMValue(const QString &name, const QString &text)
{
QDomElement node = FindM(name);
if (not node.isNull())
{
SetAttribute(node, AttrValue, text);
}
}
//---------------------------------------------------------------------------------------------------------------------
void VMeasurements::SetMBaseValue(const QString &name, int value)
{
QDomElement node = FindM(name);
if (not node.isNull())
{
SetAttribute(node, AttrValue, value);
}
}
//---------------------------------------------------------------------------------------------------------------------
void VMeasurements::SetMSizeIncrease(const QString &name, int value)
{
QDomElement node = FindM(name);
if (not node.isNull())
{
SetAttribute(node, AttrSizeIncrease, value);
}
}
//---------------------------------------------------------------------------------------------------------------------
void VMeasurements::SetMHeightIncrease(const QString &name, int value)
{
QDomElement node = FindM(name);
if (not node.isNull())
{
SetAttribute(node, AttrHeightIncrease, value);
}
}
//---------------------------------------------------------------------------------------------------------------------
void VMeasurements::SetMDescription(const QString &name, const QString &text)
{
QDomElement node = FindM(name);
if (not node.isNull())
{
SetAttribute(node, AttrDescription, text);
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VMeasurements::GenderToStr(const SexType &sex) QString VMeasurements::GenderToStr(const SexType &sex)
{ {
@ -453,15 +513,16 @@ QDomElement VMeasurements::MakeEmpty(const QString &name)
QDomElement element = createElement(TagMeasurement); QDomElement element = createElement(TagMeasurement);
SetAttribute(element, AttrName, name); SetAttribute(element, AttrName, name);
SetAttribute(element, AttrValue, QString("0"));
if (type == MeasurementsType::Standard) if (type == MeasurementsType::Standard)
{ {
SetAttribute(element, AttrBase, QString("0"));
SetAttribute(element, AttrSizeIncrease, QString("0")); SetAttribute(element, AttrSizeIncrease, QString("0"));
SetAttribute(element, AttrHeightIncrease, QString("0")); SetAttribute(element, AttrHeightIncrease, QString("0"));
} }
else else
{ {
SetAttribute(element, AttrValue, QString("0"));
SetAttribute(element, AttrDescription, QString("")); SetAttribute(element, AttrDescription, QString(""));
} }

View File

@ -75,6 +75,13 @@ public:
bool ReadOnly() const; bool ReadOnly() const;
void SetReadOnly(bool ro); void SetReadOnly(bool ro);
void SetMName(const QString &name, const QString &text);
void SetMValue(const QString &name, const QString &text);
void SetMBaseValue(const QString &name, int value);
void SetMSizeIncrease(const QString &name, int value);
void SetMHeightIncrease(const QString &name, int value);
void SetMDescription(const QString &name, const QString &text);
static const QString TagVST; static const QString TagVST;
static const QString TagVIT; static const QString TagVIT;
static const QString TagBodyMeasurements; static const QString TagBodyMeasurements;

View File

@ -218,7 +218,7 @@ QString VMeasurement::GetFormula() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VMeasurement::IsCustom() const bool VMeasurement::IsCustom() const
{ {
if (GetName().indexOf("@") == 0) if (GetName().indexOf(CustomSign) == 0)
{ {
return true; return true;
} }