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.
This commit is contained in:
dismine 2013-09-23 16:17:15 +03:00
parent 1b7fc8df85
commit 9f6bd02736
4 changed files with 154 additions and 101 deletions

View File

@ -23,8 +23,8 @@
#include <QDebug> #include <QDebug>
VExceptionEmptyParameter::VExceptionEmptyParameter(const QString &what, const QString &name, VExceptionEmptyParameter::VExceptionEmptyParameter(const QString &what, const QString &name,
const QDomElement &domElement): VException(what), name(name), const QDomElement &domElement): VException(what),
tagText(QString()), tagName(QString()), lineNumber(-1){ name(name), tagText(QString()), tagName(QString()), lineNumber(-1){
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null"); Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "Parameter name is empty"); Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "Parameter name is empty");
if(domElement.isText()){ if(domElement.isText()){
@ -36,7 +36,7 @@ VExceptionEmptyParameter::VExceptionEmptyParameter(const QString &what, const QS
} }
VExceptionEmptyParameter::VExceptionEmptyParameter(const VExceptionEmptyParameter &e):VException(e), 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{ QString VExceptionEmptyParameter::ErrorMessage() const{

View File

@ -64,7 +64,29 @@ int main(int argc, char *argv[]){
TableWindow table; TableWindow table;
QObject::connect(&w, &MainWindow::ModelChosen, &table, &TableWindow::ModelChosen); QObject::connect(&w, &MainWindow::ModelChosen, &table, &TableWindow::ModelChosen);
QObject::connect(&table, &TableWindow::closed, &w, &MainWindow::tableClosed); 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(); return app.exec();
} }

View File

@ -737,104 +737,19 @@ void MainWindow::ActionOpen(){
QString fName = QFileDialog::getOpenFileName(this, tr("Open file"), QDir::homePath(), filter); QString fName = QFileDialog::getOpenFileName(this, tr("Open file"), QDir::homePath(), filter);
if(fName.isEmpty()) if(fName.isEmpty())
return; return;
QFile file(fName); if(fileName.isEmpty() && changeInFile == false){
QString errorMsg; OpenPattern(fName);
qint32 errorLine = 0; } else {
qint32 errorColumn = 0; /*Open new copy application*/
if(file.open(QIODevice::ReadOnly)){ QProcess *v = new QProcess(this);
if(doc->setContent(&file, &errorMsg, &errorLine, &errorColumn)){ QStringList arguments;
disconnect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), arguments << "-o" << fName;
this, &MainWindow::currentDrawChanged); v->startDetached(QCoreApplication::applicationFilePath (), arguments);
try{ delete v;
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<void (QComboBox::*)(int)>(&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();
} }
fileName = fName;
QFileInfo info(fileName);
QString title(info.fileName());
title.append("-Valentina");
setWindowTitle(title);
} }
void MainWindow::ActionNew(){ void MainWindow::Clear(){
setWindowTitle("Valentina"); setWindowTitle("Valentina");
fileName.clear(); fileName.clear();
data->Clear(); data->Clear();
@ -849,9 +764,16 @@ void MainWindow::ActionNew(){
SetEnableTool(false); SetEnableTool(false);
} }
void MainWindow::ActionNew(){
QProcess *v = new QProcess(this);
v->startDetached(QCoreApplication::applicationFilePath ());
delete v;
}
void MainWindow::haveChange(){ void MainWindow::haveChange(){
if(!fileName.isEmpty()){ if(!fileName.isEmpty()){
ui->actionSave->setEnabled(true); ui->actionSave->setEnabled(true);
changeInFile = true;
} }
} }
@ -959,5 +881,112 @@ MainWindow::~MainWindow(){
delete data; delete data;
if(!doc->isNull()){ if(!doc->isNull()){
delete doc; delete doc;
} }
}
void MainWindow::OpenPattern(const QString &fileName){
if(fileName.isEmpty()){
qWarning()<<tr("Can't open pattern file. File name empty")<<Q_FUNC_INFO;
return;
}
QFile file(fileName);
QString errorMsg;
qint32 errorLine = 0;
qint32 errorColumn = 0;
if(file.open(QIODevice::ReadOnly)){
if(doc->setContent(&file, &errorMsg, &errorLine, &errorColumn)){
disconnect(comboBoxDraws, static_cast<void (QComboBox::*)(int)>(&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<void (QComboBox::*)(int)>(&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);
} }

View File

@ -49,6 +49,7 @@ class MainWindow : public QMainWindow
public: public:
explicit MainWindow(QWidget *parent = 0); explicit MainWindow(QWidget *parent = 0);
~MainWindow(); ~MainWindow();
void OpenPattern(const QString &fileName);
public slots: public slots:
void mouseMove(QPointF scenePos); void mouseMove(QPointF scenePos);
void ActionAroowTool(); void ActionAroowTool();
@ -107,6 +108,7 @@ signals:
protected: protected:
virtual void keyPressEvent ( QKeyEvent * event ); virtual void keyPressEvent ( QKeyEvent * event );
virtual void showEvent( QShowEvent *event ); virtual void showEvent( QShowEvent *event );
void Clear();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
Tools::Enum tool; Tools::Enum tool;