Added support exception for some situations.

This commit is contained in:
dismine 2013-09-23 15:08:06 +03:00
parent 91744b39b7
commit 1b7fc8df85
19 changed files with 1212 additions and 336 deletions

View File

@ -87,7 +87,14 @@ SOURCES += main.cpp\
tools/modelingTools/vmodelingpointofcontact.cpp \
tools/modelingTools/vmodelingshoulderpoint.cpp \
tools/modelingTools/vmodelingspline.cpp \
tools/modelingTools/vmodelingsplinepath.cpp
tools/modelingTools/vmodelingsplinepath.cpp \
exception/vexception.cpp \
exception/vexceptionbadid.cpp \
exception/vexceptionwrongparameterid.cpp \
exception/vexceptionconversionerror.cpp \
exception/vexceptionemptyparameter.cpp \
exception/vexceptionobjecterror.cpp \
widgets/vapplication.cpp
HEADERS += mainwindow.h \
widgets/vmaingraphicsscene.h \
@ -170,7 +177,14 @@ HEADERS += mainwindow.h \
tools/modelingTools/vmodelingpointofcontact.h \
tools/modelingTools/vmodelingshoulderpoint.h \
tools/modelingTools/vmodelingspline.h \
tools/modelingTools/vmodelingsplinepath.h
tools/modelingTools/vmodelingsplinepath.h \
exception/vexception.h \
exception/vexceptionbadid.h \
exception/vexceptionwrongparameterid.h \
exception/vexceptionconversionerror.h \
exception/vexceptionemptyparameter.h \
exception/vexceptionobjecterror.h \
widgets/vapplication.h
FORMS += mainwindow.ui \
dialogs/dialogsinglepoint.ui \

View File

@ -22,6 +22,7 @@
#include "vcontainer.h"
#include <QDebug>
#include "options.h"
#include <exception/vexceptionbadid.h>
qint64 VContainer::_id = 0;
@ -80,8 +81,7 @@ val VContainer::GetObject(const QMap<key,val> &obj, key id){
if(obj.contains(id)){
return obj.value(id);
} else {
qCritical()<<"Не можу знайти key = "<<id<<" в таблиці.";
throw"Не можу знайти об'єкт за ключем.";
throw VExceptionBadId(tr("Can't find object"), id);
}
}

View File

