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 <QUndoStack>
#include <QAction>
#include <QProcess>
#include <QSettings>
//---------------------------------------------------------------------------------------------------------------------
/**
@ -61,8 +63,8 @@ MainWindow::MainWindow(QWidget *parent)
currentScene(nullptr), sceneDraw(nullptr), sceneDetails(nullptr), mouseCoordinate(nullptr), helpLabel(nullptr),
view(nullptr), isInitialized(false), dialogTable(0), dialogTool(nullptr), dialogHistory(nullptr),
comboBoxDraws(nullptr), curFile(QString()), mode(Draw::Calculation), currentDrawIndex(0),
currentToolBoxIndex(0), drawMode(true), recentFileActs{0, 0, 0, 0, 0}, separatorAct(nullptr),
autoSaveTimer(nullptr), guiEnabled(true)
currentToolBoxIndex(0), drawMode(true), recentFileActs{nullptr, nullptr, nullptr, nullptr, nullptr},
separatorAct(nullptr), autoSaveTimer(nullptr), guiEnabled(true)
{
CreateActions();
CreateMenus();
@ -912,7 +914,7 @@ void MainWindow::OpenRecentFile()
QAction *action = qobject_cast<QAction *>(sender());
if (action)
{
LoadPattern(action->data().toString());
OpenPattern(action->data().toString());
}
}
@ -1464,43 +1466,24 @@ bool MainWindow::Save()
*/
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);
VAbstractTool::NewSceneRect(sceneDetails, view);
}
else
{
QProcess *v = new QProcess(this);
QStringList arguments;
arguments << fileName;
v->startDetached(QCoreApplication::applicationFilePath(), arguments);
delete v;
}
}
const QString filter(tr("Pattern files (*.val)"));
//Get list last open files
QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::organizationName(),
QApplication::applicationName());
const 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();
}
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;
}
//---------------------------------------------------------------------------------------------------------------------
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 Preferences();
void NewPattern();
void ShowToolTip(const QString &toolTip);
void OpenRecentFile();
void Clear();
void currentDrawChanged( int index );
void OptionDraw();
@ -134,9 +137,6 @@ public slots:
void AboutQt();
void PatternProperties();
void ShowToolTip(const QString &toolTip);
void OpenRecentFile();
void Clear();
/**
* @brief Edit XML code of pattern
*/
@ -254,6 +254,7 @@ private:
void InitAutoSave();
QString PatternPieceName(const QString &text);
QString CheckPathToMeasurements(const QString &path, const MeasurementsType &patternType);
void OpenPattern(const QString &filePath);
};
#endif // MAINWINDOW_H

View File

@ -37,6 +37,7 @@
#include <QDebug>
#include <QDir>
#include <QProcess>
#include <QSettings>
#include <QUndoStack>
@ -68,6 +69,20 @@ VApplication::VApplication(int &argc, char **argv)
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().

View File

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