Little refactoring. Convert value to measurements table unit.

--HG--
branch : develop
This commit is contained in:
dismine 2014-07-10 10:10:29 +03:00
parent fda8cc24fa
commit b64369d58f
2 changed files with 46 additions and 20 deletions

View File

@ -39,6 +39,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QCloseEvent> #include <QCloseEvent>
#include <QTableWidget> #include <QTableWidget>
#include <QSettings>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
@ -93,13 +94,8 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par
QRegExpValidator *reg = new QRegExpValidator(QRegExp("\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*")); QRegExpValidator *reg = new QRegExpValidator(QRegExp("\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"));
ui->lineEditMail->setValidator(reg); ui->lineEditMail->setValidator(reg);
ui->tableWidgetMeasurements->setColumnHidden( 1, true );// calculated value HideColumns(ui->tableWidgetMeasurements);
ui->tableWidgetMeasurements->setColumnHidden( 3, true );// in sizes HideColumns(ui->tableWidgetIncrement);
ui->tableWidgetMeasurements->setColumnHidden( 4, true );// in heights
ui->tableWidgetIncrement->setColumnHidden( 1, true );// calculated value
ui->tableWidgetIncrement->setColumnHidden( 3, true );// in sizes
ui->tableWidgetIncrement->setColumnHidden( 4, true );// in heights
ui->tableWidgetMeasurements->setItemDelegateForColumn(2, doubleDelegate);// base value ui->tableWidgetMeasurements->setItemDelegateForColumn(2, doubleDelegate);// base value
@ -185,7 +181,7 @@ void DialogIncrements::FillMeasurements()
Qt::ItemFlags flags = item->flags(); Qt::ItemFlags flags = item->flags();
flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEditable); // reset/clear the flag flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEditable); // reset/clear the flag
item->setFlags(flags); item->setFlags(flags);
ui->tableWidgetMeasurements->setItem(currentRow, 1, item); ui->tableWidgetMeasurements->setItem(currentRow, 1, item);// calculated value
} }
item = new QTableWidgetItem(QString().setNum(m.GetBase())); item = new QTableWidgetItem(QString().setNum(m.GetBase()));
@ -200,7 +196,7 @@ void DialogIncrements::FillMeasurements()
Qt::ItemFlags flags = item->flags(); Qt::ItemFlags flags = item->flags();
flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEditable); // reset/clear the flag flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEditable); // reset/clear the flag
item->setFlags(flags); item->setFlags(flags);
ui->tableWidgetMeasurements->setItem(currentRow, 3, item); ui->tableWidgetMeasurements->setItem(currentRow, 3, item);// in sizes
item = new QTableWidgetItem(QString().setNum(m.GetKheight())); item = new QTableWidgetItem(QString().setNum(m.GetKheight()));
item->setTextAlignment(Qt::AlignHCenter); item->setTextAlignment(Qt::AlignHCenter);
@ -208,7 +204,7 @@ void DialogIncrements::FillMeasurements()
flags = item->flags(); flags = item->flags();
flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEditable); // reset/clear the flag flags &= ~(Qt::ItemIsSelectable | Qt::ItemIsEditable); // reset/clear the flag
item->setFlags(flags); item->setFlags(flags);
ui->tableWidgetMeasurements->setItem(currentRow, 4, item); ui->tableWidgetMeasurements->setItem(currentRow, 4, item);// in heights
} }
item = new QTableWidgetItem(m.GetDescription()); item = new QTableWidgetItem(m.GetDescription());
@ -369,10 +365,17 @@ void DialogIncrements::FillLengthArcs()
*/ */
void DialogIncrements::FullUpdateFromFile() void DialogIncrements::FullUpdateFromFile()
{ {
disconnect(ui->tableWidgetMeasurements, &QTableWidget::cellChanged, this, &DialogIncrements::MeasurementChanged); if (qApp->patternType() == MeasurementsType::Individual)
{
disconnect(ui->tableWidgetMeasurements, &QTableWidget::cellChanged, this,
&DialogIncrements::MeasurementChanged);
}
ui->tableWidgetMeasurements->clearContents(); ui->tableWidgetMeasurements->clearContents();
FillMeasurements(); FillMeasurements();
if (qApp->patternType() == MeasurementsType::Individual)
{
connect(ui->tableWidgetMeasurements, &QTableWidget::cellChanged, this, &DialogIncrements::MeasurementChanged); connect(ui->tableWidgetMeasurements, &QTableWidget::cellChanged, this, &DialogIncrements::MeasurementChanged);
}
disconnect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, &DialogIncrements::IncrementChanged); disconnect(ui->tableWidgetIncrement, &QTableWidget::cellChanged, this, &DialogIncrements::IncrementChanged);
ui->tableWidgetIncrement->clearContents(); ui->tableWidgetIncrement->clearContents();
@ -448,7 +451,13 @@ void DialogIncrements::OpenTable()
if (qApp->patternType() == MeasurementsType::Individual) if (qApp->patternType() == MeasurementsType::Individual)
{ {
const QString filter(tr("Individual measurements (*.vit)")); const QString filter(tr("Individual measurements (*.vit)"));
const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), QDir::homePath(), filter);
//Use standard path to individual measurements
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
QString path = settings.value("paths/individual_measurements", QDir::homePath()).toString();
const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), path, filter);
if (filePath.isEmpty()) if (filePath.isEmpty())
{ {
return; return;
@ -488,7 +497,7 @@ void DialogIncrements::OpenTable()
else else
{ {
const QString filter(tr("Standard measurements (*.vst)")); const QString filter(tr("Standard measurements (*.vst)"));
const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), QDir::homePath(), filter); const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), qApp->pathToTables(), filter);
if (filePath.isEmpty()) if (filePath.isEmpty())
{ {
return; return;
@ -647,6 +656,16 @@ void DialogIncrements::AddIncrementToFile(const quint32 &id, const QString &name
list.at(0).appendChild(element); list.at(0).appendChild(element);
} }
//---------------------------------------------------------------------------------------------------------------------
void DialogIncrements::HideColumns(QTableWidget *table)
{
SCASSERT(table != nullptr);
table->setColumnHidden( 1, true );// calculated value
table->setColumnHidden( 3, true );// in sizes
table->setColumnHidden( 4, true );// in heights
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief cellChanged cell in table was changed * @brief cellChanged cell in table was changed
@ -714,7 +733,7 @@ void DialogIncrements::MeasurementChanged(qint32 row, qint32 column)
{ {
case 2:// value column case 2:// value column
{ {
const QTableWidgetItem *itemName = ui->tableWidgetMeasurements->item(row, 0); const QTableWidgetItem *itemName = ui->tableWidgetMeasurements->item(row, 0);// name column
QTableWidgetItem *item = ui->tableWidgetMeasurements->item(row, 2); QTableWidgetItem *item = ui->tableWidgetMeasurements->item(row, 2);
VMeasurement measur = data->GetMeasurement(qApp->VarFromUser(itemName->text())); VMeasurement measur = data->GetMeasurement(qApp->VarFromUser(itemName->text()));
@ -727,11 +746,6 @@ void DialogIncrements::MeasurementChanged(qint32 row, qint32 column)
return; return;
} }
m->SetAttribute(domElement, VIndividualMeasurements::AttrValue, item->text());
if (m->SaveDocument(doc->MPath()) == false)
{
qDebug()<<"Can't save measurement";
}
bool ok = false; bool ok = false;
const qreal base = item->text().replace(",", ".").toDouble(&ok); const qreal base = item->text().replace(",", ".").toDouble(&ok);
if (ok == false) if (ok == false)
@ -744,8 +758,19 @@ void DialogIncrements::MeasurementChanged(qint32 row, qint32 column)
{ {
measur.SetBase(base); measur.SetBase(base);
} }
// Convert value to measurements table unit
base = UnitConvertor(base, qApp->patternUnit(), m->MUnit());
m->SetAttribute(domElement, VIndividualMeasurements::AttrValue, QString("%1").atg(base));
if (m->SaveDocument(doc->MPath()) == false)
{
qDebug()<<"Can't save measurement";
}
data->ClearMeasurements(); data->ClearMeasurements();
m->Measurements(); m->Measurements();
emit FullUpdateTree(); emit FullUpdateTree();
break; break;
} }

View File

@ -100,6 +100,7 @@ private:
void FillLengthArcs(); void FillLengthArcs();
void AddIncrementToFile(const quint32 &id, const QString &name, const qreal &base, void AddIncrementToFile(const quint32 &id, const QString &name, const qreal &base,
const qreal &ksize, const qreal &kheight, const QString &description); const qreal &ksize, const qreal &kheight, const QString &description);
void HideColumns(QTableWidget *table);
}; };
#endif // DIALOGINCREMENTS_H #endif // DIALOGINCREMENTS_H