From b046aba66c196ba597157941351c43bcdb44906f Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 19 Jul 2015 15:28:01 +0300 Subject: [PATCH] Add custom measurement in table. --HG-- branch : feature --- src/app/tape/tmainwindow.cpp | 88 ++++++++++++++++++- src/app/tape/tmainwindow.h | 4 + src/app/tape/tmainwindow.ui | 18 +++- .../valentina/xml/vindividualmeasurements.cpp | 2 +- .../valentina/xml/vstandardmeasurements.cpp | 4 +- src/libs/vformat/vmeasurements.cpp | 43 ++++++++- src/libs/vformat/vmeasurements.h | 9 ++ .../vpatterndb/variables/vmeasurement.cpp | 18 ++-- src/libs/vpatterndb/variables/vmeasurement.h | 9 +- .../vpatterndb/variables/vmeasurement_p.h | 21 +++-- 10 files changed, 179 insertions(+), 37 deletions(-) diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index f5f239629..bc3d02189 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -340,6 +340,63 @@ void TMainWindow::ReadOnly(bool ro) } } +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::AddCustom() +{ + ui->tableWidget->setFocus(Qt::OtherFocusReason); + ui->tableWidget->blockSignals(true); + const qint32 currentRow = ui->tableWidget->rowCount(); + ui->tableWidget->insertRow( currentRow ); + + qint32 num = 1; + QString name; + do + { + name = QString("@" + tr("M_%1")).arg(num); + num++; + } while (data->IsUnique(name) == false); + + const int id = m->AddEmptyMeasurement(name); + + VMeasurement *meash; + if (mType == MeasurementsType::Standard) + { + meash = new VMeasurement(name, 0, 0, 0); + } + else + { + meash = new VMeasurement(data, id, name, 0, "0"); + } + data->AddVariable(name, meash); + + if (mType == MeasurementsType::Individual) + { + AddCell(name, currentRow, 0, id); // name + AddCell("0", currentRow, 2); // value + } + else + { + AddCell(name, currentRow, 0); // name + AddCell("0", currentRow, 1); // calculated value + AddCell("0", currentRow, 3); // base value + AddCell("0", currentRow, 4); // in sizes + AddCell("0", currentRow, 5); // in heights + } + + //ui->toolButtonRemove->setEnabled(true); + ui->tableWidget->blockSignals(false); + + ui->tableWidget->selectRow(currentRow); + + MeasurementsWasSaved(false); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::AddKnown() +{ + +} + //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::SetupMenu() { @@ -361,6 +418,10 @@ void TMainWindow::SetupMenu() connect(ui->actionQuit, &QAction::triggered, this, &TMainWindow::close); ui->actionQuit->setShortcuts(QKeySequence::Quit); + // Measurements + connect(ui->actionAddCustom, &QAction::triggered, this, &TMainWindow::AddCustom); + connect(ui->actionAddKnown, &QAction::triggered, this, &TMainWindow::AddKnown); + // Window connect(ui->menuWindow, &QMenu::aboutToShow, this, &TMainWindow::AboutToShowWindowMenu); AboutToShowWindowMenu(); @@ -466,13 +527,14 @@ void TMainWindow::InitTable() { if (mType == MeasurementsType::Standard) { - ui->tableWidget->setColumnHidden( 1, true );// value + ui->tableWidget->setColumnHidden( 2, true );// value } else { - ui->tableWidget->setColumnHidden( 2, true );// base value - ui->tableWidget->setColumnHidden( 3, true );// in sizes - ui->tableWidget->setColumnHidden( 4, true );// in heights + ui->tableWidget->setColumnHidden( 1, true );// calculated value + ui->tableWidget->setColumnHidden( 3, true );// base value + ui->tableWidget->setColumnHidden( 4, true );// in sizes + ui->tableWidget->setColumnHidden( 5, true );// in heights } } @@ -543,3 +605,21 @@ bool TMainWindow::MaybeSave() } return true; } + +//--------------------------------------------------------------------------------------------------------------------- +void TMainWindow::AddCell(const QString &text, int row, int column, int id) +{ + QTableWidgetItem *item = new QTableWidgetItem(text); + item->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter); + // set the item non-editable (view only), and non-selectable + Qt::ItemFlags flags = item->flags(); + flags &= ~(Qt::ItemIsEditable); // reset/clear the flag + item->setFlags(flags); + + if (mType == MeasurementsType::Individual && id >= 0) + { + item->setData(Qt::UserRole, id); + } + + ui->tableWidget->setItem(row, column, item); +} diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index f8030b7c4..bda635234 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -68,6 +68,8 @@ private slots: void SaveBirthDate(const QDate & date); void SaveNotes(); void ReadOnly(bool ro); + void AddCustom(); + void AddKnown(); private: Q_DISABLE_COPY(TMainWindow) @@ -87,6 +89,8 @@ private: bool SaveMeasurements(const QString &fileName, QString &error); bool MaybeSave(); + + void AddCell(const QString &text, int row, int column, int id = -1); }; #endif // TMAINWINDOW_H diff --git a/src/app/tape/tmainwindow.ui b/src/app/tape/tmainwindow.ui index ac009af45..6cd136904 100644 --- a/src/app/tape/tmainwindow.ui +++ b/src/app/tape/tmainwindow.ui @@ -32,7 +32,7 @@ Remove measurement - 1 + 0 @@ -82,6 +82,9 @@ true + + QAbstractItemView::SelectRows + true @@ -90,6 +93,11 @@ Name + + + Calculated value + + Value @@ -606,7 +614,15 @@ + + + Measurements + + + + + diff --git a/src/app/valentina/xml/vindividualmeasurements.cpp b/src/app/valentina/xml/vindividualmeasurements.cpp index de7ff2ba6..829e2570d 100644 --- a/src/app/valentina/xml/vindividualmeasurements.cpp +++ b/src/app/valentina/xml/vindividualmeasurements.cpp @@ -70,7 +70,7 @@ void VIndividualMeasurements::ReadMeasurement(const QDomElement &domElement, con { qreal value = GetParametrDouble(domElement, AttrValue, "0.0"); value = UnitConvertor(value, MUnit(), qApp->patternUnit()); - data->AddVariable(tag, new VMeasurement(tag, value, qApp->TrVars()->GuiText(tag), + data->AddVariable(tag, new VMeasurement(data, 0, tag, value, qApp->TrVars()->GuiText(tag), qApp->TrVars()->Description(tag), tag)); } diff --git a/src/app/valentina/xml/vstandardmeasurements.cpp b/src/app/valentina/xml/vstandardmeasurements.cpp index 41193656a..218c55e88 100644 --- a/src/app/valentina/xml/vstandardmeasurements.cpp +++ b/src/app/valentina/xml/vstandardmeasurements.cpp @@ -116,8 +116,8 @@ void VStandardMeasurements::ReadMeasurement(const QDomElement &domElement, const qWarning()<<"Standard table can't use inch unit."; } - data->AddVariable(tag, new VMeasurement(tag, value, size_increase, height_increase, qApp->TrVars()->GuiText(tag), - qApp->TrVars()->Description(tag), tag)); + data->AddVariable(tag, new VMeasurement(tag, value, size_increase, height_increase, + qApp->TrVars()->GuiText(tag), qApp->TrVars()->Description(tag), tag)); } diff --git a/src/libs/vformat/vmeasurements.cpp b/src/libs/vformat/vmeasurements.cpp index 6d1f52476..4867ca76c 100644 --- a/src/libs/vformat/vmeasurements.cpp +++ b/src/libs/vformat/vmeasurements.cpp @@ -44,8 +44,14 @@ const QString VMeasurements::TagBirthDate = QStringLiteral("birth-date"); const QString VMeasurements::TagSex = QStringLiteral("sex"); const QString VMeasurements::TagEmail = QStringLiteral("email"); const QString VMeasurements::TagReadOnly = QStringLiteral("read-only"); +const QString VMeasurements::TagMeasurement = QStringLiteral("m"); -const QString VMeasurements::AttrBase = QStringLiteral("base"); +const QString VMeasurements::AttrBase = QStringLiteral("base"); +const QString VMeasurements::AttrValue = QStringLiteral("value"); +const QString VMeasurements::AttrSizeIncrease = QStringLiteral("size_increase"); +const QString VMeasurements::AttrHeightIncrease = QStringLiteral("height_increase"); +const QString VMeasurements::AttrDescription = QStringLiteral("description"); +const QString VMeasurements::AttrName = QStringLiteral("name"); const QString VMeasurements::SexMale = QStringLiteral("male"); const QString VMeasurements::SexFemale = QStringLiteral("female"); @@ -55,7 +61,8 @@ const QString VMeasurements::SexUnknown = QStringLiteral("unknown"); VMeasurements::VMeasurements(VContainer *data) :VDomDocument(), data(data), - type(MeasurementsType::Unknown) + type(MeasurementsType::Unknown), + id(-1) { SCASSERT(data != nullptr) } @@ -64,7 +71,8 @@ VMeasurements::VMeasurements(VContainer *data) VMeasurements::VMeasurements(Unit unit, VContainer *data) :VDomDocument(), data(data), - type(MeasurementsType::Individual) + type(MeasurementsType::Individual), + id(-1) { SCASSERT(data != nullptr); @@ -75,7 +83,8 @@ VMeasurements::VMeasurements(Unit unit, VContainer *data) VMeasurements::VMeasurements(Unit unit, int baseSize, int baseHeight, VContainer *data) :VDomDocument(), data(data), - type(MeasurementsType::Standard) + type(MeasurementsType::Standard), + id(-1) { SCASSERT(data != nullptr); @@ -87,6 +96,32 @@ VMeasurements::~VMeasurements() { } +//--------------------------------------------------------------------------------------------------------------------- +int VMeasurements::AddEmptyMeasurement(QString &name) +{ + QDomElement element = createElement(TagMeasurement); + + SetAttribute(element, AttrName, name); + SetAttribute(element, AttrValue, QString("0")); + + if (type == MeasurementsType::Standard) + { + SetAttribute(element, AttrSizeIncrease, QString("0")); + SetAttribute(element, AttrHeightIncrease, QString("0")); + } + else + { + ++id; + SetAttribute(element, AttrId, id); + SetAttribute(element, AttrDescription, QString("")); + } + + QDomNodeList list = elementsByTagName(TagBodyMeasurements); + list.at(0).appendChild(element); + + return id; +} + //--------------------------------------------------------------------------------------------------------------------- MeasurementsType VMeasurements::Type() const { diff --git a/src/libs/vformat/vmeasurements.h b/src/libs/vformat/vmeasurements.h index 34c7ad154..f00b2f31c 100644 --- a/src/libs/vformat/vmeasurements.h +++ b/src/libs/vformat/vmeasurements.h @@ -43,6 +43,8 @@ public: VMeasurements(Unit unit, int baseSize, int baseHeight, VContainer *data); virtual ~VMeasurements() Q_DECL_OVERRIDE; + int AddEmptyMeasurement(QString &name); + MeasurementsType Type() const; Unit MUnit() const; int BaseSize() const; @@ -83,8 +85,14 @@ public: static const QString TagSex; static const QString TagEmail; static const QString TagReadOnly; + static const QString TagMeasurement; static const QString AttrBase; + static const QString AttrValue; + static const QString AttrSizeIncrease; + static const QString AttrHeightIncrease; + static const QString AttrDescription; + static const QString AttrName; static const QString SexMale; static const QString SexFemale; @@ -99,6 +107,7 @@ private: /** @brief data container with data. */ VContainer *data; MeasurementsType type; + int id; void CreateEmptyStandardFile(Unit unit, int baseSize, int baseHeight); void CreateEmptyIndividualFile(Unit unit); diff --git a/src/libs/vpatterndb/variables/vmeasurement.cpp b/src/libs/vpatterndb/variables/vmeasurement.cpp index eb9d62f99..7fac03e33 100644 --- a/src/libs/vpatterndb/variables/vmeasurement.cpp +++ b/src/libs/vpatterndb/variables/vmeasurement.cpp @@ -29,16 +29,6 @@ #include "vmeasurement.h" #include "vmeasurement_p.h" -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief VMeasurement create empty measurement - */ -VMeasurement::VMeasurement() - :VVariable(), d(new VMeasurementData) -{ - SetType(VarType::Measurement); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief VMeasurement create measurement for standard table @@ -50,7 +40,8 @@ VMeasurement::VMeasurement() * @param description measurement full description * @param tagName measurement's tag name in file */ -VMeasurement::VMeasurement(const QString &name, const qreal &base, const qreal &ksize, const qreal &kheight, +VMeasurement::VMeasurement(const QString &name, const qreal &base, const qreal &ksize, + const qreal &kheight, const QString &gui_text, const QString &description, const QString &tagName) :VVariable(name, base, ksize, kheight, description), d(new VMeasurementData(gui_text, tagName)) { @@ -66,9 +57,10 @@ VMeasurement::VMeasurement(const QString &name, const qreal &base, const qreal & * @param description measurement full description * @param tagName measurement's tag name in file */ -VMeasurement::VMeasurement(const QString &name, const qreal &base, const QString &gui_text, const QString &description, +VMeasurement::VMeasurement(VContainer *data, quint32 id, const QString &name, const qreal &base, + const QString &formula, const QString &gui_text, const QString &description, const QString &tagName) - :VVariable(name, base, description), d(new VMeasurementData(gui_text, tagName)) + :VVariable(name, base, description), d(new VMeasurementData(data, id, formula, gui_text, tagName)) { SetType(VarType::Measurement); } diff --git a/src/libs/vpatterndb/variables/vmeasurement.h b/src/libs/vpatterndb/variables/vmeasurement.h index 13291514f..ccf373209 100644 --- a/src/libs/vpatterndb/variables/vmeasurement.h +++ b/src/libs/vpatterndb/variables/vmeasurement.h @@ -35,6 +35,7 @@ #include class VMeasurementData; +class VContainer; /** * @brief The VMeasurement class keep data row of standard table @@ -42,12 +43,12 @@ class VMeasurementData; class VMeasurement :public VVariable { public: - VMeasurement(); - VMeasurement(const QString &name, const qreal &base, const qreal &ksize, const qreal &kheight, + VMeasurement(const QString &name, const qreal &base, const qreal &ksize, + const qreal &kheight, const QString &gui_text = QString(), const QString &description = QString(), + const QString &TagName = QString()); + VMeasurement(VContainer *data, quint32 id, const QString &name, const qreal &base, const QString &formula, const QString &gui_text = QString(), const QString &description = QString(), const QString &TagName = QString()); - VMeasurement(const QString &name, const qreal &base, const QString &gui_text = QString(), - const QString &description = QString(), const QString &TagName = QString()); VMeasurement(const VMeasurement &m); VMeasurement &operator=(const VMeasurement &m); virtual ~VMeasurement() Q_DECL_OVERRIDE; diff --git a/src/libs/vpatterndb/variables/vmeasurement_p.h b/src/libs/vpatterndb/variables/vmeasurement_p.h index bbe35215b..bd1969f95 100644 --- a/src/libs/vpatterndb/variables/vmeasurement_p.h +++ b/src/libs/vpatterndb/variables/vmeasurement_p.h @@ -31,6 +31,8 @@ #include +#include "vcontainer.h" + #ifdef Q_CC_GNU #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Weffc++" @@ -40,24 +42,27 @@ class VMeasurementData : public QSharedData { public: - VMeasurementData() - :gui_text(QString()), _tagName(QString()) + VMeasurementData(const QString &gui_text, const QString &tagName) + :data(VContainer(nullptr, nullptr)), id(0), gui_text(gui_text), _tagName(tagName) {} - VMeasurementData(const QString &gui_text, const QString &tagName) - :gui_text(gui_text), _tagName(tagName) + VMeasurementData(VContainer *data, quint32 id, const QString &formula, const QString &gui_text, + const QString &tagName) + :data(*data), id(id), formula(formula), gui_text(gui_text), _tagName(tagName) {} VMeasurementData(const VMeasurementData &m) - :QSharedData(m), gui_text(m.gui_text), _tagName(m._tagName) + :QSharedData(m), data(m.data), id(m.id), formula(m.formula), gui_text(m.gui_text), _tagName(m._tagName) {} virtual ~VMeasurementData(); /** @brief description description measurement */ - QString gui_text; - - QString _tagName; + VContainer data; + quint32 id; + QString formula; + QString gui_text; + QString _tagName; }; VMeasurementData::~VMeasurementData()