Little refactoring.

--HG--
branch : develop
This commit is contained in:
dismine 2014-02-10 18:10:20 +02:00
parent 01f4cc16c6
commit 33b0ac8b21
7 changed files with 216 additions and 213 deletions

View file

@ -50,7 +50,7 @@ DialogHistory::DialogHistory(VContainer *data, VDomDocument *doc, QWidget *paren
connect(ui->tableWidget, &QTableWidget::cellClicked, this, &DialogHistory::cellClicked); connect(ui->tableWidget, &QTableWidget::cellClicked, this, &DialogHistory::cellClicked);
connect(this, &DialogHistory::ShowHistoryTool, doc, &VDomDocument::ShowHistoryTool); connect(this, &DialogHistory::ShowHistoryTool, doc, &VDomDocument::ShowHistoryTool);
connect(doc, &VDomDocument::ChangedCursor, this, &DialogHistory::ChangedCursor); connect(doc, &VDomDocument::ChangedCursor, this, &DialogHistory::ChangedCursor);
connect(doc, &VDomDocument::haveChange, this, &DialogHistory::UpdateHistory); connect(doc, &VDomDocument::patternChanged, this, &DialogHistory::UpdateHistory);
connect(doc, &VDomDocument::ChangedActivDraw, this, &DialogHistory::UpdateHistory); connect(doc, &VDomDocument::ChangedActivDraw, this, &DialogHistory::UpdateHistory);
ShowPoint(); ShowPoint();
} }

View file

@ -69,8 +69,7 @@ int main(int argc, char *argv[])
VApplication app(argc, argv); VApplication app(argc, argv);
QTranslator qtTranslator; QTranslator qtTranslator;
qtTranslator.load("qt_" + QLocale::system().name(), qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
QLibraryInfo::location(QLibraryInfo::TranslationsPath));
app.installTranslator(&qtTranslator); app.installTranslator(&qtTranslator);
QTranslator appTranslator; QTranslator appTranslator;
@ -85,6 +84,11 @@ int main(int argc, char *argv[])
#endif #endif
app.installTranslator(&appTranslator); app.installTranslator(&appTranslator);
app.setApplicationDisplayName("Valentina");
app.setApplicationName("Valentina");
app.setOrganizationName("ValentinaTeam");
app.setOrganizationDomain("valentinaproject.bitbucket.org");
MainWindow w; MainWindow w;
w.setWindowState(w.windowState() ^ Qt::WindowMaximized); w.setWindowState(w.windowState() ^ Qt::WindowMaximized);
app.setWindowIcon(QIcon(":/icon/64x64/icon64x64.png")); app.setWindowIcon(QIcon(":/icon/64x64/icon64x64.png"));
@ -106,7 +110,7 @@ int main(int argc, char *argv[])
{ {
fileName = args.at(i+1); fileName = args.at(i+1);
qDebug() << args.at(i)<< ":" << fileName; qDebug() << args.at(i)<< ":" << fileName;
w.OpenPattern(fileName); w.LoadPattern(fileName);
} }
w.show(); w.show();
break; break;

View file

