2015-07-24 12:06:39 +02:00
|
|
|
|
/************************************************************************
|
2015-07-10 11:49:37 +02:00
|
|
|
|
**
|
|
|
|
|
** @file tmainwindow.cpp
|
|
|
|
|
** @author Roman Telezhynskyi <dismine(at)gmail.com>
|
|
|
|
|
** @date 10 7, 2015
|
|
|
|
|
**
|
|
|
|
|
** @brief
|
|
|
|
|
** @copyright
|
|
|
|
|
** This source code is part of the Valentine project, a pattern making
|
|
|
|
|
** program, whose allow create and modeling patterns of clothing.
|
|
|
|
|
** Copyright (C) 2015 Valentina project
|
|
|
|
|
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
|
|
|
|
|
**
|
|
|
|
|
** Valentina is free software: you can redistribute it and/or modify
|
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
** (at your option) any later version.
|
|
|
|
|
**
|
|
|
|
|
** Valentina is distributed in the hope that it will be useful,
|
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
|
**
|
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
|
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
**
|
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "tmainwindow.h"
|
|
|
|
|
#include "ui_tmainwindow.h"
|
2015-07-12 19:38:30 +02:00
|
|
|
|
#include "dialogs/dialogabouttape.h"
|
2015-07-13 12:48:29 +02:00
|
|
|
|
#include "dialogs/dialognewmeasurements.h"
|
2015-08-01 11:39:32 +02:00
|
|
|
|
#include "dialogs/dialogmdatabase.h"
|
2015-08-02 17:27:18 +02:00
|
|
|
|
#include "dialogs/tapeconfigdialog.h"
|
2015-07-21 17:28:20 +02:00
|
|
|
|
#include "../vpatterndb/calculator.h"
|
2015-07-22 11:44:31 +02:00
|
|
|
|
#include "../ifc/ifcdef.h"
|
2015-07-25 14:59:40 +02:00
|
|
|
|
#include "../ifc/xml/vvitconverter.h"
|
|
|
|
|
#include "../ifc/xml/vvstconverter.h"
|
2015-08-11 16:52:18 +02:00
|
|
|
|
#include "../ifc/xml/vpatternconverter.h"
|
2015-09-14 13:53:49 +02:00
|
|
|
|
#include "../vmisc/vlockguard.h"
|
2015-09-28 20:54:41 +02:00
|
|
|
|
#include "../vmisc/vsysexits.h"
|
2015-08-11 16:52:18 +02:00
|
|
|
|
#include "vlitepattern.h"
|
2015-07-22 11:47:51 +02:00
|
|
|
|
#include "../qmuparser/qmudef.h"
|
2015-07-24 14:06:53 +02:00
|
|
|
|
#include "../vtools/dialogs/support/dialogeditwrongformula.h"
|
2015-08-01 19:09:10 +02:00
|
|
|
|
#include "version.h"
|
2015-07-24 14:06:53 +02:00
|
|
|
|
#include "mapplication.h" // Should be last because of definning qApp
|
2015-07-10 11:49:37 +02:00
|
|
|
|
|
2015-07-18 14:39:33 +02:00
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QMessageBox>
|
2015-07-21 15:18:10 +02:00
|
|
|
|
#include <QComboBox>
|
2015-07-25 15:37:07 +02:00
|
|
|
|
#include <QProcess>
|
2015-07-18 14:39:33 +02:00
|
|
|
|
|
2015-07-21 18:24:47 +02:00
|
|
|
|
#define DIALOG_MAX_FORMULA_HEIGHT 64
|
|
|
|
|
|
2015-10-20 16:32:01 +02:00
|
|
|
|
#if defined(Q_CC_CLANG)
|
2015-10-19 15:21:06 +02:00
|
|
|
|
#pragma clang diagnostic push
|
|
|
|
|
#pragma clang diagnostic ignored "-Wmissing-prototypes"
|
2015-10-20 16:32:01 +02:00
|
|
|
|
#elif defined(Q_CC_INTEL)
|
|
|
|
|
#pragma warning( push )
|
|
|
|
|
#pragma warning( disable: 1418 )
|
2015-10-19 15:21:06 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2015-08-01 19:09:10 +02:00
|
|
|
|
Q_LOGGING_CATEGORY(tMainWindow, "t.mainwindow")
|
|
|
|
|
|
2015-10-20 16:32:01 +02:00
|
|
|
|
#if defined(Q_CC_CLANG)
|
2015-10-19 15:21:06 +02:00
|
|
|
|
#pragma clang diagnostic pop
|
2015-10-20 16:32:01 +02:00
|
|
|
|
#elif defined(Q_CC_INTEL)
|
|
|
|
|
#pragma warning( pop )
|
2015-10-19 15:21:06 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
2015-09-29 17:46:00 +02:00
|
|
|
|
// We need this enum in case we will add or delete a column. And also make code more readable.
|
|
|
|
|
enum {ColumnName = 0, ColumnFullName, ColumnCalcValue, ColumnFormula, ColumnBaseValue, ColumnInSizes, ColumnInHeights};
|
|
|
|
|
|
2015-07-10 11:49:37 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
TMainWindow::TMainWindow(QWidget *parent)
|
|
|
|
|
:QMainWindow(parent),
|
2015-07-15 09:16:59 +02:00
|
|
|
|
ui(new Ui::TMainWindow),
|
|
|
|
|
m(nullptr),
|
2015-07-16 11:38:54 +02:00
|
|
|
|
data(nullptr),
|
|
|
|
|
mUnit(Unit::Cm),
|
2015-08-18 13:53:30 +02:00
|
|
|
|
pUnit(Unit::Cm),
|
2015-07-18 14:39:33 +02:00
|
|
|
|
mType(MeasurementsType::Individual),
|
2015-07-21 15:18:10 +02:00
|
|
|
|
curFile(),
|
|
|
|
|
gradationHeights(nullptr),
|
2015-07-21 18:24:47 +02:00
|
|
|
|
gradationSizes(nullptr),
|
2015-08-18 13:53:30 +02:00
|
|
|
|
comboBoxUnits(nullptr),
|
2015-08-01 19:09:10 +02:00
|
|
|
|
formulaBaseHeight(0),
|
2015-09-15 18:49:24 +02:00
|
|
|
|
lock(nullptr),
|
2015-10-16 19:26:05 +02:00
|
|
|
|
search(),
|
|
|
|
|
labelGradationHeights(nullptr),
|
|
|
|
|
labelGradationSizes(nullptr),
|
2015-10-29 17:20:59 +01:00
|
|
|
|
labelPatternUnit(nullptr),
|
|
|
|
|
actionDockDiagram(nullptr),
|
|
|
|
|
dockDiagramVisible(false),
|
|
|
|
|
isInitialized(false)
|
2015-07-10 11:49:37 +02:00
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
2015-09-15 18:49:24 +02:00
|
|
|
|
search = QSharedPointer<VTableSearch>(new VTableSearch(ui->tableWidget));
|
2015-07-10 13:22:46 +02:00
|
|
|
|
ui->tabWidget->setVisible(false);
|
2015-07-12 16:19:53 +02:00
|
|
|
|
|
2015-07-21 15:18:10 +02:00
|
|
|
|
ui->mainToolBar->setContextMenuPolicy(Qt::PreventContextMenu);
|
|
|
|
|
ui->toolBarGradation->setContextMenuPolicy(Qt::PreventContextMenu);
|
|
|
|
|
|
2015-07-12 16:19:53 +02:00
|
|
|
|
SetupMenu();
|
2015-07-18 14:50:34 +02:00
|
|
|
|
|
2015-08-01 15:29:28 +02:00
|
|
|
|
setWindowTitle(tr("untitled %1").arg(qApp->MainWindows().size()+1));
|
2015-08-01 19:09:10 +02:00
|
|
|
|
|
|
|
|
|
ReadSettings();
|
2015-07-10 11:49:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
TMainWindow::~TMainWindow()
|
|
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
|
delete data;
|
|
|
|
|
delete m;
|
2015-07-10 11:49:37 +02:00
|
|
|
|
delete ui;
|
|
|
|
|
}
|
2015-07-10 13:14:55 +02:00
|
|
|
|
|
2015-07-25 14:59:40 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
QString TMainWindow::CurrentFile() const
|
|
|
|
|
{
|
|
|
|
|
return curFile;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-08 16:33:37 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::RetranslateTable()
|
|
|
|
|
{
|
2015-09-03 12:31:23 +02:00
|
|
|
|
if (m != nullptr)
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
RefreshTable();
|
2015-10-16 19:26:05 +02:00
|
|
|
|
ShowUnits();
|
2015-09-03 12:31:23 +02:00
|
|
|
|
ui->tableWidget->selectRow(row);
|
|
|
|
|
}
|
2015-08-08 16:33:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-18 15:31:21 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SetBaseMHeight(int height)
|
|
|
|
|
{
|
|
|
|
|
if (m != nullptr)
|
|
|
|
|
{
|
|
|
|
|
if (mType == MeasurementsType::Standard)
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
data->SetHeight(UnitConvertor(height, Unit::Cm, mUnit));
|
|
|
|
|
RefreshData();
|
|
|
|
|
ui->tableWidget->selectRow(row);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SetBaseMSize(int size)
|
|
|
|
|
{
|
|
|
|
|
if (m != nullptr)
|
|
|
|
|
{
|
|
|
|
|
if (mType == MeasurementsType::Standard)
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
data->SetSize(UnitConvertor(size, Unit::Cm, mUnit));
|
|
|
|
|
RefreshData();
|
|
|
|
|
ui->tableWidget->selectRow(row);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SetPUnit(Unit unit)
|
|
|
|
|
{
|
|
|
|
|
pUnit = unit;
|
|
|
|
|
UpdatePatternUnit();
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-10 13:14:55 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-11 11:06:14 +02:00
|
|
|
|
bool TMainWindow::LoadFile(const QString &path)
|
2015-07-12 16:19:53 +02:00
|
|
|
|
{
|
2015-07-25 14:59:40 +02:00
|
|
|
|
if (m == nullptr)
|
|
|
|
|
{
|
2015-08-18 16:53:33 +02:00
|
|
|
|
if (not QFileInfo(path).exists())
|
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
|
qCCritical(tMainWindow, "%s", qUtf8Printable(tr("File '%1' doesn't exist!").arg(path)));
|
2015-09-28 20:54:41 +02:00
|
|
|
|
if (qApp->IsTestMode())
|
|
|
|
|
{
|
2015-10-11 11:06:14 +02:00
|
|
|
|
qApp->exit(V_EX_NOINPUT);
|
2015-10-01 17:21:13 +02:00
|
|
|
|
}
|
2015-10-11 11:06:14 +02:00
|
|
|
|
return false;
|
2015-08-18 16:53:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-25 14:59:40 +02:00
|
|
|
|
// Check if file already opened
|
|
|
|
|
QList<TMainWindow*>list = qApp->MainWindows();
|
|
|
|
|
for (int i = 0; i < list.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if (list.at(i)->CurrentFile() == path)
|
|
|
|
|
{
|
|
|
|
|
list.at(i)->activateWindow();
|
2015-08-01 19:09:10 +02:00
|
|
|
|
close();
|
2015-10-11 11:06:14 +02:00
|
|
|
|
return false;
|
2015-08-01 19:09:10 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-26 08:57:20 +01:00
|
|
|
|
VlpCreateLock(lock, QFileInfo(path).fileName());
|
2015-09-14 13:53:49 +02:00
|
|
|
|
|
2015-10-09 11:50:37 +02:00
|
|
|
|
if (not lock->IsLocked())
|
2015-08-01 19:09:10 +02:00
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
|
qCCritical(tMainWindow, "%s", qUtf8Printable(tr("This file already opened in another window.")));
|
|
|
|
|
if (qApp->IsTestMode())
|
|
|
|
|
{
|
2015-10-11 11:06:14 +02:00
|
|
|
|
qApp->exit(V_EX_NOINPUT);
|
2015-10-01 17:21:13 +02:00
|
|
|
|
}
|
2015-10-11 11:06:14 +02:00
|
|
|
|
return false;
|
2015-07-25 14:59:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
data = new VContainer(qApp->TrVars(), &mUnit);
|
|
|
|
|
|
|
|
|
|
m = new VMeasurements(data);
|
|
|
|
|
m->setXMLContent(path);
|
|
|
|
|
|
|
|
|
|
mType = m->Type();
|
|
|
|
|
|
|
|
|
|
if (mType == MeasurementsType::Unknown)
|
|
|
|
|
{
|
2015-09-22 16:41:05 +02:00
|
|
|
|
VException e(tr("File has unknown format."));
|
2015-07-25 14:59:40 +02:00
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mType == MeasurementsType::Standard)
|
|
|
|
|
{
|
|
|
|
|
VVSTConverter converter(path);
|
|
|
|
|
converter.Convert();
|
|
|
|
|
|
|
|
|
|
VDomDocument::ValidateXML(VVSTConverter::CurrentSchema, path);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
VVITConverter converter(path);
|
|
|
|
|
converter.Convert();
|
|
|
|
|
|
|
|
|
|
VDomDocument::ValidateXML(VVITConverter::CurrentSchema, path);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-07 13:51:21 +02:00
|
|
|
|
m->setXMLContent(path);// Read again after conversion
|
2015-09-25 12:45:58 +02:00
|
|
|
|
|
|
|
|
|
if (not m->IsDefinedKnownNamesValid())
|
|
|
|
|
{
|
|
|
|
|
VException e(tr("File contains invalid known measurement(s)."));
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-25 14:59:40 +02:00
|
|
|
|
mUnit = m->MUnit();
|
2015-08-18 13:53:30 +02:00
|
|
|
|
pUnit = mUnit;
|
2015-07-25 14:59:40 +02:00
|
|
|
|
|
|
|
|
|
data->SetHeight(m->BaseHeight());
|
|
|
|
|
data->SetSize(m->BaseSize());
|
|
|
|
|
|
|
|
|
|
ui->labelToolTip->setVisible(false);
|
|
|
|
|
ui->tabWidget->setVisible(true);
|
|
|
|
|
|
|
|
|
|
SetCurrentFile(path);
|
|
|
|
|
|
|
|
|
|
InitWindow();
|
|
|
|
|
|
|
|
|
|
RefreshData();
|
|
|
|
|
|
|
|
|
|
if (ui->tableWidget->rowCount() > 0)
|
|
|
|
|
{
|
|
|
|
|
ui->tableWidget->selectRow(0);
|
|
|
|
|
}
|
2015-07-25 17:18:01 +02:00
|
|
|
|
|
|
|
|
|
GUIReadOnly(m->ReadOnly()); // Keep last
|
2015-07-25 14:59:40 +02:00
|
|
|
|
}
|
|
|
|
|
catch (VException &e)
|
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
|
qCCritical(tMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")),
|
|
|
|
|
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
|
2015-07-25 14:59:40 +02:00
|
|
|
|
ui->labelToolTip->setVisible(true);
|
|
|
|
|
ui->tabWidget->setVisible(false);
|
|
|
|
|
delete m;
|
|
|
|
|
m = nullptr;
|
|
|
|
|
delete data;
|
|
|
|
|
data = nullptr;
|
2015-09-15 20:21:51 +02:00
|
|
|
|
lock.reset();
|
2015-10-01 17:21:13 +02:00
|
|
|
|
|
|
|
|
|
if (qApp->IsTestMode())
|
|
|
|
|
{
|
2015-10-11 11:06:14 +02:00
|
|
|
|
qApp->exit(V_EX_NOINPUT);
|
2015-10-01 17:21:13 +02:00
|
|
|
|
}
|
2015-10-11 11:06:14 +02:00
|
|
|
|
return false;
|
2015-07-25 14:59:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
qApp->NewMainWindow();
|
2015-10-11 11:06:14 +02:00
|
|
|
|
return qApp->MainWindow()->LoadFile(path);
|
2015-07-25 14:59:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-11 11:06:14 +02:00
|
|
|
|
return true;
|
2015-07-12 16:19:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-13 12:48:29 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::FileNew()
|
|
|
|
|
{
|
2015-07-15 09:16:59 +02:00
|
|
|
|
if (m == nullptr)
|
2015-07-13 12:48:29 +02:00
|
|
|
|
{
|
2015-07-15 09:16:59 +02:00
|
|
|
|
DialogNewMeasurements measurements(this);
|
|
|
|
|
if (measurements.exec() == QDialog::Rejected)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-07-13 12:48:29 +02:00
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
|
mUnit = measurements.MUnit();
|
2015-08-18 13:53:30 +02:00
|
|
|
|
pUnit = mUnit;
|
2015-07-16 11:38:54 +02:00
|
|
|
|
mType = measurements.Type();
|
|
|
|
|
|
|
|
|
|
data = new VContainer(qApp->TrVars(), &mUnit);
|
2015-07-21 15:18:10 +02:00
|
|
|
|
data->SetHeight(measurements.BaseHeight());
|
|
|
|
|
data->SetSize(measurements.BaseSize());
|
2015-07-16 11:38:54 +02:00
|
|
|
|
|
|
|
|
|
if (mType == MeasurementsType::Standard)
|
|
|
|
|
{
|
|
|
|
|
m = new VMeasurements(mUnit, measurements.BaseSize(), measurements.BaseHeight(), data);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m = new VMeasurements(mUnit, data);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-18 14:39:33 +02:00
|
|
|
|
SetCurrentFile("");
|
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
|
InitWindow();
|
2015-07-25 17:18:01 +02:00
|
|
|
|
|
|
|
|
|
GUIReadOnly(m->ReadOnly()); // Keep last
|
2015-07-15 09:16:59 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
qApp->NewMainWindow();
|
|
|
|
|
qApp->MainWindow()->FileNew();
|
|
|
|
|
}
|
2015-07-13 12:48:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-12 17:56:34 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-07-25 14:59:40 +02:00
|
|
|
|
void TMainWindow::OpenIndividual()
|
|
|
|
|
{
|
|
|
|
|
if (m == nullptr)
|
|
|
|
|
{
|
2015-09-11 12:04:01 +02:00
|
|
|
|
const QString filter = tr("Individual measurements (*.vit);;Standard measurements (*.vst);;All files (*.*)");
|
2015-07-25 14:59:40 +02:00
|
|
|
|
//Use standard path to individual measurements
|
|
|
|
|
const QString pathTo = qApp->TapeSettings()->GetPathIndividualMeasurements();
|
|
|
|
|
Open(pathTo, filter);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
qApp->NewMainWindow();
|
|
|
|
|
qApp->MainWindow()->OpenIndividual();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::OpenStandard()
|
2015-07-12 17:56:34 +02:00
|
|
|
|
{
|
2015-07-15 09:16:59 +02:00
|
|
|
|
if (m == nullptr)
|
|
|
|
|
{
|
2015-09-11 12:04:01 +02:00
|
|
|
|
const QString filter = tr("Standard measurements (*.vst);;Individual measurements (*.vit);;All files (*.*)");
|
|
|
|
|
//Use standard path to standard measurements
|
2015-07-25 14:59:40 +02:00
|
|
|
|
const QString pathTo = qApp->TapeSettings()->GetPathStandardMeasurements();
|
|
|
|
|
Open(pathTo, filter);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
qApp->NewMainWindow();
|
|
|
|
|
qApp->MainWindow()->OpenStandard();
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-12 17:56:34 +02:00
|
|
|
|
|
2015-07-25 14:59:40 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::OpenTemplate()
|
|
|
|
|
{
|
|
|
|
|
if (m == nullptr)
|
|
|
|
|
{
|
2015-09-11 12:04:01 +02:00
|
|
|
|
const QString filter = tr("Measurements (*.vst *.vit);;All files (*.*)");
|
|
|
|
|
//Use standard path to template files
|
2015-07-25 14:59:40 +02:00
|
|
|
|
const QString pathTo = qApp->TapeSettings()->GetPathTemplate();
|
|
|
|
|
Open(pathTo, filter);
|
2015-10-08 11:57:00 +02:00
|
|
|
|
|
|
|
|
|
if (m != nullptr)
|
|
|
|
|
{// The file was opened.
|
|
|
|
|
SetCurrentFile(""); // Force user to to save new file
|
2015-10-13 15:45:03 +02:00
|
|
|
|
lock.reset();// remove lock from template
|
2015-10-08 11:57:00 +02:00
|
|
|
|
}
|
2015-07-15 09:16:59 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
qApp->NewMainWindow();
|
2015-07-25 14:59:40 +02:00
|
|
|
|
qApp->MainWindow()->OpenTemplate();
|
2015-07-15 09:16:59 +02:00
|
|
|
|
}
|
2015-07-12 17:56:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-15 14:37:10 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::CreateFromExisting()
|
|
|
|
|
{
|
|
|
|
|
if (m == nullptr)
|
|
|
|
|
{
|
|
|
|
|
const QString filter = tr("Individual measurements (*.vit)");
|
|
|
|
|
//Use standard path to standard measurements
|
|
|
|
|
const QString pathTo = qApp->TapeSettings()->GetPathIndividualMeasurements();
|
|
|
|
|
const QString mPath = QFileDialog::getOpenFileName(this, tr("Select file"), pathTo, filter);
|
|
|
|
|
|
|
|
|
|
if (not mPath.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
LoadFromExistingFile(mPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
qApp->NewMainWindow();
|
|
|
|
|
qApp->MainWindow()->CreateFromExisting();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-15 18:49:24 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::Find(const QString &term)
|
|
|
|
|
{
|
|
|
|
|
search->Find(term);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::FindPrevious()
|
|
|
|
|
{
|
|
|
|
|
search->FindPrevious();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::FindNext()
|
|
|
|
|
{
|
|
|
|
|
search->FindNext();
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-18 15:01:57 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::closeEvent(QCloseEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (MaybeSave())
|
|
|
|
|
{
|
2015-08-01 19:09:10 +02:00
|
|
|
|
WriteSettings();
|
2015-07-18 15:01:57 +02:00
|
|
|
|
event->accept();
|
2015-08-01 15:06:12 +02:00
|
|
|
|
deleteLater();
|
2015-07-18 15:01:57 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
event->ignore();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-08 16:33:37 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::changeEvent(QEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (event->type() == QEvent::LanguageChange)
|
|
|
|
|
{
|
|
|
|
|
// retranslate designer form (single inheritance approach)
|
|
|
|
|
ui->retranslateUi(this);
|
2015-10-16 19:26:05 +02:00
|
|
|
|
|
|
|
|
|
if (mType == MeasurementsType::Standard)
|
|
|
|
|
{
|
|
|
|
|
ui->labelMType->setText(tr("Standard measurements"));
|
|
|
|
|
ui->labelBaseSizeValue->setText(QString().setNum(m->BaseSize()) + " " +
|
|
|
|
|
VDomDocument::UnitsToStr(m->MUnit(), true));
|
|
|
|
|
ui->labelBaseHeightValue->setText(QString().setNum(m->BaseHeight()) + " " +
|
|
|
|
|
VDomDocument::UnitsToStr(m->MUnit(), true));
|
|
|
|
|
|
|
|
|
|
labelGradationHeights = new QLabel(tr("Height: "));
|
|
|
|
|
labelGradationSizes = new QLabel(tr("Size: "));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->labelMType->setText(tr("Individual measurements"));
|
|
|
|
|
|
|
|
|
|
const qint32 index = ui->comboBoxGender->currentIndex();
|
|
|
|
|
ui->comboBoxGender->blockSignals(true);
|
|
|
|
|
ui->comboBoxGender->clear();
|
|
|
|
|
InitGender(ui->comboBoxGender);
|
|
|
|
|
ui->comboBoxGender->setCurrentIndex(index);
|
|
|
|
|
ui->comboBoxGender->blockSignals(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const qint32 index = ui->comboBoxPMSystem->currentIndex();
|
|
|
|
|
ui->comboBoxPMSystem->blockSignals(true);
|
|
|
|
|
ui->comboBoxPMSystem->clear();
|
|
|
|
|
InitPMSystems(ui->comboBoxPMSystem);
|
|
|
|
|
ui->comboBoxPMSystem->setCurrentIndex(index);
|
|
|
|
|
ui->comboBoxPMSystem->blockSignals(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
labelPatternUnit = new QLabel(tr("Pattern unit:"));
|
|
|
|
|
|
2015-11-05 13:06:45 +01:00
|
|
|
|
if (comboBoxUnits != nullptr)
|
|
|
|
|
{
|
|
|
|
|
const qint32 index = comboBoxUnits->currentIndex();
|
|
|
|
|
comboBoxUnits->blockSignals(true);
|
|
|
|
|
comboBoxUnits->clear();
|
|
|
|
|
InitComboBoxUnits();
|
|
|
|
|
comboBoxUnits->setCurrentIndex(index);
|
|
|
|
|
comboBoxUnits->blockSignals(false);
|
|
|
|
|
}
|
2015-10-16 19:26:05 +02:00
|
|
|
|
}
|
2015-08-08 16:33:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// remember to call base class implementation
|
|
|
|
|
QMainWindow::changeEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-29 17:20:59 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::showEvent(QShowEvent *event)
|
|
|
|
|
{
|
|
|
|
|
QMainWindow::showEvent( event );
|
|
|
|
|
if ( event->spontaneous() )
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isInitialized)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// do your init stuff here
|
|
|
|
|
|
|
|
|
|
dockDiagramVisible = ui->dockWidgetDiagram->isVisible();
|
|
|
|
|
ui->dockWidgetDiagram->setVisible(false);
|
|
|
|
|
|
|
|
|
|
isInitialized = true;//first show windows are held
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-12 17:56:34 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::FileSave()
|
|
|
|
|
{
|
2015-07-18 14:39:33 +02:00
|
|
|
|
if (curFile.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
return FileSaveAs();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
QString error;
|
|
|
|
|
bool result = SaveMeasurements(curFile, error);
|
|
|
|
|
if (not result)
|
|
|
|
|
{
|
|
|
|
|
QMessageBox messageBox;
|
|
|
|
|
messageBox.setIcon(QMessageBox::Warning);
|
|
|
|
|
messageBox.setInformativeText(tr("Could not save file"));
|
|
|
|
|
messageBox.setDefaultButton(QMessageBox::Ok);
|
|
|
|
|
messageBox.setDetailedText(error);
|
|
|
|
|
messageBox.setStandardButtons(QMessageBox::Ok);
|
|
|
|
|
messageBox.exec();
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-12 17:56:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::FileSaveAs()
|
|
|
|
|
{
|
2015-07-18 14:39:33 +02:00
|
|
|
|
QString filters;
|
|
|
|
|
QString fName = tr("measurements");
|
|
|
|
|
QString suffix;
|
|
|
|
|
if (mType == MeasurementsType::Individual)
|
|
|
|
|
{
|
2015-07-25 14:59:40 +02:00
|
|
|
|
filters = tr("Individual measurements (*.vit)");
|
|
|
|
|
suffix = "vit";
|
2015-07-18 14:39:33 +02:00
|
|
|
|
fName += "." + suffix;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-07-25 14:59:40 +02:00
|
|
|
|
filters = tr("Standard measurements (*.vst)");
|
|
|
|
|
suffix = "vst";
|
2015-07-18 14:39:33 +02:00
|
|
|
|
fName += "." + suffix;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString dir;
|
|
|
|
|
if (curFile.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
if (mType == MeasurementsType::Individual)
|
|
|
|
|
{
|
2015-07-25 14:59:40 +02:00
|
|
|
|
dir = qApp->TapeSettings()->GetPathIndividualMeasurements() + "/" + fName;
|
2015-07-18 14:39:33 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-07-25 14:59:40 +02:00
|
|
|
|
dir = qApp->TapeSettings()->GetPathStandardMeasurements() + "/" + fName;
|
2015-07-18 14:39:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dir = QFileInfo(curFile).absolutePath() + "/" + fName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"), dir, filters);
|
|
|
|
|
|
|
|
|
|
if (fileName.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-07-12 17:56:34 +02:00
|
|
|
|
|
2015-07-18 14:39:33 +02:00
|
|
|
|
QFileInfo f( fileName );
|
|
|
|
|
if (f.suffix().isEmpty() && f.suffix() != suffix)
|
|
|
|
|
{
|
|
|
|
|
fileName += "." + suffix;
|
|
|
|
|
}
|
2015-09-16 13:29:01 +02:00
|
|
|
|
|
|
|
|
|
if (QFileInfo(fileName).exists())
|
|
|
|
|
{
|
2015-10-09 11:50:37 +02:00
|
|
|
|
// Temporary try to lock the file before saving
|
2015-10-26 08:57:20 +01:00
|
|
|
|
VLockGuard<char> tmp(fileName);
|
2015-09-16 13:29:01 +02:00
|
|
|
|
if (not tmp.IsLocked())
|
|
|
|
|
{
|
2015-10-09 11:50:37 +02:00
|
|
|
|
qCCritical(tMainWindow, "%s",
|
|
|
|
|
qUtf8Printable(tr("Failed to lock. This file already opened in another window.")));
|
|
|
|
|
return;
|
2015-09-16 13:29:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-18 14:39:33 +02:00
|
|
|
|
QString error;
|
|
|
|
|
bool result = SaveMeasurements(fileName, error);
|
|
|
|
|
if (result == false)
|
|
|
|
|
{
|
|
|
|
|
QMessageBox messageBox;
|
|
|
|
|
messageBox.setIcon(QMessageBox::Warning);
|
|
|
|
|
messageBox.setInformativeText(tr("Could not save file"));
|
|
|
|
|
messageBox.setDefaultButton(QMessageBox::Ok);
|
|
|
|
|
messageBox.setDetailedText(error);
|
|
|
|
|
messageBox.setStandardButtons(QMessageBox::Ok);
|
|
|
|
|
messageBox.exec();
|
2015-09-16 13:29:01 +02:00
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-26 08:57:20 +01:00
|
|
|
|
VlpCreateLock(lock, fileName);
|
2015-10-09 11:50:37 +02:00
|
|
|
|
if (not lock->IsLocked())
|
2015-09-16 13:29:01 +02:00
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
|
qCCritical(tMainWindow, "%s", qUtf8Printable(tr("Failed to lock. This file already opened in another window. "
|
|
|
|
|
"Expect collissions when run 2 copies of the program.")));
|
2015-09-16 13:29:01 +02:00
|
|
|
|
return;
|
2015-07-18 14:39:33 +02:00
|
|
|
|
}
|
2015-07-12 17:56:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::AboutToShowWindowMenu()
|
|
|
|
|
{
|
|
|
|
|
ui->menuWindow->clear();
|
2015-11-17 13:42:03 +01:00
|
|
|
|
QAction *action = ui->menuWindow->addAction(tr("&New Window"), this, SLOT(NewWindow()));
|
|
|
|
|
action->setMenuRole(QAction::NoRole);
|
2015-08-01 15:14:10 +02:00
|
|
|
|
ui->menuWindow->addSeparator();
|
|
|
|
|
|
2015-07-15 09:16:59 +02:00
|
|
|
|
QList<TMainWindow*> windows = qApp->MainWindows();
|
2015-07-12 17:56:34 +02:00
|
|
|
|
for (int i = 0; i < windows.count(); ++i)
|
|
|
|
|
{
|
|
|
|
|
TMainWindow *window = windows.at(i);
|
2015-07-18 14:50:34 +02:00
|
|
|
|
|
|
|
|
|
QString title = window->windowTitle();
|
|
|
|
|
const int index = title.lastIndexOf("[*]");
|
|
|
|
|
if (index != -1)
|
|
|
|
|
{
|
2015-11-17 13:49:28 +01:00
|
|
|
|
window->isWindowModified() ? title.replace(index, 3, "*") : title.replace(index, 3, "");
|
2015-07-18 14:50:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAction *action = ui->menuWindow->addAction(title, this, SLOT(ShowWindow()));
|
2015-07-12 17:56:34 +02:00
|
|
|
|
action->setData(i);
|
|
|
|
|
action->setCheckable(true);
|
2015-11-17 13:42:03 +01:00
|
|
|
|
action->setMenuRole(QAction::NoRole);
|
2015-07-12 17:56:34 +02:00
|
|
|
|
if (window == this)
|
|
|
|
|
{
|
|
|
|
|
action->setChecked(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::ShowWindow()
|
|
|
|
|
{
|
|
|
|
|
if (QAction *action = qobject_cast<QAction*>(sender()))
|
|
|
|
|
{
|
|
|
|
|
const QVariant v = action->data();
|
|
|
|
|
if (v.canConvert<int>())
|
|
|
|
|
{
|
|
|
|
|
const int offset = qvariant_cast<int>(v);
|
2015-07-15 09:16:59 +02:00
|
|
|
|
QList<TMainWindow*> windows = qApp->MainWindows();
|
2015-07-12 17:56:34 +02:00
|
|
|
|
windows.at(offset)->activateWindow();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::AboutApplication()
|
|
|
|
|
{
|
2015-07-12 19:38:30 +02:00
|
|
|
|
DialogAboutTape * aboutDialog = new DialogAboutTape(this);
|
|
|
|
|
aboutDialog->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
|
aboutDialog->show();
|
2015-07-12 17:56:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-18 13:08:44 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SaveGivenName()
|
|
|
|
|
{
|
2015-07-25 17:18:01 +02:00
|
|
|
|
if (m->GivenName() != ui->lineEditGivenName->text())
|
|
|
|
|
{
|
|
|
|
|
m->SetGivenName(ui->lineEditGivenName->text());
|
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
}
|
2015-07-18 13:08:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SaveFamilyName()
|
|
|
|
|
{
|
2015-07-25 17:18:01 +02:00
|
|
|
|
if (m->FamilyName() != ui->lineEditFamilyName->text())
|
|
|
|
|
{
|
|
|
|
|
m->SetFamilyName(ui->lineEditFamilyName->text());
|
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
}
|
2015-07-18 13:08:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SaveEmail()
|
|
|
|
|
{
|
2015-07-25 17:18:01 +02:00
|
|
|
|
if (m->Email() != ui->lineEditEmail->text())
|
|
|
|
|
{
|
|
|
|
|
m->SetEmail(ui->lineEditEmail->text());
|
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
}
|
2015-07-18 13:08:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-13 10:13:43 +02:00
|
|
|
|
void TMainWindow::SaveGender(int index)
|
2015-07-18 13:08:44 +02:00
|
|
|
|
{
|
2015-10-13 10:13:43 +02:00
|
|
|
|
const GenderType type = static_cast<GenderType>(ui->comboBoxGender->itemData(index).toInt());
|
|
|
|
|
if (m->Gender() != type)
|
2015-07-25 17:18:01 +02:00
|
|
|
|
{
|
2015-10-13 10:13:43 +02:00
|
|
|
|
m->SetGender(type);
|
2015-07-25 17:18:01 +02:00
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
}
|
2015-07-18 13:08:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SaveBirthDate(const QDate &date)
|
|
|
|
|
{
|
2015-07-25 17:18:01 +02:00
|
|
|
|
if (m->BirthDate() != date)
|
|
|
|
|
{
|
|
|
|
|
m->SetBirthDate(date);
|
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
}
|
2015-07-18 13:08:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SaveNotes()
|
|
|
|
|
{
|
2015-07-25 17:18:01 +02:00
|
|
|
|
if (m->Notes() != ui->plainTextEditNotes->toPlainText())
|
|
|
|
|
{
|
|
|
|
|
m->SetNotes(ui->plainTextEditNotes->toPlainText());
|
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
}
|
2015-07-18 13:08:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-16 19:26:05 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SavePMSystem(int index)
|
|
|
|
|
{
|
|
|
|
|
QString system = ui->comboBoxPMSystem->itemData(index).toString();
|
|
|
|
|
system.remove(0, 1);// clear p
|
|
|
|
|
|
|
|
|
|
if (m->PMSystem() != system)
|
|
|
|
|
{
|
|
|
|
|
m->SetPMSystem(system);
|
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-18 13:08:44 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::ReadOnly(bool ro)
|
|
|
|
|
{
|
|
|
|
|
m->SetReadOnly(ro);
|
2015-07-18 15:23:18 +02:00
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
|
2015-07-25 17:18:01 +02:00
|
|
|
|
GUIReadOnly(ro);
|
2015-07-18 13:08:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 08:41:04 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::Remove()
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), 0);
|
2015-09-29 16:04:24 +02:00
|
|
|
|
m->Remove(nameField->data(Qt::UserRole).toString());
|
2015-07-22 08:41:04 +02:00
|
|
|
|
|
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
|
2015-09-15 18:49:24 +02:00
|
|
|
|
search->RemoveRow(row);
|
2015-07-22 08:41:04 +02:00
|
|
|
|
RefreshData();
|
2015-09-15 18:49:24 +02:00
|
|
|
|
search->RefreshList(ui->lineEditFind->text());
|
2015-07-24 12:20:38 +02:00
|
|
|
|
|
|
|
|
|
if (ui->tableWidget->rowCount() > 0)
|
|
|
|
|
{
|
2015-10-12 17:05:53 +02:00
|
|
|
|
ui->tableWidget->selectRow(row);
|
2015-07-24 12:20:38 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-09-09 11:45:30 +02:00
|
|
|
|
MFields(false);
|
2015-07-24 12:20:38 +02:00
|
|
|
|
|
|
|
|
|
ui->lineEditName->blockSignals(true);
|
|
|
|
|
ui->lineEditName->setText("");
|
|
|
|
|
ui->lineEditName->blockSignals(false);
|
|
|
|
|
|
|
|
|
|
ui->plainTextEditDescription->blockSignals(true);
|
|
|
|
|
ui->plainTextEditDescription->setPlainText("");
|
|
|
|
|
ui->plainTextEditDescription->blockSignals(false);
|
|
|
|
|
|
2015-07-25 10:54:39 +02:00
|
|
|
|
ui->lineEditFullName->blockSignals(true);
|
|
|
|
|
ui->lineEditFullName->setText("");
|
|
|
|
|
ui->lineEditFullName->blockSignals(false);
|
|
|
|
|
|
2015-07-24 12:20:38 +02:00
|
|
|
|
if (mType == MeasurementsType::Standard)
|
|
|
|
|
{
|
|
|
|
|
ui->labelCalculatedValue->blockSignals(true);
|
2015-07-25 08:10:56 +02:00
|
|
|
|
ui->doubleSpinBoxBaseValue->blockSignals(true);
|
|
|
|
|
ui->doubleSpinBoxInSizes->blockSignals(true);
|
|
|
|
|
ui->doubleSpinBoxInHeights->blockSignals(true);
|
2015-07-24 12:20:38 +02:00
|
|
|
|
|
|
|
|
|
ui->labelCalculatedValue->setText("");
|
2015-07-25 08:10:56 +02:00
|
|
|
|
ui->doubleSpinBoxBaseValue->setValue(0);
|
|
|
|
|
ui->doubleSpinBoxInSizes->setValue(0);
|
|
|
|
|
ui->doubleSpinBoxInHeights->setValue(0);
|
2015-07-24 12:20:38 +02:00
|
|
|
|
|
|
|
|
|
ui->labelCalculatedValue->blockSignals(false);
|
2015-07-25 08:10:56 +02:00
|
|
|
|
ui->doubleSpinBoxBaseValue->blockSignals(false);
|
|
|
|
|
ui->doubleSpinBoxInSizes->blockSignals(false);
|
|
|
|
|
ui->doubleSpinBoxInHeights->blockSignals(false);
|
2015-07-24 12:20:38 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->labelCalculatedValue->blockSignals(true);
|
|
|
|
|
ui->labelCalculatedValue->setText("");
|
|
|
|
|
ui->labelCalculatedValue->blockSignals(false);
|
|
|
|
|
|
|
|
|
|
ui->plainTextEditFormula->blockSignals(true);
|
|
|
|
|
ui->plainTextEditFormula->setPlainText("");
|
|
|
|
|
ui->plainTextEditFormula->blockSignals(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-22 08:41:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-12 16:57:11 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::MoveTop()
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(row, ColumnName);
|
|
|
|
|
m->MoveTop(nameField->data(Qt::UserRole).toString());
|
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
RefreshData();
|
|
|
|
|
search->RefreshList(ui->lineEditFind->text());
|
|
|
|
|
ui->tableWidget->selectRow(0);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 09:01:34 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::MoveUp()
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(row, ColumnName);
|
2015-09-29 16:04:24 +02:00
|
|
|
|
m->MoveUp(nameField->data(Qt::UserRole).toString());
|
2015-07-22 09:01:34 +02:00
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
RefreshData();
|
2015-09-15 18:49:24 +02:00
|
|
|
|
search->RefreshList(ui->lineEditFind->text());
|
2015-07-24 12:11:03 +02:00
|
|
|
|
ui->tableWidget->selectRow(row-1);
|
2015-07-22 09:01:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::MoveDown()
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(row, ColumnName);
|
2015-09-29 16:04:24 +02:00
|
|
|
|
m->MoveDown(nameField->data(Qt::UserRole).toString());
|
2015-07-22 09:01:34 +02:00
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
RefreshData();
|
2015-09-15 18:49:24 +02:00
|
|
|
|
search->RefreshList(ui->lineEditFind->text());
|
2015-07-24 12:11:03 +02:00
|
|
|
|
ui->tableWidget->selectRow(row+1);
|
2015-07-22 09:01:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-12 16:57:11 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::MoveBottom()
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(row, ColumnName);
|
|
|
|
|
m->MoveBottom(nameField->data(Qt::UserRole).toString());
|
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
RefreshData();
|
|
|
|
|
search->RefreshList(ui->lineEditFind->text());
|
|
|
|
|
ui->tableWidget->selectRow(ui->tableWidget->rowCount()-1);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-24 14:06:53 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::Fx()
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-29 17:46:00 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(row, ColumnName);
|
2015-09-29 16:04:24 +02:00
|
|
|
|
|
|
|
|
|
QSharedPointer<VMeasurement> meash;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Translate to internal look.
|
|
|
|
|
meash = data->GetVariable<VMeasurement>(nameField->data(Qt::UserRole).toString());
|
|
|
|
|
}
|
|
|
|
|
catch(const VExceptionBadId & e)
|
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
|
qCCritical(tMainWindow, "%s\n\n%s\n\n%s",
|
|
|
|
|
qUtf8Printable(tr("Can't find measurement '%1'.").arg(nameField->text())),
|
|
|
|
|
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
|
2015-09-29 16:04:24 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2015-07-24 14:06:53 +02:00
|
|
|
|
|
|
|
|
|
DialogEditWrongFormula *dialog = new DialogEditWrongFormula(meash->GetData(), NULL_ID, this);
|
|
|
|
|
dialog->setWindowTitle(tr("Edit measurement"));
|
|
|
|
|
|
|
|
|
|
QString text = ui->plainTextEditFormula->toPlainText();
|
|
|
|
|
text.replace("\n", " ");
|
2015-09-29 17:09:41 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
text = qApp->TrVars()->FormulaFromUser(text, true);
|
|
|
|
|
}
|
|
|
|
|
catch (qmu::QmuParserError &e) // Just in case something bad will happen
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(e)
|
|
|
|
|
text = ui->plainTextEditFormula->toPlainText();
|
|
|
|
|
}
|
2015-07-24 14:06:53 +02:00
|
|
|
|
dialog->SetFormula(text);
|
|
|
|
|
const QString postfix = VDomDocument::UnitsToStr(mUnit, true);//Show unit in dialog lable (cm, mm or inch)
|
|
|
|
|
dialog->setPostfix(postfix);
|
|
|
|
|
|
|
|
|
|
if (dialog->exec() == QDialog::Accepted)
|
|
|
|
|
{
|
2015-09-29 16:04:24 +02:00
|
|
|
|
m->SetMValue(nameField->data(Qt::UserRole).toString(), dialog->GetFormula());
|
2015-07-24 14:06:53 +02:00
|
|
|
|
|
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
|
|
|
|
|
RefreshData();
|
|
|
|
|
|
2015-09-15 18:49:24 +02:00
|
|
|
|
search->RefreshList(ui->lineEditFind->text());
|
|
|
|
|
|
2015-07-24 14:06:53 +02:00
|
|
|
|
ui->tableWidget->selectRow(row);
|
|
|
|
|
}
|
|
|
|
|
delete dialog;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-19 14:28:01 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::AddCustom()
|
|
|
|
|
{
|
|
|
|
|
qint32 num = 1;
|
|
|
|
|
QString name;
|
|
|
|
|
do
|
|
|
|
|
{
|
2015-08-25 12:35:50 +02:00
|
|
|
|
name = CustomMSign + tr("M_%1").arg(num);
|
2015-07-19 14:28:01 +02:00
|
|
|
|
num++;
|
|
|
|
|
} while (data->IsUnique(name) == false);
|
|
|
|
|
|
2015-07-21 19:26:33 +02:00
|
|
|
|
qint32 currentRow;
|
|
|
|
|
|
|
|
|
|
if (ui->tableWidget->currentRow() == -1)
|
|
|
|
|
{
|
|
|
|
|
currentRow = ui->tableWidget->rowCount();
|
|
|
|
|
m->AddEmpty(name);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
currentRow = ui->tableWidget->currentRow()+1;
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName);
|
2015-09-29 16:04:24 +02:00
|
|
|
|
m->AddEmptyAfter(nameField->data(Qt::UserRole).toString(), name);
|
2015-07-21 19:26:33 +02:00
|
|
|
|
}
|
2015-07-19 14:28:01 +02:00
|
|
|
|
|
2015-09-15 18:49:24 +02:00
|
|
|
|
search->AddRow(currentRow);
|
2015-08-01 12:33:57 +02:00
|
|
|
|
RefreshData();
|
2015-09-15 18:49:24 +02:00
|
|
|
|
search->RefreshList(ui->lineEditFind->text());
|
2015-07-19 14:28:01 +02:00
|
|
|
|
|
|
|
|
|
ui->tableWidget->selectRow(currentRow);
|
|
|
|
|
|
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::AddKnown()
|
|
|
|
|
{
|
2015-08-01 11:39:32 +02:00
|
|
|
|
DialogMDataBase *dialog = new DialogMDataBase(m->ListKnown(), this);
|
|
|
|
|
if (dialog->exec() == QDialog::Accepted)
|
|
|
|
|
{
|
2015-08-01 13:25:05 +02:00
|
|
|
|
qint32 currentRow;
|
2015-07-19 14:28:01 +02:00
|
|
|
|
|
2015-08-01 13:25:05 +02:00
|
|
|
|
const QStringList list = dialog->GetNewNames();
|
|
|
|
|
if (ui->tableWidget->currentRow() == -1)
|
|
|
|
|
{
|
|
|
|
|
currentRow = ui->tableWidget->rowCount() + list.size() - 1;
|
|
|
|
|
for (int i = 0; i < list.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if (mType == MeasurementsType::Individual)
|
|
|
|
|
{
|
|
|
|
|
m->AddEmpty(list.at(i), qApp->TrVars()->MFormula(list.at(i)));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m->AddEmpty(list.at(i));
|
|
|
|
|
}
|
2015-09-15 18:49:24 +02:00
|
|
|
|
|
|
|
|
|
search->AddRow(currentRow);
|
2015-08-01 13:25:05 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
currentRow = ui->tableWidget->currentRow() + list.size();
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName);
|
2015-09-29 16:04:24 +02:00
|
|
|
|
QString after = nameField->data(Qt::UserRole).toString();
|
2015-08-01 13:25:05 +02:00
|
|
|
|
for (int i = 0; i < list.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if (mType == MeasurementsType::Individual)
|
|
|
|
|
{
|
|
|
|
|
m->AddEmptyAfter(after, list.at(i), qApp->TrVars()->MFormula(list.at(i)));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m->AddEmptyAfter(after, list.at(i));
|
|
|
|
|
}
|
2015-09-15 18:49:24 +02:00
|
|
|
|
search->AddRow(currentRow);
|
2015-08-01 13:25:05 +02:00
|
|
|
|
after = list.at(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RefreshData();
|
2015-09-15 18:49:24 +02:00
|
|
|
|
search->RefreshList(ui->lineEditFind->text());
|
2015-08-01 13:25:05 +02:00
|
|
|
|
|
|
|
|
|
ui->tableWidget->selectRow(currentRow);
|
|
|
|
|
|
|
|
|
|
MeasurementsWasSaved(false);
|
2015-08-01 11:39:32 +02:00
|
|
|
|
}
|
|
|
|
|
delete dialog;
|
2015-07-19 14:28:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-11 16:52:18 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::ImportFromPattern()
|
|
|
|
|
{
|
|
|
|
|
if (m == nullptr)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString filter(tr("Pattern files (*.val)"));
|
|
|
|
|
//Use standard path to individual measurements
|
|
|
|
|
const QString pathTo = qApp->TapeSettings()->GetPathTemplate();
|
|
|
|
|
|
|
|
|
|
const QString mPath = QFileDialog::getOpenFileName(this, tr("Import from a pattern"), pathTo, filter);
|
|
|
|
|
if (mPath.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-26 08:57:20 +01:00
|
|
|
|
VLockGuard<char> tmp(QFileInfo(mPath).fileName());
|
2015-10-09 11:50:37 +02:00
|
|
|
|
if (not tmp.IsLocked())
|
2015-08-11 16:52:18 +02:00
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
|
qCCritical(tMainWindow, "%s", qUtf8Printable(tr("This file already opened in another window.")));
|
2015-09-14 13:53:49 +02:00
|
|
|
|
return;
|
2015-08-11 16:52:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
|
qt_ntfs_permission_lookup++; // turn checking on
|
|
|
|
|
#endif /*Q_OS_WIN32*/
|
|
|
|
|
|
|
|
|
|
QStringList measurements;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
VPatternConverter converter(mPath);
|
|
|
|
|
converter.Convert();
|
|
|
|
|
|
|
|
|
|
VDomDocument::ValidateXML(VPatternConverter::CurrentSchema, mPath);
|
|
|
|
|
VLitePattern *doc = new VLitePattern();
|
|
|
|
|
doc->setXMLContent(mPath);
|
|
|
|
|
measurements = doc->ListMeasurements();
|
|
|
|
|
delete doc; // close a pattern
|
|
|
|
|
}
|
|
|
|
|
catch (VException &e)
|
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
|
qCCritical(tMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")),
|
|
|
|
|
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
|
2015-08-11 16:52:18 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
|
qt_ntfs_permission_lookup--; // turn it off again
|
|
|
|
|
#endif /*Q_OS_WIN32*/
|
|
|
|
|
|
|
|
|
|
measurements = FilterMeasurements(measurements, m->ListAll());
|
|
|
|
|
|
|
|
|
|
qint32 currentRow;
|
|
|
|
|
|
|
|
|
|
if (ui->tableWidget->currentRow() == -1)
|
|
|
|
|
{
|
|
|
|
|
currentRow = ui->tableWidget->rowCount() + measurements.size() - 1;
|
|
|
|
|
for (int i = 0; i < measurements.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
m->AddEmpty(measurements.at(i));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
currentRow = ui->tableWidget->currentRow() + measurements.size();
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName);
|
2015-09-29 16:04:24 +02:00
|
|
|
|
QString after = nameField->data(Qt::UserRole).toString();
|
2015-08-11 16:52:18 +02:00
|
|
|
|
for (int i = 0; i < measurements.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
m->AddEmptyAfter(after, measurements.at(i));
|
|
|
|
|
after = measurements.at(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RefreshData();
|
|
|
|
|
|
2015-09-15 18:49:24 +02:00
|
|
|
|
search->RefreshList(ui->lineEditFind->text());
|
|
|
|
|
|
2015-08-11 16:52:18 +02:00
|
|
|
|
ui->tableWidget->selectRow(currentRow);
|
|
|
|
|
|
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-21 15:18:10 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::ChangedSize(const QString &text)
|
|
|
|
|
{
|
2015-07-25 07:41:04 +02:00
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
2015-07-21 15:18:10 +02:00
|
|
|
|
data->SetSize(text.toInt());
|
|
|
|
|
RefreshData();
|
2015-09-15 18:49:24 +02:00
|
|
|
|
search->RefreshList(ui->lineEditFind->text());
|
2015-07-25 07:41:04 +02:00
|
|
|
|
ui->tableWidget->selectRow(row);
|
2015-07-21 15:18:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::ChangedHeight(const QString &text)
|
|
|
|
|
{
|
2015-07-25 07:41:04 +02:00
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
2015-07-21 15:18:10 +02:00
|
|
|
|
data->SetHeight(text.toInt());
|
|
|
|
|
RefreshData();
|
2015-09-15 18:49:24 +02:00
|
|
|
|
search->RefreshList(ui->lineEditFind->text());
|
2015-07-25 07:41:04 +02:00
|
|
|
|
ui->tableWidget->selectRow(row);
|
2015-07-21 15:18:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-21 17:28:20 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::ShowMData()
|
|
|
|
|
{
|
|
|
|
|
if (ui->tableWidget->rowCount() > 0)
|
|
|
|
|
{
|
2015-09-09 11:45:30 +02:00
|
|
|
|
MFields(true);
|
2015-07-24 12:20:38 +02:00
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName); // name
|
2015-08-01 16:36:56 +02:00
|
|
|
|
QSharedPointer<VMeasurement> meash;
|
2015-07-21 17:28:20 +02:00
|
|
|
|
|
2015-08-01 16:36:56 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
2015-09-29 16:04:24 +02:00
|
|
|
|
// Translate to internal look.
|
|
|
|
|
meash = data->GetVariable<VMeasurement>(nameField->data(Qt::UserRole).toString());
|
2015-08-01 16:36:56 +02:00
|
|
|
|
}
|
|
|
|
|
catch(const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(e);
|
2015-09-09 11:45:30 +02:00
|
|
|
|
MFields(false);
|
2015-08-01 16:36:56 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2015-07-24 12:06:39 +02:00
|
|
|
|
|
2015-10-29 17:20:59 +01:00
|
|
|
|
ShowMDiagram(meash->GetName());
|
|
|
|
|
|
2015-08-01 16:36:56 +02:00
|
|
|
|
ui->lineEditName->blockSignals(true);
|
2015-07-24 12:06:39 +02:00
|
|
|
|
ui->plainTextEditDescription->blockSignals(true);
|
2015-08-01 16:36:56 +02:00
|
|
|
|
ui->lineEditFullName->blockSignals(true);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
if (meash->IsCustom())
|
|
|
|
|
{
|
|
|
|
|
ui->plainTextEditDescription->setPlainText(meash->GetDescription());
|
2015-08-01 16:36:56 +02:00
|
|
|
|
ui->lineEditFullName->setText(meash->GetGuiText());
|
|
|
|
|
ui->lineEditName->setText(ClearCustomName(meash->GetName()));
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-08-01 16:36:56 +02:00
|
|
|
|
//Show known
|
|
|
|
|
ui->plainTextEditDescription->setPlainText(qApp->TrVars()->Description(meash->GetName()));
|
|
|
|
|
ui->lineEditFullName->setText(qApp->TrVars()->GuiText(meash->GetName()));
|
|
|
|
|
ui->lineEditName->setText(nameField->text());
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
2015-08-01 16:36:56 +02:00
|
|
|
|
ui->lineEditName->blockSignals(false);
|
2015-07-24 12:06:39 +02:00
|
|
|
|
ui->plainTextEditDescription->blockSignals(false);
|
2015-07-25 10:54:39 +02:00
|
|
|
|
ui->lineEditFullName->blockSignals(false);
|
|
|
|
|
|
2015-07-21 17:28:20 +02:00
|
|
|
|
if (mType == MeasurementsType::Standard)
|
|
|
|
|
{
|
2015-07-24 12:06:39 +02:00
|
|
|
|
ui->labelCalculatedValue->blockSignals(true);
|
2015-07-25 08:10:56 +02:00
|
|
|
|
ui->doubleSpinBoxBaseValue->blockSignals(true);
|
|
|
|
|
ui->doubleSpinBoxInSizes->blockSignals(true);
|
|
|
|
|
ui->doubleSpinBoxInHeights->blockSignals(true);
|
2015-07-24 12:06:39 +02:00
|
|
|
|
|
2015-08-18 13:53:30 +02:00
|
|
|
|
const QString postfix = VDomDocument::UnitsToStr(pUnit);//Show unit in dialog lable (cm, mm or inch)
|
|
|
|
|
const qreal value = UnitConvertor(data->GetTableValue(meash->GetName(), mType), mUnit, pUnit);
|
|
|
|
|
ui->labelCalculatedValue->setText(qApp->LocaleToString(value) + " " +postfix);
|
|
|
|
|
|
2015-07-25 08:10:56 +02:00
|
|
|
|
ui->doubleSpinBoxBaseValue->setValue(static_cast<int>(meash->GetBase()));
|
|
|
|
|
ui->doubleSpinBoxInSizes->setValue(static_cast<int>(meash->GetKsize()));
|
|
|
|
|
ui->doubleSpinBoxInHeights->setValue(static_cast<int>(meash->GetKheight()));
|
2015-07-24 12:06:39 +02:00
|
|
|
|
|
|
|
|
|
ui->labelCalculatedValue->blockSignals(false);
|
2015-07-25 08:10:56 +02:00
|
|
|
|
ui->doubleSpinBoxBaseValue->blockSignals(false);
|
|
|
|
|
ui->doubleSpinBoxInSizes->blockSignals(false);
|
|
|
|
|
ui->doubleSpinBoxInHeights->blockSignals(false);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-08-25 12:35:50 +02:00
|
|
|
|
EvalFormula(meash->GetFormula(), false, meash->GetData(), ui->labelCalculatedValue);
|
2015-07-24 12:06:39 +02:00
|
|
|
|
|
|
|
|
|
ui->plainTextEditFormula->blockSignals(true);
|
|
|
|
|
|
|
|
|
|
QString formula;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
formula = qApp->TrVars()->FormulaToUser(meash->GetFormula());
|
|
|
|
|
}
|
|
|
|
|
catch (qmu::QmuParserError &e)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(e);
|
|
|
|
|
formula = meash->GetFormula();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui->plainTextEditFormula->setPlainText(formula);
|
|
|
|
|
ui->plainTextEditFormula->blockSignals(false);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-09 11:45:30 +02:00
|
|
|
|
MeasurementReadOnly(m->ReadOnly());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MFields(false);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-29 17:20:59 +01:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::ShowMDiagram(const QString &name)
|
|
|
|
|
{
|
|
|
|
|
const VTranslateVars *trv = qApp->TrVars();
|
|
|
|
|
const QString number = trv->MNumber(name);
|
|
|
|
|
|
|
|
|
|
if (number.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
ui->labelDiagram->setText(tr("<html><head/><body><p><span style=\" font-size:340pt;\">?</span></p>"
|
|
|
|
|
"<p align=\"center\">Unknown measurement</p></body></html>"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-11-15 16:48:48 +01:00
|
|
|
|
ui->labelDiagram->setText(QString("<html><head/><body><p align=\"center\">%1</p>"
|
2015-10-29 17:20:59 +01:00
|
|
|
|
"<p align=\"center\"><b>%2</b>. <i>%3</i></p></body></html>")
|
2015-11-15 16:48:48 +01:00
|
|
|
|
.arg(DialogMDataBase::ImgTag(number)).arg(number).arg(trv->GuiText(name)));
|
2015-10-29 17:20:59 +01:00
|
|
|
|
}
|
|
|
|
|
// This part is very ugly, can't find better way to resize dockWidget.
|
|
|
|
|
ui->labelDiagram->adjustSize();
|
2015-11-15 16:48:48 +01:00
|
|
|
|
// And also those 50 px. DockWidget has some border. And i can't find how big it is.
|
2015-10-29 17:20:59 +01:00
|
|
|
|
// Can lead to problem in future.
|
|
|
|
|
ui->dockWidgetDiagram->setMaximumWidth(ui->labelDiagram->width()+50);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-21 18:24:47 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::DeployFormula()
|
|
|
|
|
{
|
|
|
|
|
SCASSERT(ui->plainTextEditFormula != nullptr);
|
2015-10-05 15:52:18 +02:00
|
|
|
|
SCASSERT(ui->pushButtonGrow != nullptr);
|
|
|
|
|
|
|
|
|
|
const QTextCursor cursor = ui->plainTextEditFormula->textCursor();
|
|
|
|
|
|
2015-07-21 18:24:47 +02:00
|
|
|
|
if (ui->plainTextEditFormula->height() < DIALOG_MAX_FORMULA_HEIGHT)
|
|
|
|
|
{
|
|
|
|
|
ui->plainTextEditFormula->setFixedHeight(DIALOG_MAX_FORMULA_HEIGHT);
|
|
|
|
|
//Set icon from theme (internal for Windows system)
|
|
|
|
|
ui->pushButtonGrow->setIcon(QIcon::fromTheme("go-next",
|
|
|
|
|
QIcon(":/icons/win.icon.theme/16x16/actions/go-next.png")));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->plainTextEditFormula->setFixedHeight(formulaBaseHeight);
|
|
|
|
|
//Set icon from theme (internal for Windows system)
|
|
|
|
|
ui->pushButtonGrow->setIcon(QIcon::fromTheme("go-down",
|
|
|
|
|
QIcon(":/icons/win.icon.theme/16x16/actions/go-down.png")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// I found that after change size of formula field, it was filed for angle formula, field for formula became black.
|
|
|
|
|
// This code prevent this.
|
|
|
|
|
setUpdatesEnabled(false);
|
|
|
|
|
repaint();
|
|
|
|
|
setUpdatesEnabled(true);
|
2015-10-05 15:52:18 +02:00
|
|
|
|
|
|
|
|
|
ui->plainTextEditFormula->setFocus();
|
|
|
|
|
ui->plainTextEditFormula->setTextCursor(cursor);
|
2015-07-21 18:24:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 11:44:31 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SaveMName()
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName);
|
2015-09-29 16:04:24 +02:00
|
|
|
|
|
|
|
|
|
QSharedPointer<VMeasurement> meash;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Translate to internal look.
|
|
|
|
|
meash = data->GetVariable<VMeasurement>(nameField->data(Qt::UserRole).toString());
|
|
|
|
|
}
|
2015-10-01 16:59:01 +02:00
|
|
|
|
catch(const VExceptionBadId &e)
|
2015-09-29 16:04:24 +02:00
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
|
qCWarning(tMainWindow, "%s\n\n%s\n\n%s",
|
|
|
|
|
qUtf8Printable(tr("Can't find measurement '%1'.").arg(nameField->text())),
|
|
|
|
|
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
|
2015-09-29 16:04:24 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
|
|
|
|
QString newName = ui->lineEditName->text();
|
|
|
|
|
if (meash->IsCustom())
|
|
|
|
|
{
|
2015-08-25 12:35:50 +02:00
|
|
|
|
newName = CustomMSign + newName;
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
2015-09-29 16:04:24 +02:00
|
|
|
|
if (data->IsUnique(newName))
|
|
|
|
|
{
|
|
|
|
|
m->SetMName(nameField->text(), newName);
|
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
RefreshData();
|
|
|
|
|
search->RefreshList(ui->lineEditFind->text());
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
2015-09-29 16:04:24 +02:00
|
|
|
|
ui->tableWidget->blockSignals(true);
|
|
|
|
|
ui->tableWidget->selectRow(row);
|
|
|
|
|
ui->tableWidget->blockSignals(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->lineEditName->setText(ClearCustomName(nameField->text()));
|
|
|
|
|
}
|
2015-07-22 11:44:31 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
|
qCWarning(tMainWindow, "%s", qUtf8Printable(tr("The name of known measurement forbidden to change.")));
|
2015-07-22 11:44:31 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SaveMValue()
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(row, ColumnName);
|
2015-07-24 12:06:39 +02:00
|
|
|
|
|
|
|
|
|
// Replace line return character with spaces for calc if exist
|
|
|
|
|
QString text = ui->plainTextEditFormula->toPlainText();
|
|
|
|
|
text.replace("\n", " ");
|
|
|
|
|
|
2015-09-29 17:46:00 +02:00
|
|
|
|
QTableWidgetItem *formulaField = ui->tableWidget->item(row, ColumnFormula);
|
2015-07-24 12:06:39 +02:00
|
|
|
|
if (formulaField->text() == text)
|
|
|
|
|
{
|
2015-09-29 17:46:00 +02:00
|
|
|
|
QTableWidgetItem *result = ui->tableWidget->item(row, ColumnCalcValue);
|
2015-08-01 14:55:52 +02:00
|
|
|
|
const QString postfix = VDomDocument::UnitsToStr(mUnit);//Show unit in dialog lable (cm, mm or inch)
|
|
|
|
|
ui->labelCalculatedValue->setText(result->text() + " " +postfix);
|
2015-07-24 12:06:39 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (text.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
const QString postfix = VDomDocument::UnitsToStr(mUnit);//Show unit in dialog lable (cm, mm or inch)
|
|
|
|
|
ui->labelCalculatedValue->setText(tr("Error") + " (" + postfix + "). " + tr("Empty field."));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-29 16:04:24 +02:00
|
|
|
|
QSharedPointer<VMeasurement> meash;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Translate to internal look.
|
|
|
|
|
meash = data->GetVariable<VMeasurement>(nameField->data(Qt::UserRole).toString());
|
|
|
|
|
}
|
|
|
|
|
catch(const VExceptionBadId & e)
|
|
|
|
|
{
|
2015-10-01 16:59:01 +02:00
|
|
|
|
qCWarning(tMainWindow, "%s\n\n%s\n\n%s",
|
|
|
|
|
qUtf8Printable(tr("Can't find measurement '%1'.").arg(nameField->text())),
|
|
|
|
|
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
|
2015-09-29 16:04:24 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2015-08-25 12:35:50 +02:00
|
|
|
|
|
|
|
|
|
const bool ok = EvalFormula(text, true, meash->GetData(), ui->labelCalculatedValue);
|
|
|
|
|
|
|
|
|
|
if (not ok)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
2015-08-25 12:35:50 +02:00
|
|
|
|
const QString formula = qApp->TrVars()->FormulaFromUser(text, true);
|
2015-09-29 16:04:24 +02:00
|
|
|
|
m->SetMValue(nameField->data(Qt::UserRole).toString(), formula);
|
2015-07-24 12:06:39 +02:00
|
|
|
|
}
|
2015-09-29 17:09:41 +02:00
|
|
|
|
catch (qmu::QmuParserError &e) // Just in case something bad will happen
|
2015-07-24 12:06:39 +02:00
|
|
|
|
{
|
2015-08-25 12:35:50 +02:00
|
|
|
|
Q_UNUSED(e)
|
2015-07-24 12:06:39 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 11:44:31 +02:00
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
|
const QTextCursor cursor = ui->plainTextEditFormula->textCursor();
|
|
|
|
|
|
2015-07-22 11:44:31 +02:00
|
|
|
|
RefreshData();
|
2015-09-15 18:49:24 +02:00
|
|
|
|
search->RefreshList(ui->lineEditFind->text());
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
|
ui->tableWidget->blockSignals(true);
|
2015-07-22 11:44:31 +02:00
|
|
|
|
ui->tableWidget->selectRow(row);
|
2015-07-24 12:06:39 +02:00
|
|
|
|
ui->tableWidget->blockSignals(false);
|
|
|
|
|
|
|
|
|
|
ui->plainTextEditFormula->setTextCursor(cursor);
|
2015-07-22 11:44:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-07-25 08:10:56 +02:00
|
|
|
|
void TMainWindow::SaveMBaseValue(double value)
|
2015-07-22 11:44:31 +02:00
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName);
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
2015-10-03 00:38:50 +02:00
|
|
|
|
QSharedPointer<VMeasurement> meash;
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
2015-10-03 00:38:50 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Translate to internal look.
|
|
|
|
|
meash = data->GetVariable<VMeasurement>(nameField->data(Qt::UserRole).toString());
|
|
|
|
|
}
|
|
|
|
|
catch(const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
qCWarning(tMainWindow, "%s\n\n%s\n\n%s",
|
|
|
|
|
qUtf8Printable(tr("Can't find measurement '%1'.").arg(nameField->text())),
|
|
|
|
|
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
2015-10-03 00:38:50 +02:00
|
|
|
|
if (meash->IsCustom())
|
|
|
|
|
{
|
|
|
|
|
m->SetMBaseValue(nameField->data(Qt::UserRole).toString(), value);
|
|
|
|
|
|
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
|
|
|
|
|
RefreshData();
|
|
|
|
|
search->RefreshList(ui->lineEditFind->text());
|
|
|
|
|
|
|
|
|
|
ui->tableWidget->blockSignals(true);
|
|
|
|
|
ui->tableWidget->selectRow(row);
|
|
|
|
|
ui->tableWidget->blockSignals(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
qCWarning(tMainWindow, "%s", qUtf8Printable(tr("The base value of known measurement forbidden to change.")));
|
|
|
|
|
}
|
2015-07-22 11:44:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-07-25 08:10:56 +02:00
|
|
|
|
void TMainWindow::SaveMSizeIncrease(double value)
|
2015-07-22 11:44:31 +02:00
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName);
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
2015-10-03 00:38:50 +02:00
|
|
|
|
QSharedPointer<VMeasurement> meash;
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
2015-10-03 00:38:50 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Translate to internal look.
|
|
|
|
|
meash = data->GetVariable<VMeasurement>(nameField->data(Qt::UserRole).toString());
|
|
|
|
|
}
|
|
|
|
|
catch(const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
qCWarning(tMainWindow, "%s\n\n%s\n\n%s",
|
|
|
|
|
qUtf8Printable(tr("Can't find measurement '%1'.").arg(nameField->text())),
|
|
|
|
|
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
2015-10-03 00:38:50 +02:00
|
|
|
|
if (meash->IsCustom())
|
|
|
|
|
{
|
|
|
|
|
m->SetMSizeIncrease(nameField->data(Qt::UserRole).toString(), value);
|
|
|
|
|
|
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
|
|
|
|
|
RefreshData();
|
|
|
|
|
search->RefreshList(ui->lineEditFind->text());
|
|
|
|
|
|
|
|
|
|
ui->tableWidget->blockSignals(true);
|
|
|
|
|
ui->tableWidget->selectRow(row);
|
|
|
|
|
ui->tableWidget->blockSignals(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
qCWarning(tMainWindow, "%s",
|
|
|
|
|
qUtf8Printable(tr("The size increase value of known measurement forbidden to change.")));
|
|
|
|
|
}
|
2015-07-22 11:44:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-07-25 08:10:56 +02:00
|
|
|
|
void TMainWindow::SaveMHeightIncrease(double value)
|
2015-07-22 11:44:31 +02:00
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName);
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
2015-10-03 00:38:50 +02:00
|
|
|
|
QSharedPointer<VMeasurement> meash;
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
2015-10-03 00:38:50 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Translate to internal look.
|
|
|
|
|
meash = data->GetVariable<VMeasurement>(nameField->data(Qt::UserRole).toString());
|
|
|
|
|
}
|
|
|
|
|
catch(const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
qCWarning(tMainWindow, "%s\n\n%s\n\n%s",
|
|
|
|
|
qUtf8Printable(tr("Can't find measurement '%1'.").arg(nameField->text())),
|
|
|
|
|
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
2015-10-03 00:38:50 +02:00
|
|
|
|
if (meash->IsCustom())
|
|
|
|
|
{
|
|
|
|
|
m->SetMHeightIncrease(nameField->data(Qt::UserRole).toString(), value);
|
|
|
|
|
|
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
|
|
|
|
|
RefreshData();
|
|
|
|
|
search->RefreshList(ui->lineEditFind->text());
|
|
|
|
|
|
|
|
|
|
ui->tableWidget->selectRow(row);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
qCWarning(tMainWindow, "%s",
|
|
|
|
|
qUtf8Printable(tr("The height increase value of known measurement forbidden to change.")));
|
|
|
|
|
}
|
2015-07-22 11:44:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SaveMDescription()
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName);
|
2015-09-29 16:04:24 +02:00
|
|
|
|
m->SetMDescription(nameField->data(Qt::UserRole).toString(), ui->plainTextEditDescription->toPlainText());
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
|
const QTextCursor cursor = ui->plainTextEditDescription->textCursor();
|
|
|
|
|
|
2015-07-22 11:44:31 +02:00
|
|
|
|
RefreshData();
|
|
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
|
ui->tableWidget->blockSignals(true);
|
2015-07-22 11:44:31 +02:00
|
|
|
|
ui->tableWidget->selectRow(row);
|
2015-07-24 12:06:39 +02:00
|
|
|
|
ui->tableWidget->blockSignals(false);
|
|
|
|
|
|
|
|
|
|
ui->plainTextEditDescription->setTextCursor(cursor);
|
2015-07-22 11:44:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-25 10:54:39 +02:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SaveMFullName()
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 00:44:44 +02:00
|
|
|
|
const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName);
|
2015-07-25 10:54:39 +02:00
|
|
|
|
|
2015-10-03 00:00:18 +02:00
|
|
|
|
QSharedPointer<VMeasurement> meash;
|
2015-07-25 10:54:39 +02:00
|
|
|
|
|
2015-10-03 00:00:18 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Translate to internal look.
|
|
|
|
|
meash = data->GetVariable<VMeasurement>(nameField->data(Qt::UserRole).toString());
|
|
|
|
|
}
|
|
|
|
|
catch(const VExceptionBadId &e)
|
|
|
|
|
{
|
|
|
|
|
qCWarning(tMainWindow, "%s\n\n%s\n\n%s",
|
|
|
|
|
qUtf8Printable(tr("Can't find measurement '%1'.").arg(nameField->text())),
|
|
|
|
|
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-07-25 10:54:39 +02:00
|
|
|
|
|
2015-10-03 00:00:18 +02:00
|
|
|
|
if (meash->IsCustom())
|
|
|
|
|
{
|
|
|
|
|
m->SetMFullName(nameField->data(Qt::UserRole).toString(), ui->lineEditFullName->text());
|
|
|
|
|
|
|
|
|
|
MeasurementsWasSaved(false);
|
|
|
|
|
|
|
|
|
|
RefreshData();
|
|
|
|
|
|
|
|
|
|
ui->tableWidget->blockSignals(true);
|
|
|
|
|
ui->tableWidget->selectRow(row);
|
|
|
|
|
ui->tableWidget->blockSignals(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
qCWarning(tMainWindow, "%s", qUtf8Printable(tr("The full name of known measurement forbidden to change.")));
|
|
|
|
|
}
|
2015-07-25 10:54:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-01 15:14:10 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::NewWindow()
|
|
|
|
|
{
|
|
|
|
|
qApp->NewMainWindow();
|
|
|
|
|
qApp->MainWindow()->activateWindow();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-02 17:27:18 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::Preferences()
|
|
|
|
|
{
|
|
|
|
|
TapeConfigDialog dlg(this);
|
|
|
|
|
dlg.exec();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-18 13:53:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::PatternUnitChanged(int index)
|
|
|
|
|
{
|
|
|
|
|
pUnit = static_cast<Unit>(comboBoxUnits->itemData(index).toInt());
|
|
|
|
|
|
2015-08-18 15:31:21 +02:00
|
|
|
|
UpdatePatternUnit();
|
2015-08-18 13:53:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-12 16:19:53 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SetupMenu()
|
2015-07-10 13:14:55 +02:00
|
|
|
|
{
|
2015-07-12 17:56:34 +02:00
|
|
|
|
// File
|
2015-07-13 12:48:29 +02:00
|
|
|
|
connect(ui->actionNew, &QAction::triggered, this, &TMainWindow::FileNew);
|
|
|
|
|
ui->actionNew->setShortcuts(QKeySequence::New);
|
|
|
|
|
|
2015-07-25 14:59:40 +02:00
|
|
|
|
connect(ui->actionOpenIndividual, &QAction::triggered, this, &TMainWindow::OpenIndividual);
|
|
|
|
|
connect(ui->actionOpenStandard, &QAction::triggered, this, &TMainWindow::OpenStandard);
|
|
|
|
|
connect(ui->actionOpenTemplate, &QAction::triggered, this, &TMainWindow::OpenTemplate);
|
2015-10-15 14:37:10 +02:00
|
|
|
|
connect(ui->actionCreateFromExisting, &QAction::triggered, this, &TMainWindow::CreateFromExisting);
|
2015-07-12 17:56:34 +02:00
|
|
|
|
|
|
|
|
|
connect(ui->actionSave, &QAction::triggered, this, &TMainWindow::FileSave);
|
2015-07-13 12:48:29 +02:00
|
|
|
|
ui->actionSave->setShortcuts(QKeySequence::Save);
|
2015-07-12 17:56:34 +02:00
|
|
|
|
|
|
|
|
|
connect(ui->actionSaveAs, &QAction::triggered, this, &TMainWindow::FileSaveAs);
|
2015-07-13 12:48:29 +02:00
|
|
|
|
ui->actionSaveAs->setShortcuts(QKeySequence::SaveAs);
|
2015-07-12 17:56:34 +02:00
|
|
|
|
|
2015-07-18 13:08:44 +02:00
|
|
|
|
connect(ui->actionReadOnly, &QAction::triggered, this, &TMainWindow::ReadOnly);
|
2015-08-02 17:27:18 +02:00
|
|
|
|
connect(ui->actionPreferences, &QAction::triggered, this, &TMainWindow::Preferences);
|
2015-07-12 17:56:34 +02:00
|
|
|
|
|
|
|
|
|
connect(ui->actionQuit, &QAction::triggered, this, &TMainWindow::close);
|
|
|
|
|
ui->actionQuit->setShortcuts(QKeySequence::Quit);
|
|
|
|
|
|
2015-07-19 14:28:01 +02:00
|
|
|
|
// Measurements
|
|
|
|
|
connect(ui->actionAddCustom, &QAction::triggered, this, &TMainWindow::AddCustom);
|
|
|
|
|
connect(ui->actionAddKnown, &QAction::triggered, this, &TMainWindow::AddKnown);
|
2015-08-01 15:56:37 +02:00
|
|
|
|
connect(ui->actionDatabase, &QAction::triggered, qApp, &MApplication::ShowDataBase);
|
2015-08-11 16:52:18 +02:00
|
|
|
|
connect(ui->actionImportFromPattern, &QAction::triggered, this, &TMainWindow::ImportFromPattern);
|
2015-10-29 17:20:59 +01:00
|
|
|
|
actionDockDiagram = ui->dockWidgetDiagram->toggleViewAction();
|
2015-11-17 13:42:03 +01:00
|
|
|
|
actionDockDiagram->setMenuRole(QAction::NoRole);
|
2015-10-29 17:20:59 +01:00
|
|
|
|
ui->menuMeasurements->addAction(actionDockDiagram);
|
|
|
|
|
actionDockDiagram->setEnabled(false);
|
2015-07-19 14:28:01 +02:00
|
|
|
|
|
2015-07-12 17:56:34 +02:00
|
|
|
|
// Window
|
|
|
|
|
connect(ui->menuWindow, &QMenu::aboutToShow, this, &TMainWindow::AboutToShowWindowMenu);
|
|
|
|
|
AboutToShowWindowMenu();
|
2015-07-10 13:14:55 +02:00
|
|
|
|
|
2015-07-12 17:56:34 +02:00
|
|
|
|
// Help
|
|
|
|
|
connect(ui->actionAboutQt, &QAction::triggered, qApp, &QApplication::aboutQt);
|
|
|
|
|
connect(ui->actionAboutTape, &QAction::triggered, this, &TMainWindow::AboutApplication);
|
2015-07-10 13:14:55 +02:00
|
|
|
|
}
|
2015-07-13 12:48:29 +02:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-07-16 11:38:54 +02:00
|
|
|
|
void TMainWindow::InitWindow()
|
2015-07-13 12:48:29 +02:00
|
|
|
|
{
|
2015-07-16 11:38:54 +02:00
|
|
|
|
SCASSERT(m != nullptr);
|
2015-07-13 12:48:29 +02:00
|
|
|
|
ui->labelToolTip->setVisible(false);
|
|
|
|
|
ui->tabWidget->setVisible(true);
|
2015-10-29 17:20:59 +01:00
|
|
|
|
ui->dockWidgetDiagram->setVisible(dockDiagramVisible);
|
|
|
|
|
actionDockDiagram->setEnabled(true);
|
2015-07-25 17:18:01 +02:00
|
|
|
|
ui->tabWidget->setCurrentIndex(0);
|
2015-07-13 12:48:29 +02:00
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
|
ui->plainTextEditNotes->setEnabled(true);
|
2015-08-18 13:53:30 +02:00
|
|
|
|
ui->toolBarGradation->setVisible(true);
|
2015-07-15 09:16:59 +02:00
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
|
if (mType == MeasurementsType::Standard)
|
2015-07-13 12:48:29 +02:00
|
|
|
|
{
|
2015-07-14 18:28:50 +02:00
|
|
|
|
ui->labelMType->setText(tr("Standard measurements"));
|
2015-07-18 13:08:44 +02:00
|
|
|
|
ui->labelBaseSizeValue->setText(QString().setNum(m->BaseSize()) + " " +
|
|
|
|
|
VDomDocument::UnitsToStr(m->MUnit(), true));
|
|
|
|
|
ui->labelBaseHeightValue->setText(QString().setNum(m->BaseHeight()) + " " +
|
|
|
|
|
VDomDocument::UnitsToStr(m->MUnit(), true));
|
2015-07-14 18:28:50 +02:00
|
|
|
|
|
2015-09-03 12:31:23 +02:00
|
|
|
|
// Because Qt Designer doesn't know about our deleting we will create empty objects for correct
|
|
|
|
|
// working the retranslation UI
|
2015-07-13 12:48:29 +02:00
|
|
|
|
// Tab Measurements
|
|
|
|
|
delete ui->horizontalLayoutValue;
|
2015-07-18 13:08:44 +02:00
|
|
|
|
delete ui->plainTextEditFormula;
|
2015-07-21 17:28:20 +02:00
|
|
|
|
delete ui->toolButtonExpr;
|
2015-07-13 12:48:29 +02:00
|
|
|
|
|
2015-09-03 12:31:23 +02:00
|
|
|
|
delete ui->labelFormula;
|
|
|
|
|
ui->labelFormula = new QLabel(this);
|
|
|
|
|
|
|
|
|
|
delete ui->pushButtonGrow;
|
|
|
|
|
ui->pushButtonGrow = new QPushButton(this);
|
|
|
|
|
|
2015-07-13 12:48:29 +02:00
|
|
|
|
// Tab Information
|
|
|
|
|
delete ui->lineEditGivenName;
|
|
|
|
|
delete ui->lineEditFamilyName;
|
2015-10-13 10:13:43 +02:00
|
|
|
|
delete ui->comboBoxGender;
|
2015-09-03 12:31:23 +02:00
|
|
|
|
delete ui->lineEditEmail;
|
|
|
|
|
|
|
|
|
|
delete ui->labelGivenName;
|
|
|
|
|
ui->labelGivenName = new QLabel(this);
|
|
|
|
|
|
|
|
|
|
delete ui->labelFamilyName;
|
|
|
|
|
ui->labelFamilyName = new QLabel(this);
|
|
|
|
|
|
2015-07-13 12:48:29 +02:00
|
|
|
|
delete ui->labelBirthDate;
|
2015-09-03 12:31:23 +02:00
|
|
|
|
ui->labelBirthDate = new QLabel(this);
|
|
|
|
|
|
2015-07-13 12:48:29 +02:00
|
|
|
|
delete ui->dateEditBirthDate;
|
2015-09-03 12:31:23 +02:00
|
|
|
|
ui->dateEditBirthDate = new QDateEdit(this);
|
|
|
|
|
|
2015-10-13 10:13:43 +02:00
|
|
|
|
delete ui->labelGender;
|
|
|
|
|
ui->labelGender = new QLabel(this);
|
2015-09-03 12:31:23 +02:00
|
|
|
|
|
2015-07-13 12:48:29 +02:00
|
|
|
|
delete ui->labelEmail;
|
2015-09-03 12:31:23 +02:00
|
|
|
|
ui->labelEmail = new QLabel(this);
|
2015-07-21 15:18:10 +02:00
|
|
|
|
|
|
|
|
|
const QStringList listHeights = VMeasurement::WholeListHeights(mUnit);
|
|
|
|
|
const QStringList listSizes = VMeasurement::WholeListSizes(mUnit);
|
|
|
|
|
|
2015-10-16 19:26:05 +02:00
|
|
|
|
labelGradationHeights = new QLabel(tr("Height: "));
|
|
|
|
|
gradationHeights = SetGradationList(labelGradationHeights, listHeights);
|
2015-07-21 15:18:10 +02:00
|
|
|
|
SetDefaultHeight(static_cast<int>(data->height()));
|
|
|
|
|
connect(gradationHeights, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
|
|
|
|
|
this, &TMainWindow::ChangedHeight);
|
|
|
|
|
|
2015-10-16 19:26:05 +02:00
|
|
|
|
labelGradationSizes = new QLabel(tr("Size: "));
|
|
|
|
|
gradationSizes = SetGradationList(labelGradationSizes, listSizes);
|
2015-07-21 15:18:10 +02:00
|
|
|
|
SetDefaultSize(static_cast<int>(data->size()));
|
|
|
|
|
connect(gradationSizes, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
|
|
|
|
|
this, &TMainWindow::ChangedSize);
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
2015-07-25 08:10:56 +02:00
|
|
|
|
connect(ui->doubleSpinBoxBaseValue,
|
|
|
|
|
static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
|
|
|
|
|
this, &TMainWindow::SaveMBaseValue);
|
|
|
|
|
connect(ui->doubleSpinBoxInSizes,
|
|
|
|
|
static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
|
|
|
|
|
this, &TMainWindow::SaveMSizeIncrease);
|
|
|
|
|
connect(ui->doubleSpinBoxInHeights,
|
|
|
|
|
static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged),
|
|
|
|
|
this, &TMainWindow::SaveMHeightIncrease);
|
|
|
|
|
|
|
|
|
|
SetDecimals();
|
2015-07-13 12:48:29 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-07-14 18:28:50 +02:00
|
|
|
|
ui->labelMType->setText(tr("Individual measurements"));
|
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
|
ui->lineEditGivenName->setEnabled(true);
|
|
|
|
|
ui->lineEditFamilyName->setEnabled(true);
|
|
|
|
|
ui->dateEditBirthDate->setEnabled(true);
|
2015-10-13 10:13:43 +02:00
|
|
|
|
ui->comboBoxGender->setEnabled(true);
|
2015-07-16 11:38:54 +02:00
|
|
|
|
ui->lineEditEmail->setEnabled(true);
|
|
|
|
|
|
2015-07-13 12:48:29 +02:00
|
|
|
|
// Tab Measurements
|
2015-07-25 08:10:56 +02:00
|
|
|
|
delete ui->doubleSpinBoxBaseValue;
|
|
|
|
|
delete ui->doubleSpinBoxInSizes;
|
|
|
|
|
delete ui->doubleSpinBoxInHeights;
|
2015-07-13 12:48:29 +02:00
|
|
|
|
|
2015-09-03 12:31:23 +02:00
|
|
|
|
delete ui->labelBaseValue;
|
|
|
|
|
ui->labelBaseValue = new QLabel(this);
|
|
|
|
|
|
|
|
|
|
delete ui->labelInSizes;
|
|
|
|
|
ui->labelInSizes = new QLabel(this);
|
|
|
|
|
|
|
|
|
|
delete ui->labelInHeights;
|
|
|
|
|
ui->labelInHeights = new QLabel(this);
|
|
|
|
|
|
2015-07-13 12:48:29 +02:00
|
|
|
|
// Tab Information
|
|
|
|
|
delete ui->labelBaseSize;
|
2015-09-03 12:31:23 +02:00
|
|
|
|
ui->labelBaseSize = new QLabel(this);
|
|
|
|
|
|
2015-07-13 12:48:29 +02:00
|
|
|
|
delete ui->labelBaseSizeValue;
|
2015-09-03 12:31:23 +02:00
|
|
|
|
ui->labelBaseSizeValue = new QLabel(this);
|
|
|
|
|
|
2015-07-13 12:48:29 +02:00
|
|
|
|
delete ui->labelBaseHeight;
|
2015-09-03 12:31:23 +02:00
|
|
|
|
ui->labelBaseHeight = new QLabel(this);
|
|
|
|
|
|
2015-07-13 12:48:29 +02:00
|
|
|
|
delete ui->labelBaseHeightValue;
|
2015-09-03 12:31:23 +02:00
|
|
|
|
ui->labelBaseHeightValue = new QLabel(this);
|
2015-07-18 13:08:44 +02:00
|
|
|
|
|
|
|
|
|
ui->lineEditGivenName->setText(m->GivenName());
|
|
|
|
|
ui->lineEditFamilyName->setText(m->FamilyName());
|
|
|
|
|
|
2015-10-16 19:26:05 +02:00
|
|
|
|
ui->comboBoxGender->clear();
|
|
|
|
|
InitGender(ui->comboBoxGender);
|
2015-10-13 10:13:43 +02:00
|
|
|
|
const qint32 index = ui->comboBoxGender->findData(static_cast<int>(m->Gender()));
|
|
|
|
|
ui->comboBoxGender->setCurrentIndex(index);
|
2015-07-18 13:08:44 +02:00
|
|
|
|
|
|
|
|
|
ui->dateEditBirthDate->setDate(m->BirthDate());
|
|
|
|
|
ui->lineEditEmail->setText(m->Email());
|
|
|
|
|
|
|
|
|
|
connect(ui->lineEditGivenName, &QLineEdit::editingFinished, this, &TMainWindow::SaveGivenName);
|
|
|
|
|
connect(ui->lineEditFamilyName, &QLineEdit::editingFinished, this, &TMainWindow::SaveFamilyName);
|
|
|
|
|
connect(ui->lineEditEmail, &QLineEdit::editingFinished, this, &TMainWindow::SaveEmail);
|
2015-10-13 10:13:43 +02:00
|
|
|
|
connect(ui->comboBoxGender, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
|
|
|
|
&TMainWindow::SaveGender);
|
2015-07-18 13:08:44 +02:00
|
|
|
|
connect(ui->dateEditBirthDate, &QDateEdit::dateChanged, this, &TMainWindow::SaveBirthDate);
|
2015-07-21 18:24:47 +02:00
|
|
|
|
connect(ui->pushButtonGrow, &QPushButton::clicked, this, &TMainWindow::DeployFormula);
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
|
this->formulaBaseHeight = ui->plainTextEditFormula->height();
|
|
|
|
|
connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &TMainWindow::SaveMValue,
|
|
|
|
|
Qt::UniqueConnection);
|
2015-07-24 14:06:53 +02:00
|
|
|
|
|
|
|
|
|
connect(ui->toolButtonExpr, &QToolButton::clicked, this, &TMainWindow::Fx);
|
2015-07-13 12:48:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-16 19:26:05 +02:00
|
|
|
|
ui->comboBoxPMSystem->setEnabled(true);
|
|
|
|
|
ui->comboBoxPMSystem->clear();
|
|
|
|
|
InitPMSystems(ui->comboBoxPMSystem);
|
|
|
|
|
const qint32 index = ui->comboBoxPMSystem->findData(QLatin1Char('p')+m->PMSystem());
|
|
|
|
|
ui->comboBoxPMSystem->setCurrentIndex(index);
|
|
|
|
|
connect(ui->comboBoxPMSystem, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
|
|
|
|
&TMainWindow::SavePMSystem);
|
|
|
|
|
|
2015-09-15 18:49:24 +02:00
|
|
|
|
connect(ui->lineEditFind, &QLineEdit::textEdited, this, &TMainWindow::Find);
|
|
|
|
|
connect(ui->toolButtonFindPrevious, &QToolButton::clicked, this, &TMainWindow::FindPrevious);
|
|
|
|
|
connect(ui->toolButtonFindNext, &QToolButton::clicked, this, &TMainWindow::FindNext);
|
|
|
|
|
|
2015-09-08 15:10:37 +02:00
|
|
|
|
ui->plainTextEditNotes->setPlainText(m->Notes());
|
|
|
|
|
connect(ui->plainTextEditNotes, &QPlainTextEdit::textChanged, this, &TMainWindow::SaveNotes);
|
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
|
ui->actionAddCustom->setEnabled(true);
|
|
|
|
|
ui->actionAddKnown->setEnabled(true);
|
2015-08-11 16:52:18 +02:00
|
|
|
|
ui->actionImportFromPattern->setEnabled(true);
|
2015-07-16 11:38:54 +02:00
|
|
|
|
ui->actionReadOnly->setEnabled(true);
|
2015-07-18 14:39:33 +02:00
|
|
|
|
ui->actionSaveAs->setEnabled(true);
|
2015-07-16 11:38:54 +02:00
|
|
|
|
|
2015-10-08 19:45:26 +02:00
|
|
|
|
#if QT_VERSION > QT_VERSION_CHECK(5, 1, 0)
|
|
|
|
|
ui->lineEditName->setValidator( new QRegularExpressionValidator(QRegularExpression(NameRegExp()), this));
|
|
|
|
|
#else
|
|
|
|
|
ui->lineEditName->setValidator( new QRegExpValidator(QRegExp(NameRegExp()), this));
|
|
|
|
|
#endif
|
2015-07-22 11:47:51 +02:00
|
|
|
|
|
2015-07-22 08:41:04 +02:00
|
|
|
|
connect(ui->toolButtonRemove, &QToolButton::clicked, this, &TMainWindow::Remove);
|
2015-10-12 16:57:11 +02:00
|
|
|
|
connect(ui->toolButtonTop, &QToolButton::clicked, this, &TMainWindow::MoveTop);
|
2015-07-22 09:01:34 +02:00
|
|
|
|
connect(ui->toolButtonUp, &QToolButton::clicked, this, &TMainWindow::MoveUp);
|
|
|
|
|
connect(ui->toolButtonDown, &QToolButton::clicked, this, &TMainWindow::MoveDown);
|
2015-10-12 16:57:11 +02:00
|
|
|
|
connect(ui->toolButtonBottom, &QToolButton::clicked, this, &TMainWindow::MoveBottom);
|
2015-07-22 08:41:04 +02:00
|
|
|
|
|
2015-07-22 11:44:31 +02:00
|
|
|
|
connect(ui->lineEditName, &QLineEdit::editingFinished, this, &TMainWindow::SaveMName);
|
|
|
|
|
connect(ui->plainTextEditDescription, &QPlainTextEdit::textChanged, this, &TMainWindow::SaveMDescription);
|
2015-07-25 10:54:39 +02:00
|
|
|
|
connect(ui->lineEditFullName, &QLineEdit::editingFinished, this, &TMainWindow::SaveMFullName);
|
2015-07-22 11:44:31 +02:00
|
|
|
|
|
2015-07-25 15:37:07 +02:00
|
|
|
|
connect(ui->pushButtonShowInExplorer, &QPushButton::clicked, this, &TMainWindow::ShowInGraphicalShell);
|
|
|
|
|
|
2015-08-18 13:53:30 +02:00
|
|
|
|
InitUnits();
|
|
|
|
|
|
2015-07-16 11:38:54 +02:00
|
|
|
|
InitTable();
|
2015-07-13 12:48:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-07-16 11:38:54 +02:00
|
|
|
|
void TMainWindow::InitTable()
|
2015-07-13 12:48:29 +02:00
|
|
|
|
{
|
2015-07-16 11:38:54 +02:00
|
|
|
|
if (mType == MeasurementsType::Standard)
|
2015-07-13 12:48:29 +02:00
|
|
|
|
{
|
2015-09-29 17:46:00 +02:00
|
|
|
|
ui->tableWidget->setColumnHidden( ColumnFormula, true );// formula
|
2015-07-13 12:48:29 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-09-29 17:46:00 +02:00
|
|
|
|
ui->tableWidget->setColumnHidden( ColumnBaseValue, true );// base value
|
|
|
|
|
ui->tableWidget->setColumnHidden( ColumnInSizes, true );// in sizes
|
|
|
|
|
ui->tableWidget->setColumnHidden( ColumnInHeights, true );// in heights
|
2015-07-13 12:48:29 +02:00
|
|
|
|
}
|
2015-07-21 17:28:20 +02:00
|
|
|
|
|
|
|
|
|
connect(ui->tableWidget, &QTableWidget::itemSelectionChanged, this, &TMainWindow::ShowMData);
|
2015-07-21 18:13:09 +02:00
|
|
|
|
|
|
|
|
|
ShowUnits();
|
|
|
|
|
|
|
|
|
|
ui->tableWidget->resizeColumnsToContents();
|
|
|
|
|
ui->tableWidget->resizeRowsToContents();
|
2015-07-25 09:44:33 +02:00
|
|
|
|
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
|
2015-07-21 18:13:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::ShowUnits()
|
|
|
|
|
{
|
|
|
|
|
const QString unit = VDomDocument::UnitsToStr(mUnit);
|
|
|
|
|
|
2015-09-29 17:46:00 +02:00
|
|
|
|
ShowHeaderUnits(ui->tableWidget, ColumnCalcValue, VDomDocument::UnitsToStr(pUnit));// calculated value
|
|
|
|
|
ShowHeaderUnits(ui->tableWidget, ColumnFormula, unit);// formula
|
|
|
|
|
ShowHeaderUnits(ui->tableWidget, ColumnBaseValue, unit);// base value
|
|
|
|
|
ShowHeaderUnits(ui->tableWidget, ColumnInSizes, unit);// in sizes
|
|
|
|
|
ShowHeaderUnits(ui->tableWidget, ColumnInHeights, unit);// in heights
|
2015-07-21 18:13:09 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::ShowHeaderUnits(QTableWidget *table, int column, const QString &unit)
|
|
|
|
|
{
|
|
|
|
|
SCASSERT(table != nullptr);
|
|
|
|
|
|
2015-08-18 13:53:30 +02:00
|
|
|
|
QString header = table->horizontalHeaderItem(column)->text();
|
2015-09-29 17:46:00 +02:00
|
|
|
|
const int index = header.indexOf(QLatin1Literal("("));
|
2015-08-18 13:53:30 +02:00
|
|
|
|
if (index != -1)
|
|
|
|
|
{
|
|
|
|
|
header.remove(index-1, 100);
|
|
|
|
|
}
|
2015-07-21 18:13:09 +02:00
|
|
|
|
const QString unitHeader = QString("%1 (%2)").arg(header).arg(unit);
|
|
|
|
|
table->horizontalHeaderItem(column)->setText(unitHeader);
|
2015-07-13 12:48:29 +02:00
|
|
|
|
}
|
2015-07-18 14:39:33 +02:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::MeasurementsWasSaved(bool saved)
|
|
|
|
|
{
|
|
|
|
|
setWindowModified(!saved);
|
|
|
|
|
ui->actionSave->setEnabled(!saved);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SetCurrentFile(const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
curFile = fileName;
|
|
|
|
|
QString shownName = QFileInfo(curFile).fileName();
|
|
|
|
|
if (curFile.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
shownName = tr("untitled");
|
|
|
|
|
if (mType == MeasurementsType::Standard)
|
|
|
|
|
{
|
|
|
|
|
shownName += ".vst";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
shownName += ".vit";
|
|
|
|
|
}
|
|
|
|
|
ui->labelPathToFile->setText(tr("<Empty>"));
|
2015-07-25 15:37:07 +02:00
|
|
|
|
ui->pushButtonShowInExplorer->setEnabled(false);
|
2015-07-18 14:39:33 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->labelPathToFile->setText(curFile);
|
2015-07-25 15:05:16 +02:00
|
|
|
|
ui->labelPathToFile->setToolTip(curFile);
|
2015-07-25 15:37:07 +02:00
|
|
|
|
ui->pushButtonShowInExplorer->setEnabled(true);
|
2015-07-18 14:39:33 +02:00
|
|
|
|
}
|
|
|
|
|
shownName += "[*]";
|
|
|
|
|
setWindowTitle(shownName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
bool TMainWindow::SaveMeasurements(const QString &fileName, QString &error)
|
|
|
|
|
{
|
|
|
|
|
const bool result = m->SaveDocument(fileName, error);
|
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
SetCurrentFile(fileName);
|
|
|
|
|
MeasurementsWasSaved(result);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2015-07-18 15:01:57 +02:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
bool TMainWindow::MaybeSave()
|
|
|
|
|
{
|
|
|
|
|
if (this->isWindowModified())
|
|
|
|
|
{
|
2015-09-09 12:00:22 +02:00
|
|
|
|
if (curFile.isEmpty() && ui->tableWidget->rowCount() == 0)
|
|
|
|
|
{
|
|
|
|
|
return true;// Don't ask if file was created without modifications.
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-18 15:01:57 +02:00
|
|
|
|
QMessageBox::StandardButton ret;
|
|
|
|
|
ret = QMessageBox::warning(this, tr("Unsaved changes"), tr("Measurements have been modified.\n"
|
2015-10-01 16:59:01 +02:00
|
|
|
|
"Do you want to save your changes?"),
|
2015-07-18 15:01:57 +02:00
|
|
|
|
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
|
|
|
|
|
if (ret == QMessageBox::Save)
|
|
|
|
|
{
|
|
|
|
|
FileSave();
|
|
|
|
|
}
|
|
|
|
|
else if (ret == QMessageBox::Cancel)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-07-19 14:28:01 +02:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-09-29 16:04:24 +02:00
|
|
|
|
QTableWidgetItem *TMainWindow::AddCell(const QString &text, int row, int column, int aligment, bool ok)
|
2015-07-19 14:28:01 +02:00
|
|
|
|
{
|
|
|
|
|
QTableWidgetItem *item = new QTableWidgetItem(text);
|
2015-08-01 15:00:33 +02:00
|
|
|
|
item->setTextAlignment(aligment);
|
2015-07-21 19:26:33 +02:00
|
|
|
|
|
2015-07-19 14:28:01 +02:00
|
|
|
|
// 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);
|
|
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
|
if (not ok)
|
|
|
|
|
{
|
|
|
|
|
QBrush brush = item->foreground();
|
|
|
|
|
brush.setColor(Qt::red);
|
|
|
|
|
item->setForeground(brush);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-19 14:28:01 +02:00
|
|
|
|
ui->tableWidget->setItem(row, column, item);
|
2015-09-29 16:04:24 +02:00
|
|
|
|
|
|
|
|
|
return item;
|
2015-07-19 14:28:01 +02:00
|
|
|
|
}
|
2015-07-21 15:18:10 +02:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-10-16 19:26:05 +02:00
|
|
|
|
QComboBox *TMainWindow::SetGradationList(QLabel *label, const QStringList &list)
|
2015-07-21 15:18:10 +02:00
|
|
|
|
{
|
2015-10-16 19:26:05 +02:00
|
|
|
|
ui->toolBarGradation->addWidget(label);
|
2015-07-21 15:18:10 +02:00
|
|
|
|
|
|
|
|
|
QComboBox *comboBox = new QComboBox;
|
|
|
|
|
comboBox->addItems(list);
|
|
|
|
|
ui->toolBarGradation->addWidget(comboBox);
|
|
|
|
|
|
|
|
|
|
return comboBox;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SetDefaultHeight(int value)
|
|
|
|
|
{
|
|
|
|
|
const qint32 index = gradationHeights->findText(QString("%1").arg(value));
|
|
|
|
|
if (index != -1)
|
|
|
|
|
{
|
|
|
|
|
gradationHeights->setCurrentIndex(index);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
data->SetHeight(gradationHeights->currentText().toInt());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SetDefaultSize(int value)
|
|
|
|
|
{
|
|
|
|
|
const qint32 index = gradationSizes->findText(QString("%1").arg(value));
|
|
|
|
|
if (index != -1)
|
|
|
|
|
{
|
|
|
|
|
gradationSizes->setCurrentIndex(index);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
data->SetSize(gradationSizes->currentText().toInt());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::RefreshData()
|
|
|
|
|
{
|
2015-09-15 18:49:24 +02:00
|
|
|
|
data->ClearUniqueNames();
|
2015-07-24 12:06:39 +02:00
|
|
|
|
data->ClearVariables(VarType::Measurement);
|
|
|
|
|
m->ReadMeasurements();
|
|
|
|
|
|
|
|
|
|
RefreshTable();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::RefreshTable()
|
|
|
|
|
{
|
|
|
|
|
ui->tableWidget->blockSignals(true);
|
|
|
|
|
ui->tableWidget->clearContents();
|
|
|
|
|
|
|
|
|
|
const QMap<QString, QSharedPointer<VMeasurement> > table = data->DataMeasurements();
|
|
|
|
|
QMap<int, QSharedPointer<VMeasurement> > orderedTable;
|
|
|
|
|
QMap<QString, QSharedPointer<VMeasurement> >::const_iterator iterMap;
|
|
|
|
|
for (iterMap = table.constBegin(); iterMap != table.constEnd(); ++iterMap)
|
|
|
|
|
{
|
|
|
|
|
QSharedPointer<VMeasurement> meash = iterMap.value();
|
|
|
|
|
orderedTable.insert(meash->Index(), meash);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qint32 currentRow = -1;
|
|
|
|
|
QMap<int, QSharedPointer<VMeasurement> >::const_iterator iMap;
|
|
|
|
|
ui->tableWidget->setRowCount ( orderedTable.size() );
|
|
|
|
|
for (iMap = orderedTable.constBegin(); iMap != orderedTable.constEnd(); ++iMap)
|
|
|
|
|
{
|
|
|
|
|
QSharedPointer<VMeasurement> meash = iMap.value();
|
|
|
|
|
currentRow++;
|
|
|
|
|
|
|
|
|
|
if (mType == MeasurementsType::Individual)
|
|
|
|
|
{
|
2015-09-29 17:46:00 +02:00
|
|
|
|
QTableWidgetItem *item = AddCell(qApp->TrVars()->MToUser(meash->GetName()), currentRow, ColumnName,
|
2015-09-29 16:04:24 +02:00
|
|
|
|
Qt::AlignVCenter); // name
|
|
|
|
|
item->setData(Qt::UserRole, meash->GetName());
|
2015-08-18 13:53:30 +02:00
|
|
|
|
|
2015-09-29 17:46:00 +02:00
|
|
|
|
if (meash->IsCustom())
|
|
|
|
|
{
|
|
|
|
|
AddCell(meash->GetGuiText(), currentRow, ColumnFullName, Qt::AlignVCenter);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
AddCell(qApp->TrVars()->GuiText(meash->GetName()), currentRow, ColumnFullName, Qt::AlignVCenter);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-18 13:53:30 +02:00
|
|
|
|
const qreal value = UnitConvertor(*meash->GetValue(), mUnit, pUnit);
|
2015-09-29 17:46:00 +02:00
|
|
|
|
AddCell(QString().setNum(value), currentRow, ColumnCalcValue, Qt::AlignHCenter | Qt::AlignVCenter,
|
2015-08-01 15:00:33 +02:00
|
|
|
|
meash->IsFormulaOk()); // calculated value
|
2015-07-21 15:18:10 +02:00
|
|
|
|
|
2015-07-24 12:06:39 +02:00
|
|
|
|
QString formula;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
formula = qApp->TrVars()->FormulaToUser(meash->GetFormula());
|
|
|
|
|
}
|
|
|
|
|
catch (qmu::QmuParserError &e)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(e);
|
|
|
|
|
formula = meash->GetFormula();
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-29 17:46:00 +02:00
|
|
|
|
AddCell(formula, currentRow, ColumnFormula, Qt::AlignVCenter); // formula
|
2015-07-24 12:06:39 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-10-03 00:38:50 +02:00
|
|
|
|
QTableWidgetItem *item = AddCell(qApp->TrVars()->MToUser(meash->GetName()), currentRow, 0,
|
|
|
|
|
Qt::AlignVCenter); // name
|
|
|
|
|
item->setData(Qt::UserRole, meash->GetName());
|
2015-08-01 15:00:33 +02:00
|
|
|
|
|
2015-09-29 17:46:00 +02:00
|
|
|
|
if (meash->IsCustom())
|
|
|
|
|
{
|
|
|
|
|
AddCell(meash->GetGuiText(), currentRow, ColumnFullName, Qt::AlignVCenter);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
AddCell(qApp->TrVars()->GuiText(meash->GetName()), currentRow, ColumnFullName, Qt::AlignVCenter);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-18 13:53:30 +02:00
|
|
|
|
const qreal value = UnitConvertor(data->GetTableValue(meash->GetName(), mType), mUnit, pUnit);
|
2015-09-29 17:46:00 +02:00
|
|
|
|
AddCell(QString().setNum(value), currentRow, ColumnCalcValue,
|
2015-08-01 15:00:33 +02:00
|
|
|
|
Qt::AlignHCenter | Qt::AlignVCenter, meash->IsFormulaOk()); // calculated value
|
|
|
|
|
|
2015-09-29 17:46:00 +02:00
|
|
|
|
AddCell(QString().setNum(meash->GetBase()), currentRow, ColumnBaseValue,
|
2015-08-01 15:00:33 +02:00
|
|
|
|
Qt::AlignHCenter | Qt::AlignVCenter); // base value
|
|
|
|
|
|
2015-09-29 17:46:00 +02:00
|
|
|
|
AddCell(QString().setNum(meash->GetKsize()), currentRow, ColumnInSizes,
|
2015-08-01 15:00:33 +02:00
|
|
|
|
Qt::AlignHCenter | Qt::AlignVCenter); // in sizes
|
|
|
|
|
|
2015-09-29 17:46:00 +02:00
|
|
|
|
AddCell(QString().setNum(meash->GetKheight()), currentRow, ColumnInHeights,
|
2015-08-01 15:00:33 +02:00
|
|
|
|
Qt::AlignHCenter | Qt::AlignVCenter); // in heights
|
2015-07-24 12:06:39 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui->tableWidget->resizeColumnsToContents();
|
|
|
|
|
ui->tableWidget->resizeRowsToContents();
|
|
|
|
|
ui->tableWidget->horizontalHeader()->setStretchLastSection(true);
|
|
|
|
|
ui->tableWidget->blockSignals(false);
|
2015-07-21 15:18:10 +02:00
|
|
|
|
}
|
2015-07-21 17:28:20 +02:00
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::Controls()
|
|
|
|
|
{
|
|
|
|
|
if (m->ReadOnly())
|
|
|
|
|
{
|
|
|
|
|
ui->toolButtonRemove->setEnabled(false);
|
2015-10-12 16:57:11 +02:00
|
|
|
|
ui->toolButtonTop->setEnabled(false);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
ui->toolButtonUp->setEnabled(false);
|
|
|
|
|
ui->toolButtonDown->setEnabled(false);
|
2015-10-12 16:57:11 +02:00
|
|
|
|
ui->toolButtonBottom->setEnabled(false);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
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)
|
|
|
|
|
{
|
2015-10-12 16:57:11 +02:00
|
|
|
|
ui->toolButtonTop->setEnabled(false);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
ui->toolButtonUp->setEnabled(false);
|
|
|
|
|
ui->toolButtonDown->setEnabled(true);
|
2015-10-12 16:57:11 +02:00
|
|
|
|
ui->toolButtonBottom->setEnabled(true);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
|
|
|
|
else if (ui->tableWidget->currentRow() == ui->tableWidget->rowCount()-1)
|
|
|
|
|
{
|
2015-10-12 16:57:11 +02:00
|
|
|
|
ui->toolButtonTop->setEnabled(true);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
ui->toolButtonUp->setEnabled(true);
|
|
|
|
|
ui->toolButtonDown->setEnabled(false);
|
2015-10-12 16:57:11 +02:00
|
|
|
|
ui->toolButtonBottom->setEnabled(false);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-10-12 16:57:11 +02:00
|
|
|
|
ui->toolButtonTop->setEnabled(true);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
ui->toolButtonUp->setEnabled(true);
|
|
|
|
|
ui->toolButtonDown->setEnabled(true);
|
2015-10-12 16:57:11 +02:00
|
|
|
|
ui->toolButtonBottom->setEnabled(true);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-10-12 16:57:11 +02:00
|
|
|
|
ui->toolButtonTop->setEnabled(false);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
ui->toolButtonUp->setEnabled(false);
|
|
|
|
|
ui->toolButtonDown->setEnabled(false);
|
2015-10-12 16:57:11 +02:00
|
|
|
|
ui->toolButtonBottom->setEnabled(false);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::MFields(bool enabled)
|
|
|
|
|
{
|
2015-09-09 11:45:30 +02:00
|
|
|
|
ui->lineEditName->setEnabled(enabled);
|
|
|
|
|
ui->plainTextEditDescription->setEnabled(enabled);
|
|
|
|
|
ui->lineEditFullName->setEnabled(enabled);
|
|
|
|
|
|
2015-07-21 17:28:20 +02:00
|
|
|
|
if (mType == MeasurementsType::Standard)
|
|
|
|
|
{
|
2015-07-25 08:10:56 +02:00
|
|
|
|
ui->doubleSpinBoxBaseValue->setEnabled(enabled);
|
|
|
|
|
ui->doubleSpinBoxInSizes->setEnabled(enabled);
|
|
|
|
|
ui->doubleSpinBoxInHeights->setEnabled(enabled);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-09-09 11:45:30 +02:00
|
|
|
|
ui->plainTextEditFormula->setEnabled(enabled);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
ui->pushButtonGrow->setEnabled(enabled);
|
|
|
|
|
ui->toolButtonExpr->setEnabled(enabled);
|
|
|
|
|
}
|
2015-09-15 18:49:24 +02:00
|
|
|
|
|
|
|
|
|
ui->lineEditFind->setEnabled(enabled);
|
|
|
|
|
ui->toolButtonFindPrevious->setEnabled(enabled);
|
|
|
|
|
ui->toolButtonFindNext->setEnabled(enabled);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
QString TMainWindow::ClearCustomName(const QString &name) const
|
|
|
|
|
{
|
|
|
|
|
QString clear = name;
|
2015-08-25 12:35:50 +02:00
|
|
|
|
const int index = clear.indexOf(CustomMSign);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
if (index == 0)
|
|
|
|
|
{
|
|
|
|
|
clear.remove(0, 1);
|
|
|
|
|
}
|
|
|
|
|
return clear;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
2015-08-25 12:35:50 +02:00
|
|
|
|
bool TMainWindow::EvalFormula(const QString &formula, bool fromUser, VContainer *data, QLabel *label)
|
2015-07-21 17:28:20 +02:00
|
|
|
|
{
|
2015-08-18 13:53:30 +02:00
|
|
|
|
const QString postfix = VDomDocument::UnitsToStr(pUnit);//Show unit in dialog lable (cm, mm or inch)
|
2015-07-21 17:28:20 +02:00
|
|
|
|
if (formula.isEmpty())
|
|
|
|
|
{
|
2015-08-25 12:35:50 +02:00
|
|
|
|
label->setText(tr("Error") + " (" + postfix + "). " + tr("Empty field."));
|
2015-07-21 17:28:20 +02:00
|
|
|
|
label->setToolTip(tr("Empty field"));
|
2015-08-25 12:35:50 +02:00
|
|
|
|
return false;
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// Replace line return character with spaces for calc if exist
|
2015-08-25 12:35:50 +02:00
|
|
|
|
QString f;
|
2015-09-29 16:04:24 +02:00
|
|
|
|
if (fromUser)
|
2015-08-25 12:35:50 +02:00
|
|
|
|
{
|
|
|
|
|
f = qApp->TrVars()->FormulaFromUser(formula, true);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
f = formula;
|
|
|
|
|
}
|
2015-07-21 17:28:20 +02:00
|
|
|
|
f.replace("\n", " ");
|
2015-10-15 12:07:43 +02:00
|
|
|
|
Calculator *cal = new Calculator();
|
|
|
|
|
const qreal result = UnitConvertor(cal->EvalFormula(data->PlainVariables(), f), mUnit, pUnit);
|
2015-07-21 17:28:20 +02:00
|
|
|
|
delete cal;
|
|
|
|
|
|
|
|
|
|
label->setText(qApp->LocaleToString(result) + " " +postfix);
|
|
|
|
|
label->setToolTip(tr("Value"));
|
2015-08-25 12:35:50 +02:00
|
|
|
|
return true;
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
|
|
|
|
catch (qmu::QmuParserError &e)
|
|
|
|
|
{
|
2015-08-25 12:35:50 +02:00
|
|
|
|
label->setText(tr("Error") + " (" + postfix + "). " + tr("Parser error: %1").arg(e.GetMsg()));
|
2015-07-21 17:28:20 +02:00
|
|
|
|
label->setToolTip(tr("Parser error: %1").arg(e.GetMsg()));
|
2015-08-25 12:35:50 +02:00
|
|
|
|
return false;
|
2015-07-21 17:28:20 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-25 08:10:56 +02:00
|
|
|
|
|
2015-07-25 14:59:40 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::Open(const QString &pathTo, const QString &filter)
|
|
|
|
|
{
|
|
|
|
|
const QString mPath = QFileDialog::getOpenFileName(this, tr("Open file"), pathTo, filter);
|
|
|
|
|
|
|
|
|
|
if (mPath.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LoadFile(mPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-25 17:18:01 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::GUIReadOnly(bool ro)
|
|
|
|
|
{
|
|
|
|
|
ui->actionReadOnly->setChecked(ro);
|
|
|
|
|
if (ro)
|
|
|
|
|
{
|
|
|
|
|
ui->actionReadOnly->setIcon(QIcon("://tapeicon/24x24/padlock_locked.png"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->actionReadOnly->setIcon(QIcon("://tapeicon/24x24/padlock_opened.png"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui->actionAddCustom->setDisabled(ro);
|
|
|
|
|
ui->actionAddKnown->setDisabled(ro);
|
|
|
|
|
|
2015-09-09 11:45:30 +02:00
|
|
|
|
ui->plainTextEditNotes->setReadOnly(ro);
|
|
|
|
|
|
|
|
|
|
if (mType == MeasurementsType::Individual)
|
|
|
|
|
{
|
|
|
|
|
ui->lineEditGivenName->setReadOnly(ro);
|
|
|
|
|
ui->lineEditFamilyName->setReadOnly(ro);
|
|
|
|
|
ui->dateEditBirthDate->setReadOnly(ro);
|
2015-10-13 10:13:43 +02:00
|
|
|
|
ui->comboBoxGender->setDisabled(ro);
|
2015-09-09 11:45:30 +02:00
|
|
|
|
ui->lineEditEmail->setReadOnly(ro);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-16 19:26:05 +02:00
|
|
|
|
ui->comboBoxPMSystem->setDisabled(ro);
|
|
|
|
|
|
2015-09-09 11:45:30 +02:00
|
|
|
|
MeasurementReadOnly(ro);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::MeasurementReadOnly(bool ro)
|
|
|
|
|
{
|
|
|
|
|
if (ro == false)
|
2015-07-25 17:18:01 +02:00
|
|
|
|
{
|
2015-10-03 00:44:44 +02:00
|
|
|
|
if (const QTableWidgetItem *nameField = ui->tableWidget->item(ui->tableWidget->currentRow(), ColumnName))
|
2015-07-25 17:18:01 +02:00
|
|
|
|
{
|
2015-08-25 12:35:50 +02:00
|
|
|
|
if (nameField->text().indexOf(CustomMSign) == 0) // Check if custom
|
2015-07-25 17:18:01 +02:00
|
|
|
|
{
|
|
|
|
|
ui->lineEditName->setReadOnly(ro);
|
2015-09-09 11:45:30 +02:00
|
|
|
|
ui->plainTextEditDescription->setReadOnly(ro);
|
|
|
|
|
ui->lineEditFullName->setReadOnly(ro);
|
2015-10-03 00:00:18 +02:00
|
|
|
|
|
|
|
|
|
// Need to block signals for QLineEdit in readonly mode because it still emits
|
|
|
|
|
// QLineEdit::editingFinished signal.
|
|
|
|
|
ui->lineEditName->blockSignals(ro);
|
|
|
|
|
ui->lineEditFullName->blockSignals(ro);
|
2015-09-09 11:45:30 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ // known measurement
|
|
|
|
|
ui->lineEditName->setReadOnly(not ro);
|
|
|
|
|
ui->plainTextEditDescription->setReadOnly(not ro);
|
|
|
|
|
ui->lineEditFullName->setReadOnly(not ro);
|
2015-10-03 00:00:18 +02:00
|
|
|
|
|
|
|
|
|
// Need to block signals for QLineEdit in readonly mode because it still emits
|
|
|
|
|
// QLineEdit::editingFinished signal.
|
|
|
|
|
ui->lineEditName->blockSignals(not ro);
|
|
|
|
|
ui->lineEditFullName->blockSignals(not ro);
|
2015-07-25 17:18:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-09-09 11:45:30 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-07-25 17:18:01 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ui->lineEditName->setReadOnly(ro);
|
2015-09-09 11:45:30 +02:00
|
|
|
|
ui->plainTextEditDescription->setReadOnly(ro);
|
|
|
|
|
ui->lineEditFullName->setReadOnly(ro);
|
2015-10-03 00:38:50 +02:00
|
|
|
|
|
|
|
|
|
// Need to block signals for QLineEdit in readonly mode because it still emits
|
|
|
|
|
// QLineEdit::editingFinished signal.
|
|
|
|
|
ui->lineEditName->blockSignals(ro);
|
|
|
|
|
ui->lineEditFullName->blockSignals(ro);
|
2015-07-25 17:18:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mType == MeasurementsType::Individual)
|
|
|
|
|
{
|
|
|
|
|
ui->plainTextEditFormula->setReadOnly(ro);
|
2015-10-03 00:38:50 +02:00
|
|
|
|
|
|
|
|
|
// Need to block signals for QLineEdit in readonly mode because it still emits QLineEdit::editingFinished
|
|
|
|
|
// signal.
|
|
|
|
|
ui->lineEditGivenName->blockSignals(ro);
|
|
|
|
|
ui->lineEditFamilyName->blockSignals(ro);
|
|
|
|
|
ui->lineEditEmail->blockSignals(ro);
|
2015-07-25 17:18:01 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-09-09 11:45:30 +02:00
|
|
|
|
ui->doubleSpinBoxBaseValue->setReadOnly(ro);
|
|
|
|
|
ui->doubleSpinBoxInSizes->setReadOnly(ro);
|
|
|
|
|
ui->doubleSpinBoxInHeights->setReadOnly(ro);
|
2015-07-25 17:18:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Controls(); // Buttons remove, up, down
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-01 19:09:10 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::ReadSettings()
|
|
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
|
const VTapeSettings *settings = qApp->TapeSettings();
|
|
|
|
|
restoreGeometry(settings->GetGeometry());
|
|
|
|
|
restoreState(settings->GetWindowState());
|
|
|
|
|
restoreState(settings->GetToolbarsState(), APP_VERSION);
|
2015-08-01 19:09:10 +02:00
|
|
|
|
|
|
|
|
|
// Stack limit
|
2015-10-28 15:22:36 +01:00
|
|
|
|
//qApp->getUndoStack()->setUndoLimit(settings->GetUndoCount());
|
2015-08-01 19:09:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::WriteSettings()
|
|
|
|
|
{
|
2015-10-28 15:22:36 +01:00
|
|
|
|
VTapeSettings *settings = qApp->TapeSettings();
|
|
|
|
|
settings->SetGeometry(saveGeometry());
|
|
|
|
|
settings->SetWindowState(saveState());
|
|
|
|
|
settings->SetToolbarsState(saveState(APP_VERSION));
|
2015-08-01 19:09:10 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-08-11 16:52:18 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
QStringList TMainWindow::FilterMeasurements(const QStringList &mNew, const QStringList &mFilter)
|
|
|
|
|
{
|
|
|
|
|
const QSet<QString> import = mNew.toSet().subtract(mFilter.toSet());
|
|
|
|
|
return QStringList(import.toList());
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-18 15:31:21 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::UpdatePatternUnit()
|
|
|
|
|
{
|
|
|
|
|
const int row = ui->tableWidget->currentRow();
|
|
|
|
|
|
|
|
|
|
if (row == -1)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ShowUnits();
|
|
|
|
|
RefreshTable();
|
|
|
|
|
|
2015-09-15 18:49:24 +02:00
|
|
|
|
search->RefreshList(ui->lineEditFind->text());
|
|
|
|
|
|
2015-08-18 15:31:21 +02:00
|
|
|
|
ui->tableWidget->selectRow(row);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-15 14:37:10 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
bool TMainWindow::LoadFromExistingFile(const QString &path)
|
|
|
|
|
{
|
|
|
|
|
if (m == nullptr)
|
|
|
|
|
{
|
|
|
|
|
if (not QFileInfo(path).exists())
|
|
|
|
|
{
|
|
|
|
|
qCCritical(tMainWindow, "%s", qUtf8Printable(tr("File '%1' doesn't exist!").arg(path)));
|
|
|
|
|
if (qApp->IsTestMode())
|
|
|
|
|
{
|
|
|
|
|
qApp->exit(V_EX_NOINPUT);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if file already opened
|
|
|
|
|
QList<TMainWindow*>list = qApp->MainWindows();
|
|
|
|
|
for (int i = 0; i < list.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
if (list.at(i)->CurrentFile() == path)
|
|
|
|
|
{
|
|
|
|
|
list.at(i)->activateWindow();
|
|
|
|
|
close();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-26 08:57:20 +01:00
|
|
|
|
VlpCreateLock(lock, QFileInfo(path).fileName());
|
2015-10-15 14:37:10 +02:00
|
|
|
|
|
|
|
|
|
if (not lock->IsLocked())
|
|
|
|
|
{
|
|
|
|
|
qCCritical(tMainWindow, "%s", qUtf8Printable(tr("This file already opened in another window.")));
|
|
|
|
|
if (qApp->IsTestMode())
|
|
|
|
|
{
|
|
|
|
|
qApp->exit(V_EX_NOINPUT);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
data = new VContainer(qApp->TrVars(), &mUnit);
|
|
|
|
|
|
|
|
|
|
m = new VMeasurements(data);
|
|
|
|
|
m->setXMLContent(path);
|
|
|
|
|
|
|
|
|
|
mType = m->Type();
|
|
|
|
|
|
|
|
|
|
if (mType == MeasurementsType::Unknown)
|
|
|
|
|
{
|
|
|
|
|
VException e(tr("File has unknown format."));
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mType == MeasurementsType::Standard)
|
|
|
|
|
{
|
|
|
|
|
VException e(tr("Export standard measurements not supported."));
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
VVITConverter converter(path);
|
|
|
|
|
converter.Convert();
|
|
|
|
|
|
|
|
|
|
VDomDocument::ValidateXML(VVITConverter::CurrentSchema, path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m->setXMLContent(path);// Read again after conversion
|
|
|
|
|
|
|
|
|
|
if (not m->IsDefinedKnownNamesValid())
|
|
|
|
|
{
|
|
|
|
|
VException e(tr("File contains invalid known measurement(s)."));
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mUnit = m->MUnit();
|
|
|
|
|
pUnit = mUnit;
|
|
|
|
|
|
|
|
|
|
data->SetHeight(m->BaseHeight());
|
|
|
|
|
data->SetSize(m->BaseSize());
|
|
|
|
|
|
|
|
|
|
ui->labelToolTip->setVisible(false);
|
|
|
|
|
ui->tabWidget->setVisible(true);
|
|
|
|
|
|
|
|
|
|
InitWindow();
|
|
|
|
|
|
|
|
|
|
m->ClearForExport();
|
|
|
|
|
RefreshData();
|
|
|
|
|
|
|
|
|
|
if (ui->tableWidget->rowCount() > 0)
|
|
|
|
|
{
|
|
|
|
|
ui->tableWidget->selectRow(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lock.reset();// Now we can unlock the file
|
|
|
|
|
|
|
|
|
|
GUIReadOnly(m->ReadOnly()); // Keep last
|
|
|
|
|
}
|
|
|
|
|
catch (VException &e)
|
|
|
|
|
{
|
|
|
|
|
qCCritical(tMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")),
|
|
|
|
|
qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation()));
|
|
|
|
|
ui->labelToolTip->setVisible(true);
|
|
|
|
|
ui->tabWidget->setVisible(false);
|
|
|
|
|
delete m;
|
|
|
|
|
m = nullptr;
|
|
|
|
|
delete data;
|
|
|
|
|
data = nullptr;
|
|
|
|
|
lock.reset();
|
|
|
|
|
|
|
|
|
|
if (qApp->IsTestMode())
|
|
|
|
|
{
|
|
|
|
|
qApp->exit(V_EX_NOINPUT);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
qApp->NewMainWindow();
|
|
|
|
|
return qApp->MainWindow()->LoadFile(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-25 08:10:56 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::SetDecimals()
|
|
|
|
|
{
|
|
|
|
|
switch (mUnit)
|
|
|
|
|
{
|
|
|
|
|
case Unit::Cm:
|
|
|
|
|
ui->doubleSpinBoxBaseValue->setDecimals(1);
|
|
|
|
|
ui->doubleSpinBoxInSizes->setDecimals(1);
|
|
|
|
|
ui->doubleSpinBoxInHeights->setDecimals(1);
|
|
|
|
|
break;
|
|
|
|
|
case Unit::Mm:
|
|
|
|
|
ui->doubleSpinBoxBaseValue->setDecimals(0);
|
|
|
|
|
ui->doubleSpinBoxInSizes->setDecimals(0);
|
|
|
|
|
ui->doubleSpinBoxInHeights->setDecimals(0);
|
|
|
|
|
break;
|
|
|
|
|
case Unit::Inch:
|
|
|
|
|
ui->doubleSpinBoxBaseValue->setDecimals(5);
|
|
|
|
|
ui->doubleSpinBoxInSizes->setDecimals(5);
|
|
|
|
|
ui->doubleSpinBoxInHeights->setDecimals(5);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-25 15:37:07 +02:00
|
|
|
|
|
2015-08-18 13:53:30 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::InitUnits()
|
|
|
|
|
{
|
2015-10-16 19:26:05 +02:00
|
|
|
|
labelPatternUnit = new QLabel(tr("Pattern unit:"));
|
|
|
|
|
ui->toolBarGradation->addWidget(labelPatternUnit);
|
2015-08-18 13:53:30 +02:00
|
|
|
|
|
|
|
|
|
comboBoxUnits = new QComboBox(this);
|
2015-10-16 19:26:05 +02:00
|
|
|
|
InitComboBoxUnits();
|
2015-08-18 13:53:30 +02:00
|
|
|
|
|
|
|
|
|
// set default unit
|
|
|
|
|
const qint32 indexUnit = comboBoxUnits->findData(static_cast<int>(pUnit));
|
|
|
|
|
if (indexUnit != -1)
|
|
|
|
|
{
|
|
|
|
|
comboBoxUnits->setCurrentIndex(indexUnit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connect(comboBoxUnits, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
|
|
|
|
|
&TMainWindow::PatternUnitChanged);
|
|
|
|
|
|
|
|
|
|
ui->toolBarGradation->addWidget(comboBoxUnits);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-16 19:26:05 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::InitComboBoxUnits()
|
|
|
|
|
{
|
|
|
|
|
SCASSERT(comboBoxUnits != nullptr);
|
|
|
|
|
comboBoxUnits->addItem(VDomDocument::UnitsToStr(Unit::Cm, true), QVariant(static_cast<int>(Unit::Cm)));
|
|
|
|
|
comboBoxUnits->addItem(VDomDocument::UnitsToStr(Unit::Mm, true), QVariant(static_cast<int>(Unit::Mm)));
|
|
|
|
|
comboBoxUnits->addItem(VDomDocument::UnitsToStr(Unit::Inch, true), QVariant(static_cast<int>(Unit::Inch)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::InitGender(QComboBox *gender)
|
|
|
|
|
{
|
|
|
|
|
SCASSERT(gender != nullptr);
|
|
|
|
|
gender->addItem(tr("unknown", "gender"), QVariant(static_cast<int>(GenderType::Unknown)));
|
|
|
|
|
gender->addItem(tr("male", "gender"), QVariant(static_cast<int>(GenderType::Male)));
|
|
|
|
|
gender->addItem(tr("female", "gender"), QVariant(static_cast<int>(GenderType::Female)));
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-25 15:37:07 +02:00
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
void TMainWindow::ShowInGraphicalShell()
|
|
|
|
|
{
|
|
|
|
|
#ifdef Q_WS_MAC
|
|
|
|
|
QStringList args;
|
|
|
|
|
args << "-e";
|
|
|
|
|
args << "tell application \"Finder\"";
|
|
|
|
|
args << "-e";
|
|
|
|
|
args << "activate";
|
|
|
|
|
args << "-e";
|
|
|
|
|
args << "select POSIX file \""+curFile+"\"";
|
|
|
|
|
args << "-e";
|
|
|
|
|
args << "end tell";
|
|
|
|
|
QProcess::startDetached("osascript", args);
|
|
|
|
|
#elif defined(Q_WS_WIN)
|
|
|
|
|
QStringList args;
|
|
|
|
|
args << "/select," << QDir::toNativeSeparators(curFile);
|
|
|
|
|
const QString command = "explorer" + " " + args;
|
|
|
|
|
QProcess::startDetached(command);
|
|
|
|
|
#else
|
|
|
|
|
const QString app = "xdg-open %d";
|
|
|
|
|
QString cmd;
|
|
|
|
|
for (int i = 0; i < app.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
QChar c = app.at(i);
|
|
|
|
|
if (c == QLatin1Char('%') && i < app.size()-1)
|
|
|
|
|
{
|
|
|
|
|
c = app.at(++i);
|
|
|
|
|
QString s;
|
|
|
|
|
if (c == QLatin1Char('d'))
|
|
|
|
|
{
|
|
|
|
|
s = QLatin1Char('"') + QFileInfo(curFile).path() + QLatin1Char('"');
|
|
|
|
|
}
|
|
|
|
|
else if (c == QLatin1Char('%'))
|
|
|
|
|
{
|
|
|
|
|
s = c;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
s = QLatin1Char('%');
|
|
|
|
|
s += c;
|
|
|
|
|
}
|
|
|
|
|
cmd += s;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
cmd += c;
|
|
|
|
|
}
|
|
|
|
|
QProcess::startDetached(cmd);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
}
|