@ -33,12 +33,14 @@
#include "geometry/vsplinepath.h"
#include "geometry/vdetail.h"
#include "widgets/vitem.h"
#include <QCoreApplication>
/**
* @brief The VContainer class
*/
class VContainer
{
Q_DECLARE_TR_FUNCTIONS(VContainer)
public:
/**
* @brief VContainer

34
exception/vexception.cpp Normal file
View File

@ -0,0 +1,34 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "vexception.h"
VException::VException(const QString &what):QException(), what(what){
Q_ASSERT_X(!what.isEmpty(), Q_FUNC_INFO, "Error message is empty");
}
VException::VException(const VException &e):what(e.What()){
}
QString VException::ErrorMessage() const{
QString error = QString("Exception: %1").arg(what);
return error;
}

44
exception/vexception.h Normal file
View File

@ -0,0 +1,44 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef VEXCEPTION_H
#define VEXCEPTION_H
#include <QException>
#include <QString>
class VException : public QException
{
public:
VException(const QString &what);
VException(const VException &e);
virtual ~VException() noexcept(true){}
void raise() const { throw *this; }
VException *clone() const { return new VException(*this); }
virtual QString ErrorMessage() const;
virtual QString DetailedInformation() const { return QString(); }
QString What() const {return what;}
protected:
QString what;
};
#endif // VEXCEPTION_H

View File

@ -0,0 +1,44 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "vexceptionbadid.h"
VExceptionBadId::VExceptionBadId(const QString &what, const qint64 &id):VException(what), id(id),
key(QString()){
}
VExceptionBadId::VExceptionBadId(const QString &what, const QString &key):VException(what), id(0), key(key)
{
}
VExceptionBadId::VExceptionBadId(const VExceptionBadId &e):VException(e), id(e.BadId()), key(e.BadKey()){
}
QString VExceptionBadId::ErrorMessage() const{
QString error;
if(key.isEmpty()){
error = QString("ExceptionBadId: %1, id = %2").arg(what).arg(id);
} else {
error = QString("ExceptionBadId: %1, id = %2").arg(what).arg(key);
}
return error;
}

View File

@ -0,0 +1,42 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef VEXCEPTIONBADID_H
#define VEXCEPTIONBADID_H
#include "vexception.h"
class VExceptionBadId : public VException
{
public:
VExceptionBadId(const QString &what, const qint64 &id);
VExceptionBadId(const QString &what, const QString &key);
VExceptionBadId(const VExceptionBadId &e);
virtual ~VExceptionBadId() noexcept(true){}
virtual QString ErrorMessage() const;
qint64 BadId() const {return id; }
QString BadKey() const {return key; }
protected:
qint64 id;
QString key;
};
#endif // VEXCEPTIONBADID_H

View File

@ -0,0 +1,36 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "vexceptionconversionerror.h"
VExceptionConversionError::VExceptionConversionError(const QString &what, const QString &str)
:VException(what), str(str){
Q_ASSERT_X(!str.isEmpty(), Q_FUNC_INFO, "Error converting string is empty");
}
VExceptionConversionError::VExceptionConversionError(const VExceptionConversionError &e):
VException(e), str(e.String()){
}
QString VExceptionConversionError::ErrorMessage() const{
QString error = QString("ExceptionConversionError: %1 %2").arg(what, str);
return error;
}

View File

@ -0,0 +1,39 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef VEXCEPTIONCONVERSIONERROR_H
#define VEXCEPTIONCONVERSIONERROR_H
#include "vexception.h"
class VExceptionConversionError : public VException
{
public:
VExceptionConversionError(const QString &what, const QString &str);
VExceptionConversionError(const VExceptionConversionError &e);
virtual ~VExceptionConversionError() noexcept(true) {}
virtual QString ErrorMessage() const;
QString String() const {return str;}
protected:
QString str;
};
#endif // VEXCEPTIONCONVERSIONERROR_H

View File

@ -0,0 +1,50 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "vexceptionemptyparameter.h"
#include <QDebug>
VExceptionEmptyParameter::VExceptionEmptyParameter(const QString &what, const QString &name,
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()){
QDomText text = domElement.toText();
tagText = text.data();
}
tagName = domElement.tagName();
lineNumber = domElement.lineNumber();
}
VExceptionEmptyParameter::VExceptionEmptyParameter(const VExceptionEmptyParameter &e):VException(e),
name(e.Name()), tagName(e.TagName()), tagText(e.TagText()), lineNumber(e.LineNumber()){
}
QString VExceptionEmptyParameter::ErrorMessage() const{
QString error = QString("ExceptionEmptyParameter: %1 %2").arg(what, name);
return error;
}
QString VExceptionEmptyParameter::DetailedInformation() const{
QString detail = QString("tag: %1 in line %2\nFull tag:\n%3").arg(tagName).arg(lineNumber).arg(tagText);
return detail;
}

View File

@ -0,0 +1,47 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef VEXCEPTIONEMPTYPARAMETER_H
#define VEXCEPTIONEMPTYPARAMETER_H
#include "vexception.h"
#include "QDomElement"
class VExceptionEmptyParameter : public VException
{
public:
VExceptionEmptyParameter(const QString &what, const QString &name, const QDomElement &domElement);
VExceptionEmptyParameter(const VExceptionEmptyParameter &e);
virtual ~VExceptionEmptyParameter() noexcept(true) {}
virtual QString ErrorMessage() const;
virtual QString DetailedInformation() const;
QString Name() const {return name;}
QString TagText() const {return tagText;}
QString TagName() const {return tagName;}
qint32 LineNumber() const {return lineNumber;}
protected:
QString name;
QString tagText;
QString tagName;
qint32 lineNumber;
};
#endif // VEXCEPTIONEMPTYPARAMETER_H

View File

@ -0,0 +1,61 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "vexceptionobjecterror.h"
#include <QDebug>
VExceptionObjectError::VExceptionObjectError(const QString &what, const QDomElement &domElement):
VException(what), tagText(QString()), tagName(QString()), lineNumber(-1), moreInfo(QString()){
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
if(domElement.isText()){
QDomText text = domElement.toText();
tagText = text.data();
}
tagName = domElement.tagName();
lineNumber = domElement.lineNumber();
}
VExceptionObjectError::VExceptionObjectError(const VExceptionObjectError &e):VException(e),
tagText(e.TagText()), tagName(e.TagName()), lineNumber(e.LineNumber()), moreInfo(e.MoreInformation()){
}
QString VExceptionObjectError::ErrorMessage() const{
QString error = QString("ExceptionObjectError: %1").arg(what);
return error;
}
QString VExceptionObjectError::DetailedInformation() const{
QString detail;
if(!moreInfo.isEmpty()){
QString i = QString("tag: %1 in line %2\n%3").arg(tagName).arg(lineNumber).arg(tagText);
detail = QString("%1\n%2").arg(moreInfo, i);
} else {
detail = QString("tag: %1 in line %2\n%3").arg(tagName).arg(lineNumber).arg(tagText);
}
return detail;
}
void VExceptionObjectError::AddMoreInformation(const QString &info){
if(info.isEmpty()){
qWarning()<<"Error additional information is empty."<<Q_FUNC_INFO;
}
this->moreInfo.append(info);
}

View File

@ -0,0 +1,48 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef VEXCEPTIONOBJECTERROR_H
#define VEXCEPTIONOBJECTERROR_H
#include "vexception.h"
#include <QDomElement>
class VExceptionObjectError : public VException
{
public:
VExceptionObjectError(const QString &what, const QDomElement &domElement);
VExceptionObjectError(const VExceptionObjectError &e);
virtual ~VExceptionObjectError() noexcept(true) {}
virtual QString ErrorMessage() const;
virtual QString DetailedInformation() const;
QString TagText() const {return tagText;}
QString TagName() const {return tagName;}
qint32 LineNumber() const {return lineNumber;}
void AddMoreInformation(const QString &info);
QString MoreInformation() const {return moreInfo;}
protected:
QString tagText;
QString tagName;
qint32 lineNumber;
QString moreInfo;
};
#endif // VEXCEPTIONOBJECTERROR_H

View File

@ -0,0 +1,48 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "vexceptionwrongparameterid.h"
#include <QDebug>
VExceptionWrongParameterId::VExceptionWrongParameterId(const QString &what, const QDomElement &domElement):
VException(what), tagText(QString()), tagName(QString()), lineNumber(-1){
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
if(domElement.isText()){
QDomText text = domElement.toText();
tagText = text.data();
}
tagName = domElement.tagName();
lineNumber = domElement.lineNumber();
}
VExceptionWrongParameterId::VExceptionWrongParameterId(const VExceptionWrongParameterId &e):VException(e),
tagText(e.TagText()), tagName(e.TagName()), lineNumber(e.LineNumber()){
}
QString VExceptionWrongParameterId::ErrorMessage() const{
QString error = QString("ExceptionWrongParameterId: %1").arg(what);
return error;
}
QString VExceptionWrongParameterId::DetailedInformation() const{
QString detail = QString("tag: %1 in line %2\n%3").arg(tagName).arg(lineNumber).arg(tagText);
return detail;
}

View File

@ -0,0 +1,45 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#ifndef VEXCEPTIONWRONGPARAMETERID_H
#define VEXCEPTIONWRONGPARAMETERID_H
#include "vexception.h"
#include <QDomElement>
class VExceptionWrongParameterId : public VException
{
public:
VExceptionWrongParameterId(const QString &what, const QDomElement &domElement);
VExceptionWrongParameterId(const VExceptionWrongParameterId &e);
virtual ~VExceptionWrongParameterId() noexcept(true){}
virtual QString ErrorMessage() const;
virtual QString DetailedInformation() const;
QString TagText() const {return tagText;}
QString TagName() const {return tagName;}
qint32 LineNumber() const {return lineNumber;}
protected:
QString tagText;
QString tagName;
qint32 lineNumber;
};
#endif // VEXCEPTIONWRONGPARAMETERID_H

View File

@ -30,6 +30,11 @@
#include <QFileDialog>
#include <QDebug>
#include "geometry/vspline.h"
#include <QMessageBox>
#include "exception/vexceptionobjecterror.h"
#include "exception/vexceptionconversionerror.h"
#include "exception/vexceptionemptyparameter.h"
#include "exception/vexceptionwrongparameterid.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), ui(new Ui::MainWindow), tool(Tools::ArrowTool), currentScene(0), sceneDraw(0),
@ -732,17 +737,68 @@ void MainWindow::ActionOpen(){
QString fName = QFileDialog::getOpenFileName(this, tr("Open file"), QDir::homePath(), filter);
if(fName.isEmpty())
return;
fileName = fName;
QFileInfo info(fileName);
QString title(info.fileName());
title.append("-Valentina");
setWindowTitle(title);
QFile file(fileName);
QFile file(fName);
QString errorMsg;
qint32 errorLine = 0;
qint32 errorColumn = 0;
if(file.open(QIODevice::ReadOnly)){
if(doc->setContent(&file)){
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();
@ -756,9 +812,26 @@ void MainWindow::ActionOpen(){
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(){

102
widgets/vapplication.cpp Normal file
View File

@ -0,0 +1,102 @@
/****************************************************************************
**
** Copyright (C) 2013 Valentina project All Rights Reserved.
**
** This file is part of Valentina.
**
** Tox is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Tox is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
****************************************************************************/
#include "vapplication.h"
#include <QtGui>
#include <QMessageBox>
#include "exception/vexceptionobjecterror.h"
#include "exception/vexceptionbadid.h"
#include "exception/vexceptionconversionerror.h"
#include "exception/vexceptionemptyparameter.h"
#include "exception/vexceptionwrongparameterid.h"
VApplication::VApplication(int & argc, char ** argv) :
QApplication(argc, argv){
}
// reimplemented from QApplication so we can throw exceptions in slots
bool VApplication::notify(QObject *receiver, QEvent *event){
try {
return QApplication::notify(receiver, event);
}
catch(const VExceptionObjectError &e){
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error!"));
msgBox.setText(tr("Error parsing file. Program will be terminated."));
msgBox.setInformativeText(e.ErrorMessage());
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setDetailedText(e.DetailedInformation());
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
abort();
}
catch(const VExceptionBadId &e){
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error!"));
msgBox.setText(tr("Error bad id. Program will be terminated."));
msgBox.setInformativeText(e.ErrorMessage());
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
abort();
}
catch(const VExceptionConversionError &e){
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error!"));
msgBox.setText(tr("Error can't convert value. Program will be terminated."));
msgBox.setInformativeText(e.ErrorMessage());
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
abort();
}
catch(const VExceptionEmptyParameter &e){
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error!"));
msgBox.setText(tr("Error empty parameter. Program will be terminated."));
msgBox.setInformativeText(e.ErrorMessage());
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setDetailedText(e.DetailedInformation());
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
abort();
}
catch(const VExceptionWrongParameterId &e){
QMessageBox msgBox;
msgBox.setWindowTitle(tr("Error!"));
msgBox.setText(tr("Error wrong id. Program will be terminated."));
msgBox.setInformativeText(e.ErrorMessage());
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
msgBox.setDetailedText(e.DetailedInformation());
msgBox.setIcon(QMessageBox::Critical);
msgBox.exec();
abort();
}
catch(std::exception& e) {
qCritical() << "Exception thrown:" << e.what();
}
return false;
}

15
widgets/vapplication.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef VAPPLICATION_H
#define VAPPLICATION_H
#include <QApplication>
class VApplication : public QApplication
{
Q_OBJECT
public:
VApplication(int &argc, char ** argv);
virtual ~VApplication() { }
virtual bool notify(QObject * receiver, QEvent * event);
};
#endif // VAPPLICATION_H

View File

@ -28,7 +28,11 @@
#include "options.h"
#include "container/calculator.h"
#include "geometry/vsplinepoint.h"
#include "exception/vexceptionwrongparameterid.h"
#include "exception/vexceptionconversionerror.h"
#include "exception/vexceptionemptyparameter.h"
#include "exception/vexceptionbadid.h"
#include "exception/vexceptionobjecterror.h"
VDomDocument::VDomDocument(VContainer *data, QComboBox *comboBoxDraws, Draw::Mode *mode) : QDomDocument(),
@ -324,8 +328,11 @@ void VDomDocument::ParseIncrementsElement(const QDomNode &node){
}
qint64 VDomDocument::GetParametrId(const QDomElement &domElement) const{
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
qint64 id = GetParametrLongLong(domElement, "id");
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
if(id <= 0){
throw VExceptionWrongParameterId(tr("Got wrong parameter id. Need only id > 0."), domElement);
}
return id;
}
@ -335,20 +342,20 @@ qint64 VDomDocument::GetParametrLongLong(const QDomElement &domElement, const QS
bool ok = false;
QString parametr = GetParametrString(domElement, name);
qint64 id = parametr.toLongLong(&ok);
QString error("can't convert parametr ");
error.append(name);
Q_ASSERT_X(ok, Q_FUNC_INFO, error.toLatin1().data());
if(ok == false){
throw VExceptionConversionError(tr("Can't convert toLongLong parameter"), name);
}
return id;
}
QString VDomDocument::GetParametrString(const QDomElement &domElement, const QString &name) const{
Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, "name of parametr is empty");
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
QString parametr = domElement.attribute(name, "");
QString error("get empty parametr ");
error.append(name);
Q_ASSERT_X(!parametr.isEmpty(), Q_FUNC_INFO, error.toLatin1().data());
return parametr;
QString parameter = domElement.attribute(name, "");
if(parameter.isEmpty()){
throw VExceptionEmptyParameter(tr("Got empty parameter"), name, domElement);
}
return parameter;
}
qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QString &name) const{
@ -357,9 +364,9 @@ qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QStri
bool ok = false;
QString parametr = GetParametrString(domElement, name);
qreal param = parametr.toDouble(&ok);
QString error("can't convert parametr ");
error.append(name);
Q_ASSERT_X(ok, Q_FUNC_INFO, error.toLatin1().data());
if(ok == false){
throw VExceptionConversionError(tr("Can't convert toDouble parameter"), name);
}
return param;
}
@ -423,6 +430,7 @@ void VDomDocument::ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDo
Document::Enum parse){
Q_CHECK_PTR(sceneDetail);
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
try{
VDetail detail;
VDetail oldDetail;
qint64 id = GetParametrId(domElement);
@ -490,6 +498,12 @@ void VDomDocument::ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDo
}
VToolDetail::Create(id, detail, oldDetail, sceneDetail, this, data, parse, Tool::FromFile);
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating detail"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
void VDomDocument::ParseDetails(VMainGraphicsScene *sceneDetail, const QDomElement &domElement,
Document::Enum parse){
@ -515,6 +529,7 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
Q_ASSERT_X(!type.isEmpty(), Q_FUNC_INFO, "type of point is empty");
if(type == "single"){
try{
qint64 id = GetParametrId(domElement);
QString name = GetParametrString(domElement, "name");
qreal x = toPixel(GetParametrDouble(domElement, "x"));
@ -536,7 +551,14 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
}
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating single point"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if(type == "endLine"){
try{
qint64 id = GetParametrId(domElement);
QString name = GetParametrString(domElement, "name");
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
@ -554,7 +576,14 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
}
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating point of end line"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if(type == "alongLine"){
try{
qint64 id = GetParametrId(domElement);
QString name = GetParametrString(domElement, "name");
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
@ -572,7 +601,14 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
}
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating point along line"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if(type == "shoulder"){
try{
qint64 id = GetParametrId(domElement);
QString name = GetParametrString(domElement, "name");
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
@ -591,7 +627,14 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
}
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating point of shoulder"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if(type == "normal"){
try{
qint64 id = GetParametrId(domElement);
QString name = GetParametrString(domElement, "name");
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
@ -610,7 +653,14 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
}
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating point of normal"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if(type == "bisector"){
try{
qint64 id = GetParametrId(domElement);
QString name = GetParametrString(domElement, "name");
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
@ -629,7 +679,14 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
}
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating point of bisector"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if(type == "lineIntersect"){
try{
qint64 id = GetParametrId(domElement);
QString name = GetParametrString(domElement, "name");
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
@ -647,7 +704,14 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
}
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating point of lineintersection"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if(type == "pointOfContact"){
try{
qint64 id = GetParametrId(domElement);
QString name = GetParametrString(domElement, "name");
qreal mx = toPixel(GetParametrDouble(domElement, "mx"));
@ -665,7 +729,14 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
}
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating point of contact"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if(type == "modeling"){
try{
qint64 id = GetParametrId(domElement);
qint64 idObject = GetParametrLongLong(domElement, "idObject");
QString tObject = GetParametrString(domElement, "typeObject");
@ -685,12 +756,19 @@ void VDomDocument::ParsePointElement(VMainGraphicsScene *scene, const QDomElemen
data->IncrementReferens(idObject, Scene::Point, typeObject);
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating modeling point"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
}
void VDomDocument::ParseLineElement(VMainGraphicsScene *scene, const QDomElement &domElement,
Document::Enum parse, Draw::Mode mode){
Q_CHECK_PTR(scene);
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
try{
qint64 id = GetParametrId(domElement);
qint64 firstPoint = GetParametrLongLong(domElement, "firstPoint");
qint64 secondPoint = GetParametrLongLong(domElement, "secondPoint");
@ -700,6 +778,12 @@ void VDomDocument::ParseLineElement(VMainGraphicsScene *scene, const QDomElement
VModelingLine::Create(id, firstPoint, secondPoint, this, data, parse, Tool::FromFile);
}
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating line"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomElement &domElement,
Document::Enum parse, const QString &type, Draw::Mode mode){
@ -707,6 +791,7 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
Q_ASSERT_X(!type.isEmpty(), Q_FUNC_INFO, "type of spline is empty");
if(type == "simple"){
try{
qint64 id = GetParametrId(domElement);
qint64 point1 = GetParametrLongLong(domElement, "point1");
qint64 point4 = GetParametrLongLong(domElement, "point4");
@ -724,7 +809,14 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme
}
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating simple curve"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if(type == "path"){
try{
qint64 id = GetParametrId(domElement);
qreal kCurve = GetParametrDouble(domElement, "kCurve");
VSplinePath path(data->DataPoints(), kCurve);
@ -751,7 +843,14 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme
}
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating curve path"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if(type == "modelingSpline"){
try{
qint64 id = GetParametrId(domElement);
qint64 idObject = GetParametrLongLong(domElement, "idObject");
QString tObject = GetParametrString(domElement, "typeObject");
@ -776,7 +875,14 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme
}
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating modeling simple curve"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if(type == "modelingPath"){
try{
qint64 id = GetParametrId(domElement);
qint64 idObject = GetParametrLongLong(domElement, "idObject");
QString tObject = GetParametrString(domElement, "typeObject");
@ -802,6 +908,12 @@ void VDomDocument::ParseSplineElement(VMainGraphicsScene *scene, const QDomEleme
}
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating modeling curve path"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
}
void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement &domElement,
@ -810,6 +922,7 @@ void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement
Q_ASSERT_X(!domElement.isNull(), Q_FUNC_INFO, "domElement is null");
Q_ASSERT_X(!type.isEmpty(), Q_FUNC_INFO, "type of spline is empty");
if(type == "simple"){
try{
qint64 id = GetParametrId(domElement);
qint64 center = GetParametrLongLong(domElement, "center");
QString radius = GetParametrString(domElement, "radius");
@ -822,7 +935,14 @@ void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement
}
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating simple arc"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
if(type == "modeling"){
try{
qint64 id = GetParametrId(domElement);
qint64 idObject = GetParametrLongLong(domElement, "idObject");
QString tObject = GetParametrString(domElement, "typeObject");
@ -840,13 +960,25 @@ void VDomDocument::ParseArcElement(VMainGraphicsScene *scene, const QDomElement
data->UpdateModelingArc(id, arc);
return;
}
catch(const VExceptionBadId &e){
VExceptionObjectError excep(tr("Error creating or updating modeling arc"), domElement);
excep.AddMoreInformation(e.ErrorMessage());
throw excep;
}
}
}
void VDomDocument::FullUpdateTree(){
VMainGraphicsScene *scene = new VMainGraphicsScene();
Q_CHECK_PTR(scene);
try{
data->ClearObject();
Parse(Document::LiteParse, scene, scene);
}
catch(...){
delete scene;
throw;
}
delete scene;
setCurrentData();
emit FullUpdateFromFile();