@ -78,8 +78,8 @@ private:
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
:QMainWindow(parent), ui(new Ui::MainWindow), pattern(0), doc(0), tool(Tool::ArrowTool), currentScene(0), :QMainWindow(parent), ui(new Ui::MainWindow), pattern(0), doc(0), tool(Tool::ArrowTool), currentScene(0),
sceneDraw(0), sceneDetails(0), mouseCoordinate(0), helpLabel(0), view(0), isInitialized(false), dialogTable(0), sceneDraw(0), sceneDetails(0), mouseCoordinate(0), helpLabel(0), view(0), isInitialized(false), dialogTable(0),
dialogTool(0), dialogHistory(0), comboBoxDraws(0), fileName(QString()), changeInFile(false), dialogTool(0), dialogHistory(0), comboBoxDraws(0), curFile(QString()), mode(Draw::Calculation),
mode(Draw::Calculation), currentDrawIndex(0), currentToolBoxIndex(0), drawMode(true) currentDrawIndex(0), currentToolBoxIndex(0), drawMode(true)
{ {
ui->setupUi(this); ui->setupUi(this);
static const char * GENERIC_ICON_TO_CHECK = "document-open"; static const char * GENERIC_ICON_TO_CHECK = "document-open";
@ -121,10 +121,10 @@ MainWindow::MainWindow(QWidget *parent)
connect(ui->actionDetails, &QAction::triggered, this, &MainWindow::ActionDetails); connect(ui->actionDetails, &QAction::triggered, this, &MainWindow::ActionDetails);
connect(ui->actionNewDraw, &QAction::triggered, this, &MainWindow::ActionNewDraw); connect(ui->actionNewDraw, &QAction::triggered, this, &MainWindow::ActionNewDraw);
connect(ui->actionOptionDraw, &QAction::triggered, this, &MainWindow::OptionDraw); connect(ui->actionOptionDraw, &QAction::triggered, this, &MainWindow::OptionDraw);
connect(ui->actionSaveAs, &QAction::triggered, this, &MainWindow::ActionSaveAs); connect(ui->actionSaveAs, &QAction::triggered, this, &MainWindow::SaveAs);
connect(ui->actionSave, &QAction::triggered, this, &MainWindow::ActionSave); connect(ui->actionSave, &QAction::triggered, this, &MainWindow::Save);
connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::ActionOpen); connect(ui->actionOpen, &QAction::triggered, this, &MainWindow::Open);
connect(ui->actionNew, &QAction::triggered, this, &MainWindow::ActionNew); connect(ui->actionNew, &QAction::triggered, this, &MainWindow::NewPattern);
connect(ui->actionTable, &QAction::triggered, this, &MainWindow::ActionTable); connect(ui->actionTable, &QAction::triggered, this, &MainWindow::ActionTable);
connect(ui->toolButtonEndLine, &QToolButton::clicked, this, &MainWindow::ToolEndLine); connect(ui->toolButtonEndLine, &QToolButton::clicked, this, &MainWindow::ToolEndLine);
connect(ui->toolButtonLine, &QToolButton::clicked, this, &MainWindow::ToolLine); connect(ui->toolButtonLine, &QToolButton::clicked, this, &MainWindow::ToolLine);
@ -150,7 +150,7 @@ MainWindow::MainWindow(QWidget *parent)
doc = new VDomDocument(pattern, comboBoxDraws, &mode); doc = new VDomDocument(pattern, comboBoxDraws, &mode);
doc->CreateEmptyFile(); doc->CreateEmptyFile();
connect(doc, &VDomDocument::haveChange, this, &MainWindow::haveChange); connect(doc, &VDomDocument::patternChanged, this, &MainWindow::PatternWasModified);
//Autosaving file each 5 minutes //Autosaving file each 5 minutes
QTimer *timer = new QTimer(this); QTimer *timer = new QTimer(this);
@ -163,6 +163,10 @@ MainWindow::MainWindow(QWidget *parent)
connect(ui->actionExit, &QAction::triggered, this, &MainWindow::close); connect(ui->actionExit, &QAction::triggered, this, &MainWindow::close);
ui->toolBox->setCurrentIndex(0); ui->toolBox->setCurrentIndex(0);
ReadSettings();
setCurrentFile("");
} }
void MainWindow::ActionNewDraw() void MainWindow::ActionNewDraw()
@ -220,7 +224,6 @@ void MainWindow::ActionNewDraw()
VDrawTool::AddRecord(id, Tool::SinglePointTool, doc); VDrawTool::AddRecord(id, Tool::SinglePointTool, doc);
SetEnableTool(true); SetEnableTool(true);
SetEnableWidgets(true); SetEnableWidgets(true);
changeInFile = true;
index = comboBoxDraws->findText(nameDraw); index = comboBoxDraws->findText(nameDraw);
if ( index != -1 ) if ( index != -1 )
@ -580,51 +583,14 @@ void MainWindow::showEvent( QShowEvent *event )
void MainWindow::closeEvent(QCloseEvent *event) void MainWindow::closeEvent(QCloseEvent *event)
{ {
if (changeInFile == true) if (MaybeSave())
{ {
QMessageBox msgBox(this); WriteSettings();
msgBox.setText(tr("The pattern has been modified.")); event->accept();
msgBox.setInformativeText(tr("Do you want to save your changes?")); }
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); else
msgBox.setDefaultButton(QMessageBox::Save); {
msgBox.setIcon(QMessageBox::Question); event->ignore();
int ret = msgBox.exec();
switch (ret)
{
case QMessageBox::Save:
// Save was clicked
if (fileName.isEmpty())
{
ActionSaveAs();
}
else
{
ActionSave();
}
if (changeInFile)
{
// We did't save file
event->ignore();
}
else
{
// We have successfully saved the file
event->accept();
}
break;
case QMessageBox::Discard:
// Don't Save was clicked
event->accept();
break;
case QMessageBox::Cancel:
// Cancel was clicked
event->ignore();
break;
default:
// should never be reached
event->accept();
break;
}
} }
} }
@ -950,113 +916,77 @@ void MainWindow::ActionDetails(bool checked)
} }
} }
void MainWindow::ActionSaveAs() bool MainWindow::SaveAs()
{ {
QString filters(tr("Pattern files (*.val)")); QString filters(tr("Pattern files (*.val)"));
QString dir = QDir::homePath() + tr("/pattern.val"); QString dir = QDir::homePath() + tr("/pattern.val");
QString fName = QFileDialog::getSaveFileName(this, tr("Save as"), dir, filters); QString fileName = QFileDialog::getSaveFileName(this, tr("Save as"), dir, filters);
if (fName.isEmpty()) if (fileName.isEmpty())
{ {
return; return false;
} }
QFileInfo f( fName ); QFileInfo f( fileName );
if (f.suffix().isEmpty() && f.suffix() != "val") if (f.suffix().isEmpty() && f.suffix() != "val")
{ {
fName += ".val"; fileName += ".val";
} }
fileName = fName; return SavePattern(fileName);
ActionSave();
} }
void MainWindow::ActionSave() bool MainWindow::Save()
{ {
if (fileName.isEmpty() == false) if (curFile.isEmpty())
{ {
bool result = SafeSaveing(fileName); return SaveAs();
if (result)
{
ui->actionSave->setEnabled(false);
changeInFile = false;
QFileInfo info(fileName);
QString title(info.fileName());
title.append("-Valentina");
setWindowTitle(title);
}
else
{
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error!"));
msgBox.setText(tr("Error saving file. Can't save file."));
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setIcon(QMessageBox::Warning);
msgBox.exec();
}
}
}
void MainWindow::ActionOpen()
{
QString filter(tr("Pattern files (*.val)"));
QString fName = QFileDialog::getOpenFileName(this, tr("Open file"), QDir::homePath(), filter);
if (fName.isEmpty())
{
return;
}
if (fileName.isEmpty() && changeInFile == false)
{
OpenPattern(fName);
VAbstractTool::NewSceneRect(sceneDraw, view);
VAbstractTool::NewSceneRect(sceneDetails, view);
} }
else else
{ {
/*Open new copy application*/ return SavePattern(curFile);
QProcess *v = new QProcess(this); }
QStringList arguments; }
arguments << "-o" << fName;
v->startDetached(QCoreApplication::applicationFilePath (), arguments); void MainWindow::Open()
delete v; {
if (MaybeSave())
{
QString filter(tr("Pattern files (*.val)"));
QString fileName = QFileDialog::getOpenFileName(this, tr("Open file"), QDir::homePath(), filter);
if (fileName.isEmpty() == false)
{
LoadPattern(fileName);
VAbstractTool::NewSceneRect(sceneDraw, view);
VAbstractTool::NewSceneRect(sceneDetails, view);
}
} }
} }
void MainWindow::Clear() void MainWindow::Clear()
{ {
setWindowTitle("Valentina"); setCurrentFile("");
fileName.clear();
pattern->Clear(); pattern->Clear();
doc->clear(); doc->clear();
sceneDraw->clear(); sceneDraw->clear();
sceneDetails->clear(); sceneDetails->clear();
CancelTool(); CancelTool();
comboBoxDraws->clear(); comboBoxDraws->clear();
fileName.clear();
ui->actionOptionDraw->setEnabled(false); ui->actionOptionDraw->setEnabled(false);
ui->actionSave->setEnabled(false); ui->actionSave->setEnabled(false);
SetEnableTool(false); SetEnableTool(false);
} }
void MainWindow::ActionNew() void MainWindow::NewPattern()
{ {
QProcess *v = new QProcess(this); QProcess *v = new QProcess(this);
v->startDetached(QCoreApplication::applicationFilePath ()); v->startDetached(QCoreApplication::applicationFilePath ());
delete v; delete v;
} }
void MainWindow::haveChange() void MainWindow::PatternWasModified()
{ {
if (fileName.isEmpty() == false) setWindowModified(doc->isPatternModified());
{ ui->actionSave->setEnabled(true);
ui->actionSave->setEnabled(true);
changeInFile = true;
QFileInfo info(fileName);
QString title(info.fileName());
title.append("*-Valentina");
setWindowTitle(title);
}
} }
void MainWindow::ChangedSize(const QString & text) void MainWindow::ChangedSize(const QString & text)
@ -1079,7 +1009,7 @@ void MainWindow::SetEnableWidgets(bool enable)
ui->actionDraw->setEnabled(enable); ui->actionDraw->setEnabled(enable);
ui->actionDetails->setEnabled(enable); ui->actionDetails->setEnabled(enable);
ui->actionOptionDraw->setEnabled(enable); ui->actionOptionDraw->setEnabled(enable);
if (enable == true && fileName.isEmpty() == false) if (enable == true && curFile.isEmpty() == false)
{ {
ui->actionSave->setEnabled(enable); ui->actionSave->setEnabled(enable);
} }
@ -1140,7 +1070,7 @@ void MainWindow::ActionLayout(bool checked)
QPainterPath path = VEquidistant().ContourPath(idetail.key(), pattern); QPainterPath path = VEquidistant().ContourPath(idetail.key(), pattern);
listDetails.append(new VItem(path, listDetails.size())); listDetails.append(new VItem(path, listDetails.size()));
} }
emit ModelChosen(listDetails, fileName); emit ModelChosen(listDetails, curFile);
} }
void MainWindow::ClosedActionHistory() void MainWindow::ClosedActionHistory()
@ -1196,27 +1126,18 @@ void MainWindow::MinimumScrollBar()
bool MainWindow::ValidatePattern(const QString &schema, const QString &fileName, QString &errorMsg, qint64 &errorLine, bool MainWindow::ValidatePattern(const QString &schema, const QString &fileName, QString &errorMsg, qint64 &errorLine,
qint64 &errorColumn) const qint64 &errorColumn) const
{ {
errorLine = -1;
errorColumn = -1;
QFile pattern(fileName); QFile pattern(fileName);
if (pattern.open(QIODevice::ReadOnly) == false) if (pattern.open(QIODevice::ReadOnly) == false)
{ {
errorMsg = QString(tr("Can't open pattern file.")); errorMsg = QString(tr("Can't open pattern file %1:\n%2.").arg(fileName).arg(pattern.errorString()));
errorLine = -1;
errorColumn = -1;
return false;
}
if (schema.isEmpty())
{
errorMsg = QString(tr("Empty schema path."));
errorLine = -1;
errorColumn = -1;
return false; return false;
} }
QFile fileSchema(schema); QFile fileSchema(schema);
if (fileSchema.open(QIODevice::ReadOnly) == false) if (fileSchema.open(QIODevice::ReadOnly) == false)
{ {
errorMsg = QString(tr("Can't open schema file.")); errorMsg = QString(tr("Can't open schema file %1:\n%2.").arg(schema).arg(fileSchema.errorString()));
errorLine = -1;
errorColumn = -1;
return false; return false;
} }
@ -1252,7 +1173,7 @@ bool MainWindow::ValidatePattern(const QString &schema, const QString &fileName,
} }
} }
bool MainWindow::SafeSaveing(const QString &fileName) const bool MainWindow::SavePattern(const QString &fileName)
{ {
try try
{ {
@ -1260,15 +1181,7 @@ bool MainWindow::SafeSaveing(const QString &fileName) const
} }
catch (const VExceptionUniqueId &e) catch (const VExceptionUniqueId &e)
{ {
QMessageBox msgBox; e.CriticalMessageBox(tr("Error no unique id."), this);
msgBox.setWindowTitle(tr("Error!"));
msgBox.setText(tr("Error no unique id."));
msgBox.setInformativeText(e.ErrorMessage());
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setDetailedText(e.DetailedInformation());
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
return false; return false;
} }
if (fileName.isEmpty()) if (fileName.isEmpty())
@ -1279,7 +1192,6 @@ bool MainWindow::SafeSaveing(const QString &fileName) const
//Writing in temporary file //Writing in temporary file
QFileInfo tempInfo(fileName); QFileInfo tempInfo(fileName);
QString temp = tempInfo.absolutePath() + "/" + tempInfo.baseName() + ".tmp"; QString temp = tempInfo.absolutePath() + "/" + tempInfo.baseName() + ".tmp";
qDebug()<<"file "<<fileName<<"temp file "<<temp;
QFile tempFile(temp); QFile tempFile(temp);
if (tempFile.open(QIODevice::WriteOnly| QIODevice::Truncate)) if (tempFile.open(QIODevice::WriteOnly| QIODevice::Truncate))
{ {
@ -1301,7 +1213,7 @@ bool MainWindow::SafeSaveing(const QString &fileName) const
{ {
if ( tempFile.copy(patternFile.fileName()) == false ) if ( tempFile.copy(patternFile.fileName()) == false )
{ {
qCritical()<<tr("Could not copy temp file to pattern file")<<Q_FUNC_INFO; qWarning()<<tr("Could not copy temp file to pattern file")<<Q_FUNC_INFO;
tempOfPattern.copy(fileName); tempOfPattern.copy(fileName);
result = false; result = false;
} }
@ -1312,33 +1224,82 @@ bool MainWindow::SafeSaveing(const QString &fileName) const
} }
else else
{ {
qCritical()<<tr("Could not remove pattern file")<<Q_FUNC_INFO; qWarning()<<tr("Could not remove pattern file")<<Q_FUNC_INFO;
result = false; result = false;
} }
if (result) if (result)
{ {
tempFile.remove(); tempFile.remove();
setCurrentFile(fileName);
helpLabel->setText(tr("File saved"));
ui->actionSave->setEnabled(false);
} }
return result; return result;
} }
void MainWindow::AutoSavePattern() void MainWindow::AutoSavePattern()
{ {
if (fileName.isEmpty() == false && changeInFile == true) if (curFile.isEmpty() == false && doc->isPatternModified() == true)
{ {
bool result = SafeSaveing(fileName); if (Save() == false)
if (result)
{ {
ui->actionSave->setEnabled(false); qWarning()<<tr("Can not save pattern")<<Q_FUNC_INFO;
changeInFile = false;
QFileInfo info(fileName);
QString title(info.fileName());
title.append("-Valentina");
setWindowTitle(title);
} }
} }
} }
void MainWindow::setCurrentFile(const QString &fileName)
{
curFile = fileName;
doc->setPatternModified(false);
setWindowModified(false);
QString shownName = strippedName(curFile);
if (curFile.isEmpty())
{
shownName = tr("untitled.val");
}
shownName+="[*]";
setWindowTitle(shownName);
}
QString MainWindow::strippedName(const QString &fullFileName)
{
return QFileInfo(fullFileName).fileName();
}
void MainWindow::ReadSettings()
{
QSettings settings(QSettings::IniFormat, QSettings::UserScope, "ValentinaTeam", "Valentina");
QPoint pos = settings.value("pos", QPoint(10, 10)).toPoint();
QSize size = settings.value("size", QSize(1000, 800)).toSize();
resize(size);
move(pos);
}
void MainWindow::WriteSettings()
{
QSettings settings(QSettings::IniFormat, QSettings::UserScope, "ValentinaTeam", "Valentina");
settings.setValue("pos", pos());
settings.setValue("size", size());
}
bool MainWindow::MaybeSave()
{
if (doc->isPatternModified())
{
QMessageBox::StandardButton ret;
ret = QMessageBox::warning(this, tr("Unsaved change"), tr("The pattern has been modified.\n"
"Do you want to save your changes?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
if (ret == QMessageBox::Save)
return Save();
else if (ret == QMessageBox::Cancel)
return false;
}
return true;
}
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
CancelTool(); CancelTool();
@ -1350,13 +1311,8 @@ MainWindow::~MainWindow()
delete sceneDraw; delete sceneDraw;
} }
void MainWindow::OpenPattern(const QString &fileName) void MainWindow::LoadPattern(const QString &fileName)
{ {
if (fileName.isEmpty())
{
qWarning()<<tr("Can't open pattern file. File name is empty")<<Q_FUNC_INFO;
return;
}
QFile file(fileName); QFile file(fileName);
QString errorMsg; QString errorMsg;
qint64 errorLine = 0; qint64 errorLine = 0;
@ -1373,7 +1329,13 @@ void MainWindow::OpenPattern(const QString &fileName)
this, &MainWindow::currentDrawChanged); this, &MainWindow::currentDrawChanged);
try try
{ {
#ifndef QT_NO_CURSOR
QApplication::setOverrideCursor(Qt::WaitCursor);
#endif
doc->Parse(Document::FullParse, sceneDraw, sceneDetails); doc->Parse(Document::FullParse, sceneDraw, sceneDetails);
#ifndef QT_NO_CURSOR
QApplication::restoreOverrideCursor();
#endif
} }
catch (const VExceptionObjectError &e) catch (const VExceptionObjectError &e)
{ {
@ -1463,12 +1425,10 @@ void MainWindow::OpenPattern(const QString &fileName)
} }
else else
{ {
qWarning()<<tr("Can't open pattern file.")<<Q_FUNC_INFO; QMessageBox::warning(this, tr("Valentina"), tr("Cannot read file %1:\n%2.")
.arg(fileName)
.arg(file.errorString()));
} }
this->fileName = fileName; setCurrentFile(fileName);
QFileInfo info(fileName); helpLabel->setText(tr("File loaded"));
QString title(info.fileName());
title.append("-Valentina");
setWindowTitle(title);
helpLabel->setText("");
} }

