Add custom measurement in table.
--HG-- branch : feature
This commit is contained in:
parent
397f5b65bc
commit
b046aba66c
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
<string>Remove measurement</string>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tabMeasurements">
|
||||
<attribute name="icon">
|
||||
|
@ -82,6 +82,9 @@
|
|||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
|
@ -90,6 +93,11 @@
|
|||
<string>Name</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Calculated value</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Value</string>
|
||||
|
@ -606,7 +614,15 @@
|
|||
<addaction name="actionAboutQt"/>
|
||||
<addaction name="actionAboutTape"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuMeasurements">
|
||||
<property name="title">
|
||||
<string>Measurements</string>
|
||||
</property>
|
||||
<addaction name="actionAddKnown"/>
|
||||
<addaction name="actionAddCustom"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
<addaction name="menuMeasurements"/>
|
||||
<addaction name="menuWindow"/>
|
||||
<addaction name="menuHelp"/>
|
||||
</widget>
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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::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
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include <QStringList>
|
||||
|
||||
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;
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
|
||||
#include <QSharedData>
|
||||
|
||||
#include "vcontainer.h"
|
||||
|
||||
#ifdef Q_CC_GNU
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Weffc++"
|
||||
|
@ -40,23 +42,26 @@ 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 */
|
||||
VContainer data;
|
||||
quint32 id;
|
||||
QString formula;
|
||||
QString gui_text;
|
||||
|
||||
QString _tagName;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user