Resolved issue #382. Add 'Create from existing file' option in Tape,
Create/Edit. --HG-- branch : develop
This commit is contained in:
parent
1e05300ae1
commit
3358f9dbc7
|
@ -385,6 +385,28 @@ void TMainWindow::OpenTemplate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void TMainWindow::Find(const QString &term)
|
void TMainWindow::Find(const QString &term)
|
||||||
{
|
{
|
||||||
|
@ -1557,6 +1579,7 @@ void TMainWindow::SetupMenu()
|
||||||
connect(ui->actionOpenIndividual, &QAction::triggered, this, &TMainWindow::OpenIndividual);
|
connect(ui->actionOpenIndividual, &QAction::triggered, this, &TMainWindow::OpenIndividual);
|
||||||
connect(ui->actionOpenStandard, &QAction::triggered, this, &TMainWindow::OpenStandard);
|
connect(ui->actionOpenStandard, &QAction::triggered, this, &TMainWindow::OpenStandard);
|
||||||
connect(ui->actionOpenTemplate, &QAction::triggered, this, &TMainWindow::OpenTemplate);
|
connect(ui->actionOpenTemplate, &QAction::triggered, this, &TMainWindow::OpenTemplate);
|
||||||
|
connect(ui->actionCreateFromExisting, &QAction::triggered, this, &TMainWindow::CreateFromExisting);
|
||||||
|
|
||||||
connect(ui->actionSave, &QAction::triggered, this, &TMainWindow::FileSave);
|
connect(ui->actionSave, &QAction::triggered, this, &TMainWindow::FileSave);
|
||||||
ui->actionSave->setShortcuts(QKeySequence::Save);
|
ui->actionSave->setShortcuts(QKeySequence::Save);
|
||||||
|
@ -2344,6 +2367,132 @@ void TMainWindow::UpdatePatternUnit()
|
||||||
ui->tableWidget->selectRow(row);
|
ui->tableWidget->selectRow(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VlpCreateLock(lock, QFileInfo(path).fileName()+".lock");
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void TMainWindow::SetDecimals()
|
void TMainWindow::SetDecimals()
|
||||||
{
|
{
|
||||||
|
|
|
@ -68,6 +68,7 @@ public slots:
|
||||||
void OpenIndividual();
|
void OpenIndividual();
|
||||||
void OpenStandard();
|
void OpenStandard();
|
||||||
void OpenTemplate();
|
void OpenTemplate();
|
||||||
|
void CreateFromExisting();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
|
virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
|
||||||
|
@ -178,6 +179,8 @@ private:
|
||||||
QStringList FilterMeasurements(const QStringList &mNew, const QStringList &mFilter);
|
QStringList FilterMeasurements(const QStringList &mNew, const QStringList &mFilter);
|
||||||
|
|
||||||
void UpdatePatternUnit();
|
void UpdatePatternUnit();
|
||||||
|
|
||||||
|
bool LoadFromExistingFile(const QString &path);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TMAINWINDOW_H
|
#endif // TMAINWINDOW_H
|
||||||
|
|
|
@ -724,6 +724,7 @@
|
||||||
<addaction name="actionOpenIndividual"/>
|
<addaction name="actionOpenIndividual"/>
|
||||||
<addaction name="actionOpenStandard"/>
|
<addaction name="actionOpenStandard"/>
|
||||||
<addaction name="actionOpenTemplate"/>
|
<addaction name="actionOpenTemplate"/>
|
||||||
|
<addaction name="actionCreateFromExisting"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="actionSave"/>
|
<addaction name="actionSave"/>
|
||||||
<addaction name="actionSaveAs"/>
|
<addaction name="actionSaveAs"/>
|
||||||
|
@ -958,6 +959,17 @@
|
||||||
<string>Import from a pattern</string>
|
<string>Import from a pattern</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionCreateFromExisting">
|
||||||
|
<property name="text">
|
||||||
|
<string>Create from existing ...</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Create from existing file</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string notr="true"/>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
<resources>
|
<resources>
|
||||||
|
|
|
@ -39,7 +39,7 @@ OBJECTS_DIR = obj
|
||||||
|
|
||||||
include(qmuparser.pri)
|
include(qmuparser.pri)
|
||||||
|
|
||||||
VERSION = 2.3.0
|
VERSION = 2.4.0
|
||||||
|
|
||||||
# Set "make install" command for Unix-like systems.
|
# Set "make install" command for Unix-like systems.
|
||||||
unix:!macx{
|
unix:!macx{
|
||||||
|
|
|
@ -73,10 +73,14 @@ QmuTokenParser::~QmuTokenParser()
|
||||||
* Work only with expressions in internal (C) locale.
|
* Work only with expressions in internal (C) locale.
|
||||||
* @param formula expression for test
|
* @param formula expression for test
|
||||||
* @return true if fomula has single number
|
* @return true if fomula has single number
|
||||||
* @throw qmu::QmuParserError if expression is incorrect. Has bad separator.
|
|
||||||
*/
|
*/
|
||||||
bool QmuTokenParser::IsSingle(const QString &formula)
|
bool QmuTokenParser::IsSingle(const QString &formula)
|
||||||
{
|
{
|
||||||
|
if (formula.isEmpty())
|
||||||
|
{
|
||||||
|
return false;// if don't know say no
|
||||||
|
}
|
||||||
|
|
||||||
QmuTokenParser *cal = new QmuTokenParser();
|
QmuTokenParser *cal = new QmuTokenParser();
|
||||||
|
|
||||||
// Parser doesn't know any variable on this stage. So, we just use variable factory that for each unknown
|
// Parser doesn't know any variable on this stage. So, we just use variable factory that for each unknown
|
||||||
|
@ -84,8 +88,16 @@ bool QmuTokenParser::IsSingle(const QString &formula)
|
||||||
cal->SetVarFactory(AddVariable, cal);
|
cal->SetVarFactory(AddVariable, cal);
|
||||||
cal->SetSepForEval();//Reset separators options
|
cal->SetSepForEval();//Reset separators options
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
cal->SetExpr(formula);
|
cal->SetExpr(formula);
|
||||||
cal->Eval();// We don't need save result, only parse formula
|
cal->Eval();// We don't need save result, only parse formula
|
||||||
|
}
|
||||||
|
catch (const qmu::QmuParserError &e)
|
||||||
|
{
|
||||||
|
Q_UNUSED(e)
|
||||||
|
return false;// something wrong with formula, say no
|
||||||
|
}
|
||||||
|
|
||||||
QMap<int, QString> tokens = cal->GetTokens();// Tokens (variables, measurements)
|
QMap<int, QString> tokens = cal->GetTokens();// Tokens (variables, measurements)
|
||||||
const QMap<int, QString> numbers = cal->GetNumbers();// All numbers in expression
|
const QMap<int, QString> numbers = cal->GetNumbers();// All numbers in expression
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include "../ifc/xml/vvitconverter.h"
|
#include "../ifc/xml/vvitconverter.h"
|
||||||
#include "../ifc/exception/vexceptionemptyparameter.h"
|
#include "../ifc/exception/vexceptionemptyparameter.h"
|
||||||
#include "../vpatterndb/calculator.h"
|
#include "../vpatterndb/calculator.h"
|
||||||
|
#include "../qmuparser/qmutokenparser.h"
|
||||||
|
|
||||||
const QString VMeasurements::TagVST = QStringLiteral("vst");
|
const QString VMeasurements::TagVST = QStringLiteral("vst");
|
||||||
const QString VMeasurements::TagVIT = QStringLiteral("vit");
|
const QString VMeasurements::TagVIT = QStringLiteral("vit");
|
||||||
|
@ -278,6 +279,24 @@ void VMeasurements::ReadMeasurements() const
|
||||||
delete tempData;
|
delete tempData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VMeasurements::ClearForExport()
|
||||||
|
{
|
||||||
|
const QDomNodeList list = elementsByTagName(TagMeasurement);
|
||||||
|
|
||||||
|
for (int i=0; i < list.size(); ++i)
|
||||||
|
{
|
||||||
|
QDomElement domElement = list.at(i).toElement();
|
||||||
|
if (domElement.isNull() == false)
|
||||||
|
{
|
||||||
|
if (qmu::QmuTokenParser::IsSingle(domElement.attribute(AttrValue)))
|
||||||
|
{
|
||||||
|
SetAttribute(domElement, AttrValue, QString("0"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
MeasurementsType VMeasurements::Type() const
|
MeasurementsType VMeasurements::Type() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -54,6 +54,7 @@ public:
|
||||||
void MoveBottom(const QString &name);
|
void MoveBottom(const QString &name);
|
||||||
|
|
||||||
void ReadMeasurements() const;
|
void ReadMeasurements() const;
|
||||||
|
void ClearForExport();
|
||||||
|
|
||||||
MeasurementsType Type() const;
|
MeasurementsType Type() const;
|
||||||
Unit MUnit() const;
|
Unit MUnit() const;
|
||||||
|
|
|
@ -49,6 +49,9 @@ void TST_QmuTokenParser::IsSingle_data()
|
||||||
QTest::newRow("Digit and variable") << "2+a" << false;
|
QTest::newRow("Digit and variable") << "2+a" << false;
|
||||||
QTest::newRow("One variable twice") << "a+a" << false;
|
QTest::newRow("One variable twice") << "a+a" << false;
|
||||||
QTest::newRow("Two variables") << "a+b" << false;
|
QTest::newRow("Two variables") << "a+b" << false;
|
||||||
|
QTest::newRow("Empty string") << "" << false;
|
||||||
|
QTest::newRow("Several spaces") << " " << false;
|
||||||
|
QTest::newRow("Invalid formula") << "2*)))" << false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue
Block a user