View file

@ -58,10 +58,10 @@ public:
explicit MainWindow(QWidget *parent = 0); explicit MainWindow(QWidget *parent = 0);
~MainWindow(); ~MainWindow();
/** /**
* @brief OpenPattern open pattern file. * @brief LoadPattern open pattern file.
* @param fileName name of file. * @param fileName name of file.
*/ */
void OpenPattern(const QString &fileName); void LoadPattern(const QString &curFile);
public slots: public slots:
/** /**
* @brief mouseMove save mouse position and show user. * @brief mouseMove save mouse position and show user.
@ -87,21 +87,23 @@ public slots:
*/ */
void ActionNewDraw(); void ActionNewDraw();
/** /**
* @brief ActionSaveAs save as pattern file. * @brief SaveAs save as pattern file.
* @return true for successes saving.
*/ */
void ActionSaveAs(); bool SaveAs();
/** /**
* @brief ActionSave save pattern file. * @brief Save save pattern file.
* @return true for successes saving.
*/ */
void ActionSave(); bool Save();
/** /**
* @brief ActionOpen ask user select pattern file. * @brief Open ask user select pattern file.
*/ */
void ActionOpen(); void Open();
/** /**
* @brief ActionNew create new empty pattern. * @brief NewPattern create new empty pattern.
*/ */
void ActionNew(); void NewPattern();
/** /**
* @brief ActionTable show table with variables. * @brief ActionTable show table with variables.
* @param checked true - button checked. * @param checked true - button checked.
@ -129,7 +131,7 @@ public slots:
/** /**
* @brief haveChange enable action save if we have unsaved change. * @brief haveChange enable action save if we have unsaved change.
*/ */
void haveChange(); void PatternWasModified();
/** /**
* @brief ChangedSize change new size value. * @brief ChangedSize change new size value.
* @param text value size. * @param text value size.
@ -360,7 +362,7 @@ signals:
* @brief ModelChosen emit after calculation all details. * @brief ModelChosen emit after calculation all details.
* @param listDetails list of details. * @param listDetails list of details.
*/ */
void ModelChosen(QVector<VItem*> listDetails, const QString &fileName); void ModelChosen(QVector<VItem*> listDetails, const QString &curFile);
protected: protected:
/** /**
* @brief keyPressEvent handle key press events. * @brief keyPressEvent handle key press events.
@ -437,11 +439,7 @@ private:
/** /**
* @brief fileName name current pattern file. * @brief fileName name current pattern file.
*/ */
QString fileName; QString curFile;
/**
* @brief changeInFile true if exist change in file.
*/
bool changeInFile;
/** /**
* @brief mode keep current draw mode. * @brief mode keep current draw mode.
*/ */
@ -516,7 +514,7 @@ private:
* @param errorColumn number error column. * @param errorColumn number error column.
* @return true if validation successful. * @return true if validation successful.
*/ */
bool ValidatePattern(const QString &schema, const QString &fileName, QString &errorMsg, qint64 &errorLine, bool ValidatePattern(const QString &schema, const QString &curFile, QString &errorMsg, qint64 &errorLine,
qint64 &errorColumn) const; qint64 &errorColumn) const;
template <typename DrawTool> template <typename DrawTool>
/** /**
@ -525,15 +523,40 @@ private:
*/ */
void ClosedDialog(int result); void ClosedDialog(int result);
/** /**
* @brief SafeSaveing safe saving pattern file. * @brief SavePattern save pattern file.
* @param fileName pattern file name. * @param fileName pattern file name.
* @return true if all is all right. * @return true if all is good.
*/ */
bool SafeSaveing(const QString &fileName)const; bool SavePattern(const QString &curFile);
/** /**
* @brief AutoSavePattern start safe saving. * @brief AutoSavePattern start safe saving.
*/ */
void AutoSavePattern(); void AutoSavePattern();
/**
* @brief setCurrentFile the function is called to reset the state of a few variables when a file
* is loaded or saved, or when the user starts editing a new file (in which case fileName is empty).
* @param fileName file name.
*/
void setCurrentFile(const QString &fileName);
/**
* @brief strippedName the function call around curFile to exclude the path to the file.
* @param fullFileName full path to the file.
* @return file name.
*/
QString strippedName(const QString &fullFileName);
/**
* @brief ReadSettings read setting for app.
*/
void ReadSettings();
/**
* @brief WriteSettings save setting for app.
*/
void WriteSettings();
/**
* @brief MaybeSave The function is called to save pending changes.
* @return returns true in all cases, except when the user clicks Cancel.
*/
bool MaybeSave();
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View file

