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>
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{

View File

@ -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();
}

View File

@ -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<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();
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();
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;
}
}
@ -961,3 +883,110 @@ MainWindow::~MainWindow(){
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:
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;