From 9f6bd02736b36ee7ad5940211213401b855305ba Mon Sep 17 00:00:00 2001 From: dismine Date: Mon, 23 Sep 2013 16:17:15 +0300 Subject: [PATCH] Change in function open and new. Open try open file and if he lose will show error message. After that clear area. Open will open new window. --- exception/vexceptionemptyparameter.cpp | 6 +- main.cpp | 26 ++- mainwindow.cpp | 221 ++++++++++++++----------- mainwindow.h | 2 + 4 files changed, 154 insertions(+), 101 deletions(-) diff --git a/exception/vexceptionemptyparameter.cpp b/exception/vexceptionemptyparameter.cpp index 480084f77..72c645724 100644 --- a/exception/vexceptionemptyparameter.cpp +++ b/exception/vexceptionemptyparameter.cpp @@ -23,8 +23,8 @@ #include VExceptionEmptyParameter::VExceptionEmptyParameter(const QString &what, const QString &name, - const QDomElement &domElement): VException(what), name(name), - tagText(QString()), tagName(QString()), lineNumber(-1){ + const QDomElement &domElement): VException(what), + name(name), tagText(QString()), tagName(QString()), lineNumber(-1){ Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null"); Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "Parameter name is empty"); if(domElement.isText()){ @@ -36,7 +36,7 @@ VExceptionEmptyParameter::VExceptionEmptyParameter(const QString &what, const QS } VExceptionEmptyParameter::VExceptionEmptyParameter(const VExceptionEmptyParameter &e):VException(e), - name(e.Name()), tagName(e.TagName()), tagText(e.TagText()), lineNumber(e.LineNumber()){ + name(e.Name()), tagText(e.TagText()), tagName(e.TagName()), lineNumber(e.LineNumber()){ } QString VExceptionEmptyParameter::ErrorMessage() const{ diff --git a/main.cpp b/main.cpp index 0490fd252..5561ab56e 100644 --- a/main.cpp +++ b/main.cpp @@ -64,7 +64,29 @@ int main(int argc, char *argv[]){ TableWindow table; QObject::connect(&w, &MainWindow::ModelChosen, &table, &TableWindow::ModelChosen); QObject::connect(&table, &TableWindow::closed, &w, &MainWindow::tableClosed); - w.show(); - + + const QStringList args = app.arguments(); + QString fileName; + QRegExp rxArgOpenFile("-o");//parameter open file + + if(args.size()>1){ + for (int i = 1; i < args.size(); ++i) { + if (rxArgOpenFile.indexIn(args.at(i)) != -1 ) { + if(args.at(i+1).isEmpty() == false){ + fileName = args.at(i+1); + qDebug() << args.at(i)<< ":" << fileName; + w.OpenPattern(fileName); + } + w.show(); + break; + } else { + qDebug() << "Uknown arg:" << args.at(i); + w.show(); + break; + } + } + } else { + w.show(); + } return app.exec(); } diff --git a/mainwindow.cpp b/mainwindow.cpp index 30fede2e8..a4e762d45 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -737,104 +737,19 @@ void MainWindow::ActionOpen(){ QString fName = QFileDialog::getOpenFileName(this, tr("Open file"), QDir::homePath(), filter); if(fName.isEmpty()) return; - QFile file(fName); - QString errorMsg; - qint32 errorLine = 0; - qint32 errorColumn = 0; - if(file.open(QIODevice::ReadOnly)){ - if(doc->setContent(&file, &errorMsg, &errorLine, &errorColumn)){ - disconnect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), - this, &MainWindow::currentDrawChanged); - try{ - doc->Parse(Document::FullParse, sceneDraw, sceneDetails); - } - catch(const VExceptionObjectError &e){ - QMessageBox msgBox; - msgBox.setWindowTitle(tr("Error!")); - msgBox.setText(tr("Error parsing file.")); - msgBox.setInformativeText(e.ErrorMessage()); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.setDetailedText(e.DetailedInformation()); - msgBox.setIcon(QMessageBox::Critical); - msgBox.exec(); - file.close(); - return; - } - catch(const VExceptionConversionError &e){ - QMessageBox msgBox; - msgBox.setWindowTitle(tr("Error!")); - msgBox.setText(tr("Error can't convert value.")); - msgBox.setInformativeText(e.ErrorMessage()); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.setIcon(QMessageBox::Critical); - msgBox.exec(); - file.close(); - return; - } - catch(const VExceptionEmptyParameter &e){ - QMessageBox msgBox; - msgBox.setWindowTitle(tr("Error!")); - msgBox.setText(tr("Error empty parameter.")); - msgBox.setInformativeText(e.ErrorMessage()); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.setDetailedText(e.DetailedInformation()); - msgBox.setIcon(QMessageBox::Critical); - msgBox.exec(); - file.close(); - return; - } - catch(const VExceptionWrongParameterId &e){ - QMessageBox msgBox; - msgBox.setWindowTitle(tr("Error!")); - msgBox.setText(tr("Error wrong id.")); - msgBox.setInformativeText(e.ErrorMessage()); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.setDetailedText(e.DetailedInformation()); - msgBox.setIcon(QMessageBox::Critical); - msgBox.exec(); - file.close(); - return; - } - connect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), - this, &MainWindow::currentDrawChanged); - QString nameDraw = doc->GetNameActivDraw(); - qint32 index = comboBoxDraws->findText(nameDraw); - if ( index != -1 ) { // -1 for not found - comboBoxDraws->setCurrentIndex(index); - } - if(comboBoxDraws->count() > 0){ - SetEnableTool(true); - } else { - SetEnableTool(false); - } - SetEnableWidgets(true); - } else { - QMessageBox msgBox; - msgBox.setWindowTitle(tr("Error!")); - msgBox.setText(tr("Error parsing pattern file.")); - msgBox.setInformativeText(errorMsg); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - QString error = QString(tr("Error in line %1 column %2")).arg(errorLine, errorColumn); - msgBox.setDetailedText(error); - msgBox.exec(); - file.close(); - return; - } - file.close(); + if(fileName.isEmpty() && changeInFile == false){ + OpenPattern(fName); + } else { + /*Open new copy application*/ + QProcess *v = new QProcess(this); + QStringList arguments; + arguments << "-o" << fName; + v->startDetached(QCoreApplication::applicationFilePath (), arguments); + delete v; } - fileName = fName; - QFileInfo info(fileName); - QString title(info.fileName()); - title.append("-Valentina"); - setWindowTitle(title); } -void MainWindow::ActionNew(){ +void MainWindow::Clear(){ setWindowTitle("Valentina"); fileName.clear(); data->Clear(); @@ -849,9 +764,16 @@ void MainWindow::ActionNew(){ SetEnableTool(false); } +void MainWindow::ActionNew(){ + QProcess *v = new QProcess(this); + v->startDetached(QCoreApplication::applicationFilePath ()); + delete v; +} + void MainWindow::haveChange(){ if(!fileName.isEmpty()){ ui->actionSave->setEnabled(true); + changeInFile = true; } } @@ -959,5 +881,112 @@ MainWindow::~MainWindow(){ delete data; if(!doc->isNull()){ delete doc; - } + } +} + +void MainWindow::OpenPattern(const QString &fileName){ + if(fileName.isEmpty()){ + qWarning()<setContent(&file, &errorMsg, &errorLine, &errorColumn)){ + disconnect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), + this, &MainWindow::currentDrawChanged); + try{ + doc->Parse(Document::FullParse, sceneDraw, sceneDetails); + } + catch(const VExceptionObjectError &e){ + QMessageBox msgBox; + msgBox.setWindowTitle(tr("Error!")); + msgBox.setText(tr("Error parsing file.")); + msgBox.setInformativeText(e.ErrorMessage()); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setDefaultButton(QMessageBox::Ok); + msgBox.setDetailedText(e.DetailedInformation()); + msgBox.setIcon(QMessageBox::Critical); + msgBox.exec(); + file.close(); + Clear(); + return; + } + catch(const VExceptionConversionError &e){ + QMessageBox msgBox; + msgBox.setWindowTitle(tr("Error!")); + msgBox.setText(tr("Error can't convert value.")); + msgBox.setInformativeText(e.ErrorMessage()); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setDefaultButton(QMessageBox::Ok); + msgBox.setIcon(QMessageBox::Critical); + msgBox.exec(); + file.close(); + Clear(); + return; + } + catch(const VExceptionEmptyParameter &e){ + QMessageBox msgBox; + msgBox.setWindowTitle(tr("Error!")); + msgBox.setText(tr("Error empty parameter.")); + msgBox.setInformativeText(e.ErrorMessage()); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setDefaultButton(QMessageBox::Ok); + msgBox.setDetailedText(e.DetailedInformation()); + msgBox.setIcon(QMessageBox::Critical); + msgBox.exec(); + file.close(); + Clear(); + return; + } + catch(const VExceptionWrongParameterId &e){ + QMessageBox msgBox; + msgBox.setWindowTitle(tr("Error!")); + msgBox.setText(tr("Error wrong id.")); + msgBox.setInformativeText(e.ErrorMessage()); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setDefaultButton(QMessageBox::Ok); + msgBox.setDetailedText(e.DetailedInformation()); + msgBox.setIcon(QMessageBox::Critical); + msgBox.exec(); + file.close(); + Clear(); + return; + } + connect(comboBoxDraws, static_cast(&QComboBox::currentIndexChanged), + this, &MainWindow::currentDrawChanged); + QString nameDraw = doc->GetNameActivDraw(); + qint32 index = comboBoxDraws->findText(nameDraw); + if ( index != -1 ) { // -1 for not found + comboBoxDraws->setCurrentIndex(index); + } + if(comboBoxDraws->count() > 0){ + SetEnableTool(true); + } else { + SetEnableTool(false); + } + SetEnableWidgets(true); + } else { + QMessageBox msgBox; + msgBox.setWindowTitle(tr("Error!")); + msgBox.setText(tr("Error parsing pattern file.")); + msgBox.setInformativeText(errorMsg); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setDefaultButton(QMessageBox::Ok); + QString error = QString(tr("Error in line %1 column %2")).arg(errorLine, errorColumn); + msgBox.setDetailedText(error); + msgBox.exec(); + file.close(); + Clear(); + return; + } + file.close(); + } + this->fileName = fileName; + QFileInfo info(fileName); + QString title(info.fileName()); + title.append("-Valentina"); + setWindowTitle(title); } diff --git a/mainwindow.h b/mainwindow.h index 11cf17816..5655f361b 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -49,6 +49,7 @@ class MainWindow : public QMainWindow public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); + void OpenPattern(const QString &fileName); public slots: void mouseMove(QPointF scenePos); void ActionAroowTool(); @@ -107,6 +108,7 @@ signals: protected: virtual void keyPressEvent ( QKeyEvent * event ); virtual void showEvent( QShowEvent *event ); + void Clear(); private: Ui::MainWindow *ui; Tools::Enum tool;