Show measurement details.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2015-07-21 18:28:20 +03:00
parent dfc7332356
commit 930c7cbf42
7 changed files with 231 additions and 11 deletions

View File

@ -70,6 +70,9 @@ public:
QString translationsPath() const;
template <typename T>
QString LocaleToString(const T &value);
public slots:
TMainWindow *NewMainWindow();
@ -91,4 +94,14 @@ private:
void Clean();
};
//---------------------------------------------------------------------------------------------------------------------
template <typename T>
inline QString MApplication::LocaleToString(const T &value)
{
QLocale loc;
qApp->Settings()->GetOsSeparator() ? loc = QLocale::system() : loc = QLocale(QLocale::C);
return loc.toString(value);
}
#endif // MAPPLICATION_H

View File

@ -3,7 +3,6 @@
<file>tapeicon/64x64/logo.png</file>
<file>tapeicon/16x16/info.png</file>
<file>tapeicon/16x16/measurement.png</file>
<file>tapeicon/24x24/equal.png</file>
<file>tapeicon/24x24/fx.png</file>
<file>tapeicon/24x24/orange_plus.png</file>
<file>tapeicon/24x24/red_plus.png</file>

View File

@ -31,6 +31,7 @@
#include "mapplication.h"
#include "dialogs/dialogabouttape.h"
#include "dialogs/dialognewmeasurements.h"
#include "../vpatterndb/calculator.h"
#include <QFileDialog>
#include <QFileInfo>
@ -347,6 +348,8 @@ void TMainWindow::ReadOnly(bool ro)
ui->comboBoxSex->setDisabled(ro);
ui->lineEditEmail->setDisabled(ro);
}
ui->groupBoxDetails->setDisabled(ro);
}
//---------------------------------------------------------------------------------------------------------------------
@ -420,6 +423,56 @@ void TMainWindow::ChangedHeight(const QString &text)
RefreshData();
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::ShowMData()
{
Controls(); // Buttons remove, up, down
if (ui->tableWidget->rowCount() > 0)
{
QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), 0);
QSharedPointer<VMeasurement> meash = data->GetVariable<VMeasurement>(nameField->text());
ui->lineEditName->setText(ClearCustomName(meash->GetName()));
if (meash->IsCustom())
{
ui->plainTextEditDescription->setPlainText(meash->GetDescription());
}
else
{
//Show from known description
ui->plainTextEditDescription->setPlainText("");
}
if (mType == MeasurementsType::Standard)
{
ui->labelCalculatedValue->setText(QString().setNum(data->GetTableValue(nameField->text(), mType)));
ui->doubleSpinBoxBaseValue->setValue(meash->GetBase());
ui->doubleSpinBoxInSizes->setValue(meash->GetKsize());
ui->doubleSpinBoxInHeights->setValue(meash->GetKheight());
}
else
{
EvalFormula(meash->GetFormula(), meash->GetData(), ui->labelCalculatedValue);
ui->plainTextEditFormula->setPlainText(qApp->TrVars()->FormulaToUser(meash->GetFormula()));
}
if (m->ReadOnly())
{
MFields(false);
}
else
{
MFields(true);
if (not meash->IsCustom())
{
ui->lineEditName->setEnabled(false);
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::SetupMenu()
{
@ -475,8 +528,8 @@ void TMainWindow::InitWindow()
delete ui->labelFormula;
delete ui->horizontalLayoutValue;
delete ui->plainTextEditFormula;
delete ui->pushButtonGrowLength;
delete ui->toolButtonExprLength;
delete ui->pushButtonGrow;
delete ui->toolButtonExpr;
// Tab Information
delete ui->labelGivenName;
@ -571,6 +624,8 @@ void TMainWindow::InitTable()
ui->tableWidget->setColumnHidden( 4, true );// in sizes
ui->tableWidget->setColumnHidden( 5, true );// in heights
}
connect(ui->tableWidget, &QTableWidget::itemSelectionChanged, this, &TMainWindow::ShowMData);
}
//---------------------------------------------------------------------------------------------------------------------
@ -704,3 +759,111 @@ void TMainWindow::RefreshData()
{
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::Controls()
{
if (m->ReadOnly())
{
ui->toolButtonRemove->setEnabled(false);
ui->toolButtonUp->setEnabled(false);
ui->toolButtonDown->setEnabled(false);
return;
}
if (ui->tableWidget->rowCount() > 0)
{
ui->toolButtonRemove->setEnabled(true);
}
else
{
ui->toolButtonRemove->setEnabled(false);
}
if (ui->tableWidget->rowCount() >= 2)
{
if (ui->tableWidget->currentRow() == 0)
{
ui->toolButtonUp->setEnabled(false);
ui->toolButtonDown->setEnabled(true);
}
else if (ui->tableWidget->currentRow() == ui->tableWidget->rowCount()-1)
{
ui->toolButtonUp->setEnabled(true);
ui->toolButtonDown->setEnabled(false);
}
else
{
ui->toolButtonUp->setEnabled(true);
ui->toolButtonDown->setEnabled(true);
}
}
else
{
ui->toolButtonUp->setEnabled(false);
ui->toolButtonDown->setEnabled(false);
}
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::MFields(bool enabled)
{
ui->lineEditName->setEnabled(enabled);
ui->plainTextEditDescription->setEnabled(enabled);
if (mType == MeasurementsType::Standard)
{
ui->doubleSpinBoxBaseValue->setEnabled(enabled);
ui->doubleSpinBoxInSizes->setEnabled(enabled);
ui->doubleSpinBoxInHeights->setEnabled(enabled);
}
else
{
ui->plainTextEditFormula->setEnabled(enabled);
ui->pushButtonGrow->setEnabled(enabled);
ui->toolButtonExpr->setEnabled(enabled);
}
}
//---------------------------------------------------------------------------------------------------------------------
QString TMainWindow::ClearCustomName(const QString &name) const
{
QString clear = name;
const int index = clear.indexOf("@");
if (index == 0)
{
clear.remove(0, 1);
}
return clear;
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::EvalFormula(const QString &formula, VContainer *data, QLabel *label)
{
const QString postfix = VDomDocument::UnitsToStr(mUnit);//Show unit in dialog lable (cm, mm or inch)
if (formula.isEmpty())
{
label->setText(tr("Error") + " (" + postfix + ")");
label->setToolTip(tr("Empty field"));
}
else
{
try
{
// Replace line return character with spaces for calc if exist
QString f = formula;
f.replace("\n", " ");
Calculator *cal = new Calculator(data, mType);
const qreal result = cal->EvalFormula(f);
delete cal;
label->setText(qApp->LocaleToString(result) + " " +postfix);
label->setToolTip(tr("Value"));
}
catch (qmu::QmuParserError &e)
{
label->setText(tr("Error") + " (" + postfix + ")");
label->setToolTip(tr("Parser error: %1").arg(e.GetMsg()));
}
}
}

View File

@ -76,6 +76,8 @@ private slots:
void ChangedSize(const QString &text);
void ChangedHeight(const QString & text);
void ShowMData();
private:
Q_DISABLE_COPY(TMainWindow)
Ui::TMainWindow *ui;
@ -104,6 +106,13 @@ private:
void SetDefaultSize(int value);
void RefreshData();
void Controls();
void MFields(bool enabled);
QString ClearCustomName(const QString &name) const;
void EvalFormula(const QString &formula, VContainer *data, QLabel *label);
};
#endif // TMAINWINDOW_H

View File

@ -93,13 +93,16 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<widget class="QGroupBox" name="groupBoxDetails">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>2</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Details</string>
</property>
<property name="title">
<string>Details</string>
</property>
@ -112,7 +115,7 @@
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="lineEdit">
<widget class="QLineEdit" name="lineEditName">
<property name="enabled">
<bool>false</bool>
</property>
@ -150,7 +153,7 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonGrowLength">
<widget class="QPushButton" name="pushButtonGrow">
<property name="enabled">
<bool>false</bool>
</property>
@ -188,7 +191,7 @@
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButtonExprLength">
<widget class="QToolButton" name="toolButtonExpr">
<property name="enabled">
<bool>false</bool>
</property>
@ -259,7 +262,7 @@
</widget>
</item>
<item row="9" column="1">
<widget class="QPlainTextEdit" name="plainTextEdit">
<widget class="QPlainTextEdit" name="plainTextEditDescription">
<property name="enabled">
<bool>false</bool>
</property>

View File

@ -208,3 +208,28 @@ void VMeasurement::setTagName(const QString &tagName)
{
d->_tagName = tagName;
}
//---------------------------------------------------------------------------------------------------------------------
QString VMeasurement::GetFormula() const
{
return d->formula;
}
//---------------------------------------------------------------------------------------------------------------------
bool VMeasurement::IsCustom() const
{
if (GetName().indexOf("@") == 0)
{
return true;
}
else
{
return false;
}
}
//---------------------------------------------------------------------------------------------------------------------
VContainer *VMeasurement::GetData()
{
return &d->data;
}

View File

@ -54,8 +54,16 @@ public:
virtual ~VMeasurement() Q_DECL_OVERRIDE;
QString GetGuiText() const;
QString TagName() const;
void setTagName(const QString &TagName);
QString GetFormula() const;
bool IsCustom() const;
VContainer *GetData();
static QStringList ListHeights(QMap<GHeights, bool> heights, Unit patternUnit);
static QStringList ListSizes(QMap<GSizes, bool> sizes, Unit patternUnit);
static QStringList WholeListHeights(Unit patternUnit);