@ -47,8 +47,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>150</width> <width>144</width>
<height>144</height> <height>150</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -302,8 +302,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>150</width> <width>100</width>
<height>56</height> <height>58</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -378,8 +378,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>150</width> <width>100</width>
<height>100</height> <height>104</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -507,7 +507,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>150</width> <width>150</width>
<height>56</height> <height>58</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -579,8 +579,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>150</width> <width>100</width>
<height>56</height> <height>58</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -664,7 +664,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1100</width> <width>1100</width>
<height>21</height> <height>25</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuFile"> <widget class="QMenu" name="menuFile">
@ -709,7 +709,6 @@
<addaction name="actionNew"/> <addaction name="actionNew"/>
<addaction name="actionOpen"/> <addaction name="actionOpen"/>
<addaction name="actionSave"/> <addaction name="actionSave"/>
<addaction name="actionSaveAs"/>
</widget> </widget>
<widget class="QStatusBar" name="statusBar"/> <widget class="QStatusBar" name="statusBar"/>
<widget class="QToolBar" name="toolBar"> <widget class="QToolBar" name="toolBar">

View file

@ -43,19 +43,19 @@
VDomDocument::VDomDocument(VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode, QObject *parent) VDomDocument::VDomDocument(VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode, QObject *parent)
: QObject(parent), QDomDocument(), map(QHash<QString, QDomElement>()), nameActivDraw(QString()), data(data), : QObject(parent), QDomDocument(), map(QHash<QString, QDomElement>()), nameActivDraw(QString()), data(data),
tools(QHash<qint64, VDataTool*>()), history(QVector<VToolRecord>()), cursor(0), tools(QHash<qint64, VDataTool*>()), history(QVector<VToolRecord>()), cursor(0),
comboBoxDraws(comboBoxDraws), mode(mode){} comboBoxDraws(comboBoxDraws), mode(mode), patternModified(false){}
VDomDocument::VDomDocument(const QString& name, VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode, VDomDocument::VDomDocument(const QString& name, VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode,
QObject *parent) QObject *parent)
:QObject(parent), QDomDocument(name), map(QHash<QString, QDomElement>()), nameActivDraw(QString()), data(data), :QObject(parent), QDomDocument(name), map(QHash<QString, QDomElement>()), nameActivDraw(QString()), data(data),
tools(QHash<qint64, VDataTool*>()), history(QVector<VToolRecord>()), cursor(0), tools(QHash<qint64, VDataTool*>()), history(QVector<VToolRecord>()), cursor(0),
comboBoxDraws(comboBoxDraws), mode(mode){} comboBoxDraws(comboBoxDraws), mode(mode), patternModified(false){}
VDomDocument::VDomDocument(const QDomDocumentType& doctype, VContainer *data, QComboBox *comboBoxDraws, VDomDocument::VDomDocument(const QDomDocumentType& doctype, VContainer *data, QComboBox *comboBoxDraws,
Draw::Draws *mode, QObject *parent) Draw::Draws *mode, QObject *parent)
:QObject(parent), QDomDocument(doctype), map(QHash<QString, QDomElement>()), nameActivDraw(QString()), data(data), :QObject(parent), QDomDocument(doctype), map(QHash<QString, QDomElement>()), nameActivDraw(QString()), data(data),
tools(QHash<qint64, VDataTool*>()), history(QVector<VToolRecord>()), cursor(0), tools(QHash<qint64, VDataTool*>()), history(QVector<VToolRecord>()), cursor(0),
comboBoxDraws(comboBoxDraws), mode(mode){} comboBoxDraws(comboBoxDraws), mode(mode), patternModified(false){}
QDomElement VDomDocument::elementById(const QString& id) QDomElement VDomDocument::elementById(const QString& id)
{ {
@ -223,7 +223,7 @@ bool VDomDocument::SetNameDraw(const QString& name)
{ {
nameActivDraw = name; nameActivDraw = name;
element.setAttribute("name", nameActivDraw); element.setAttribute("name", nameActivDraw);
emit haveChange(); emit patternChanged();
emit ChangedNameDraw(oldName, nameActivDraw); emit ChangedNameDraw(oldName, nameActivDraw);
return true; return true;
} }
@ -1346,13 +1346,24 @@ void VDomDocument::FullUpdateTree()
void VDomDocument::haveLiteChange() void VDomDocument::haveLiteChange()
{ {
emit haveChange(); patternModified = true;
emit patternChanged();
} }
void VDomDocument::ShowHistoryTool(qint64 id, Qt::GlobalColor color, bool enable) void VDomDocument::ShowHistoryTool(qint64 id, Qt::GlobalColor color, bool enable)
{ {
emit ShowTool(id, color, enable); emit ShowTool(id, color, enable);
} }
bool VDomDocument::isPatternModified() const
{
return patternModified;
}
void VDomDocument::setPatternModified(bool value)
{
patternModified = value;
}
void VDomDocument::setCursor(const qint64 &value) void VDomDocument::setCursor(const qint64 &value)
{ {

View file

@ -239,6 +239,8 @@ public:
* @return id base point. * @return id base point.
*/ */
qint64 SPointActiveDraw(); qint64 SPointActiveDraw();
bool isPatternModified() const;
void setPatternModified(bool value);
signals: signals:
/** /**
* @brief ChangedActivDraw change active pattern peace. * @brief ChangedActivDraw change active pattern peace.
@ -256,9 +258,9 @@ signals:
*/ */
void FullUpdateFromFile(); void FullUpdateFromFile();
/** /**
* @brief haveChange emit if we have unsaved change. * @brief patternChanged emit if we have unsaved change.
*/ */
void haveChange(); void patternChanged();
/** /**
* @brief ShowTool highlight tool. * @brief ShowTool highlight tool.
* @param id tool id. * @param id tool id.
@ -321,6 +323,10 @@ private:
* @brief mode current draw mode. * @brief mode current draw mode.
*/ */
Draw::Draws *mode; Draw::Draws *mode;
/**
* @brief fileModified true if exist change in file.
*/
bool patternModified;
/** /**
* @brief find find element by id. * @brief find find element by id.
* @param node node. * @param node node.