Fix opening patterns.

--HG--
branch : develop
This commit is contained in:
dismine 2014-07-04 17:52:11 +03:00
parent 7d34444398
commit c9e2c32dae
4 changed files with 60 additions and 41 deletions

View File

@ -50,6 +50,8 @@
#include <QSourceLocation> #include <QSourceLocation>
#include <QUndoStack> #include <QUndoStack>
#include <QAction> #include <QAction>
#include <QProcess>
#include <QSettings>
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
@ -61,8 +63,8 @@ MainWindow::MainWindow(QWidget *parent)
currentScene(nullptr), sceneDraw(nullptr), sceneDetails(nullptr), mouseCoordinate(nullptr), helpLabel(nullptr), currentScene(nullptr), sceneDraw(nullptr), sceneDetails(nullptr), mouseCoordinate(nullptr), helpLabel(nullptr),
view(nullptr), isInitialized(false), dialogTable(0), dialogTool(nullptr), dialogHistory(nullptr), view(nullptr), isInitialized(false), dialogTable(0), dialogTool(nullptr), dialogHistory(nullptr),
comboBoxDraws(nullptr), curFile(QString()), mode(Draw::Calculation), currentDrawIndex(0), comboBoxDraws(nullptr), curFile(QString()), mode(Draw::Calculation), currentDrawIndex(0),
currentToolBoxIndex(0), drawMode(true), recentFileActs{0, 0, 0, 0, 0}, separatorAct(nullptr), currentToolBoxIndex(0), drawMode(true), recentFileActs{nullptr, nullptr, nullptr, nullptr, nullptr},
autoSaveTimer(nullptr), guiEnabled(true) separatorAct(nullptr), autoSaveTimer(nullptr), guiEnabled(true)
{ {
CreateActions(); CreateActions();
CreateMenus(); CreateMenus();
@ -912,7 +914,7 @@ void MainWindow::OpenRecentFile()
QAction *action = qobject_cast<QAction *>(sender()); QAction *action = qobject_cast<QAction *>(sender());
if (action) if (action)
{ {
LoadPattern(action->data().toString()); OpenPattern(action->data().toString());
} }
} }
@ -1464,43 +1466,24 @@ bool MainWindow::Save()
*/ */
void MainWindow::Open() void MainWindow::Open()
{ {
if (MaybeSave())
{
QString filter(tr("Pattern files (*.val)"));
//Get list last open files
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
QStringList files = settings.value("recentFileList").toStringList();
QString dir;
if (files.isEmpty())
{
dir = QDir::homePath();
}
else
{
//Absolute path to last open file
dir = QFileInfo(files.first()).absolutePath();
}
QString fileName = QFileDialog::getOpenFileName(this, tr("Open file"), dir, filter);
if (fileName.isEmpty() == false && fileName != curFile)
{
if (curFile.isEmpty())
{
LoadPattern(fileName);
VAbstractTool::NewSceneRect(sceneDraw, view); const QString filter(tr("Pattern files (*.val)"));
VAbstractTool::NewSceneRect(sceneDetails, view); //Get list last open files
} QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
else QApplication::applicationName());
{ const QStringList files = settings.value("recentFileList").toStringList();
QProcess *v = new QProcess(this); QString dir;
QStringList arguments; if (files.isEmpty())
arguments << fileName; {
v->startDetached(QCoreApplication::applicationFilePath(), arguments); dir = QDir::homePath();
delete v;
}
}
} }
else
{
//Absolute path to last open file
dir = QFileInfo(files.first()).absolutePath();
}
const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), dir, filter);
OpenPattern(filePath);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -2326,3 +2309,22 @@ QString MainWindow::CheckPathToMeasurements(const QString &path, const Measureme
} }
return path; return path;
} }
//---------------------------------------------------------------------------------------------------------------------
void MainWindow::OpenPattern(const QString &filePath)
{
if (filePath.isEmpty() == false && filePath != curFile)
{
if (curFile.isEmpty() && this->isWindowModified() == false)
{
LoadPattern(filePath);
VAbstractTool::NewSceneRect(sceneDraw, view);
VAbstractTool::NewSceneRect(sceneDetails, view);
}
else
{
VApplication::NewValentina(filePath);
}
}
}

View File

@ -74,6 +74,9 @@ public slots:
void Open(); void Open();
void Preferences(); void Preferences();
void NewPattern(); void NewPattern();
void ShowToolTip(const QString &toolTip);
void OpenRecentFile();
void Clear();
void currentDrawChanged( int index ); void currentDrawChanged( int index );
void OptionDraw(); void OptionDraw();
@ -134,9 +137,6 @@ public slots:
void AboutQt(); void AboutQt();
void PatternProperties(); void PatternProperties();
void ShowToolTip(const QString &toolTip);
void OpenRecentFile();
void Clear();
/** /**
* @brief Edit XML code of pattern * @brief Edit XML code of pattern
*/ */
@ -254,6 +254,7 @@ private:
void InitAutoSave(); void InitAutoSave();
QString PatternPieceName(const QString &text); QString PatternPieceName(const QString &text);
QString CheckPathToMeasurements(const QString &path, const MeasurementsType &patternType); QString CheckPathToMeasurements(const QString &path, const MeasurementsType &patternType);
void OpenPattern(const QString &filePath);
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View File

@ -37,6 +37,7 @@
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
#include <QProcess>
#include <QSettings> #include <QSettings>
#include <QUndoStack> #include <QUndoStack>
@ -68,6 +69,20 @@ VApplication::VApplication(int &argc, char **argv)
InitPostfixOperators(); InitPostfixOperators();
} }
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief NewValentina start Valentina in new process, send path to pattern file in argument.
* @param fileName path to pattern file.
*/
void VApplication::NewValentina(const QString &fileName)
{
QProcess *v = new QProcess();
QStringList arguments;
arguments << fileName;
v->startDetached(QCoreApplication::applicationFilePath(), arguments);
delete v;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief notify Reimplemented from QApplication::notify(). * @brief notify Reimplemented from QApplication::notify().

View File

@ -51,6 +51,7 @@ class VApplication : public QApplication
public: public:
VApplication(int &argc, char ** argv); VApplication(int &argc, char ** argv);
virtual ~VApplication() {} virtual ~VApplication() {}
static void NewValentina(const QString &fileName);
virtual bool notify(QObject * receiver, QEvent * event); virtual bool notify(QObject * receiver, QEvent * event);
Unit patternUnit() const; Unit patternUnit() const;
void setPatternUnit(const Unit &patternUnit); void setPatternUnit(const Unit &patternUnit);