Refactoring.

--HG--
branch : develop
This commit is contained in:
dismine 2013-10-27 09:47:01 +02:00
parent f0a9bdf4d2
commit f2860076ee
4 changed files with 94 additions and 147 deletions

View File

@ -20,21 +20,19 @@
****************************************************************************/ ****************************************************************************/
#include "vdomdocument.h" #include "vdomdocument.h"
#include <QDebug> #include <exception/vexceptionwrongparameterid.h>
#include "tools/drawTools/drawtools.h" #include <exception/vexceptionconversionerror.h>
#include "tools/nodeDetails/nodedetails.h" #include <exception/vexceptionemptyparameter.h>
#include "tools/modelingTools/modelingtools.h" #include <exception/vexceptionuniqueid.h>
#include "tools/vtooldetail.h" #include <tools/vtooldetail.h>
#include "options.h" #include <exception/vexceptionobjecterror.h>
#include "container/calculator.h" #include <exception/vexceptionbadid.h>
#include "geometry/vsplinepoint.h" #include <tools/drawTools/drawtools.h>
#include "exception/vexceptionwrongparameterid.h" #include <tools/modelingTools/modelingtools.h>
#include "exception/vexceptionconversionerror.h" #include <tools/nodeDetails/vnodepoint.h>
#include "exception/vexceptionemptyparameter.h" #include <tools/nodeDetails/vnodespline.h>
#include "exception/vexceptionbadid.h" #include <tools/nodeDetails/vnodesplinepath.h>
#include "exception/vexceptionobjecterror.h" #include <tools/nodeDetails/vnodearc.h>
#include "exception/vexceptionuniqueid.h"
#include <QMessageBox>
VDomDocument::VDomDocument(VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode) : QDomDocument(), VDomDocument::VDomDocument(VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode) : QDomDocument(),
map(QHash<QString, QDomElement>()), nameActivDraw(QString()), data(data), map(QHash<QString, QDomElement>()), nameActivDraw(QString()), data(data),
@ -56,9 +54,6 @@ VDomDocument::VDomDocument(const QDomDocumentType& doctype, VContainer *data, QC
comboBoxDraws(comboBoxDraws), mode(mode){ comboBoxDraws(comboBoxDraws), mode(mode){
} }
VDomDocument::~VDomDocument(){
}
QDomElement VDomDocument::elementById(const QString& id){ QDomElement VDomDocument::elementById(const QString& id){
if (map.contains(id)) { if (map.contains(id)) {
QDomElement e = map[id]; QDomElement e = map[id];
@ -190,10 +185,6 @@ void VDomDocument::SetActivDraw(const QString& name){
this->nameActivDraw = name; this->nameActivDraw = name;
} }
QString VDomDocument::GetNameActivDraw() const{
return nameActivDraw;
}
bool VDomDocument::GetActivDrawElement(QDomElement &element){ bool VDomDocument::GetActivDrawElement(QDomElement &element){
if(!nameActivDraw.isEmpty()){ if(!nameActivDraw.isEmpty()){
QDomNodeList elements = this->documentElement().elementsByTagName( "draw" ); QDomNodeList elements = this->documentElement().elementsByTagName( "draw" );
@ -307,14 +298,6 @@ void VDomDocument::Parse(Document::Documents parse, VMainGraphicsScene *sceneDra
} }
} }
QHash<qint64, VDataTool *> *VDomDocument::getTools(){
return &tools;
}
QVector<VToolRecord> *VDomDocument::getHistory(){
return &history;
}
void VDomDocument::ParseIncrementsElement(const QDomNode &node){ void VDomDocument::ParseIncrementsElement(const QDomNode &node){
QDomNode domNode = node.firstChild(); QDomNode domNode = node.firstChild();
while(!domNode.isNull()){ while(!domNode.isNull()){
@ -1134,10 +1117,6 @@ void VDomDocument::ShowHistoryTool(qint64 id, Qt::GlobalColor color, bool enable
emit ShowTool(id, color, enable); emit ShowTool(id, color, enable);
} }
qint64 VDomDocument::getCursor() const{
return cursor;
}
void VDomDocument::setCursor(const qint64 &value){ void VDomDocument::setCursor(const qint64 &value){
cursor = value; cursor = value;
emit ChangedCursor(cursor); emit ChangedCursor(cursor);

View File

@ -23,10 +23,9 @@
#define VDOMDOCUMENT_H #define VDOMDOCUMENT_H
#include <QDomDocument> #include <QDomDocument>
#include <QHash> #include <container/vcontainer.h>
#include <QComboBox> #include <widgets/vmaingraphicsscene.h>
#include "widgets/vmaingraphicsscene.h" #include <tools/vdatatool.h>
#include "tools/vdatatool.h"
#include "vtoolrecord.h" #include "vtoolrecord.h"
namespace Document { namespace Document {
@ -40,80 +39,80 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(Document::Documents)
class VDomDocument : public QObject, public QDomDocument{ class VDomDocument : public QObject, public QDomDocument{
Q_OBJECT Q_OBJECT
public: public:
VDomDocument(VContainer *data,QComboBox *comboBoxDraws, Draw::Draws *mode); VDomDocument(VContainer *data,QComboBox *comboBoxDraws, Draw::Draws *mode);
VDomDocument(const QString& name, VContainer *data, QComboBox *comboBoxDraws, VDomDocument(const QString& name, VContainer *data, QComboBox *comboBoxDraws,
Draw::Draws *mode); Draw::Draws *mode);
VDomDocument(const QDomDocumentType& doctype, VContainer *data, QComboBox *comboBoxDraws, VDomDocument(const QDomDocumentType& doctype, VContainer *data, QComboBox *comboBoxDraws,
Draw::Draws *mode); Draw::Draws *mode);
~VDomDocument(); ~VDomDocument(){}
QDomElement elementById(const QString& id); QDomElement elementById(const QString& id);
void CreateEmptyFile(); void CreateEmptyFile();
void ChangeActivDraw(const QString& name, Document::Documents parse = Document::FullParse); void ChangeActivDraw(const QString& name, Document::Documents parse = Document::FullParse);
QString GetNameActivDraw() const; inline QString GetNameActivDraw() const {return nameActivDraw;}
bool GetActivDrawElement(QDomElement &element); bool GetActivDrawElement(QDomElement &element);
bool GetActivCalculationElement(QDomElement &element); bool GetActivCalculationElement(QDomElement &element);
bool GetActivModelingElement(QDomElement &element); bool GetActivModelingElement(QDomElement &element);
bool GetActivDetailsElement(QDomElement &element); bool GetActivDetailsElement(QDomElement &element);
bool appendDraw(const QString& name); bool appendDraw(const QString& name);
bool SetNameDraw(const QString& name); bool SetNameDraw(const QString& name);
void Parse(Document::Documents parse, VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail); void Parse(Document::Documents parse, VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail);
QHash<qint64, VDataTool*>* getTools(); inline QHash<qint64, VDataTool*>* getTools() {return &tools;}
QVector<VToolRecord> *getHistory(); inline QVector<VToolRecord> *getHistory() {return &history;}
qint64 getCursor() const; inline qint64 getCursor() const {return cursor;}
void setCursor(const qint64 &value); void setCursor(const qint64 &value);
void setCurrentData(); void setCurrentData();
void AddTool(const qint64 &id, VDataTool *tool); void AddTool(const qint64 &id, VDataTool *tool);
void UpdateToolData(const qint64 &id, VContainer *data); void UpdateToolData(const qint64 &id, VContainer *data);
void IncrementReferens(qint64 id) const; void IncrementReferens(qint64 id) const;
void DecrementReferens(qint64 id) const; void DecrementReferens(qint64 id) const;
void TestUniqueId() const; void TestUniqueId() const;
signals: signals:
void ChangedActivDraw(const QString newName); void ChangedActivDraw(const QString newName);
void ChangedNameDraw(const QString oldName, const QString newName); void ChangedNameDraw(const QString oldName, const QString newName);
void FullUpdateFromFile(); void FullUpdateFromFile();
void haveChange(); void haveChange();
void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); void ShowTool(qint64 id, Qt::GlobalColor color, bool enable);
void ChangedCursor(qint64 id); void ChangedCursor(qint64 id);
public slots: public slots:
void FullUpdateTree(); void FullUpdateTree();
void haveLiteChange(); void haveLiteChange();
void ShowHistoryTool(qint64 id, Qt::GlobalColor color, bool enable); void ShowHistoryTool(qint64 id, Qt::GlobalColor color, bool enable);
private: private:
Q_DISABLE_COPY(VDomDocument) Q_DISABLE_COPY(VDomDocument)
QHash<QString, QDomElement> map; QHash<QString, QDomElement> map;
QString nameActivDraw; QString nameActivDraw;
VContainer *data; VContainer *data;
QHash<qint64, VDataTool*> tools; QHash<qint64, VDataTool*> tools;
QVector<VToolRecord> history; QVector<VToolRecord> history;
qint64 cursor; qint64 cursor;
QComboBox *comboBoxDraws; QComboBox *comboBoxDraws;
Draw::Draws *mode; Draw::Draws *mode;
bool find(QDomElement node, const QString& id); bool find(QDomElement node, const QString& id);
bool CheckNameDraw(const QString& name) const; bool CheckNameDraw(const QString& name) const;
void SetActivDraw(const QString& name); void SetActivDraw(const QString& name);
bool GetActivNodeElement(const QString& name, QDomElement& element); bool GetActivNodeElement(const QString& name, QDomElement& element);
void ParseDrawElement(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, void ParseDrawElement(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail,
const QDomNode& node, const Document::Documents &parse); const QDomNode& node, const Document::Documents &parse);
void ParseDrawMode(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, void ParseDrawMode(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail,
const QDomNode& node, const Document::Documents &parse, Draw::Draws mode); const QDomNode& node, const Document::Documents &parse, Draw::Draws mode);
void ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDomElement &domElement, void ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDomElement &domElement,
const Document::Documents &parse); const Document::Documents &parse);
void ParseDetails(VMainGraphicsScene *sceneDetail, const QDomElement &domElement, void ParseDetails(VMainGraphicsScene *sceneDetail, const QDomElement &domElement,
const Document::Documents &parse); const Document::Documents &parse);
void ParsePointElement(VMainGraphicsScene *scene, const QDomElement& domElement, void ParsePointElement(VMainGraphicsScene *scene, const QDomElement& domElement,
const Document::Documents &parse, const QString &type, Draw::Draws mode); const Document::Documents &parse, const QString &type, Draw::Draws mode);
void ParseLineElement(VMainGraphicsScene *scene, const QDomElement& domElement, void ParseLineElement(VMainGraphicsScene *scene, const QDomElement& domElement,
const Document::Documents &parse, Draw::Draws mode); const Document::Documents &parse, Draw::Draws mode);
void ParseSplineElement(VMainGraphicsScene *scene, const QDomElement& domElement, void ParseSplineElement(VMainGraphicsScene *scene, const QDomElement& domElement,
const Document::Documents &parse, const QString& type, Draw::Draws mode);
void ParseArcElement(VMainGraphicsScene *scene, const QDomElement& domElement,
const Document::Documents &parse, const QString& type, Draw::Draws mode); const Document::Documents &parse, const QString& type, Draw::Draws mode);
void ParseArcElement(VMainGraphicsScene *scene, const QDomElement& domElement, void ParseIncrementsElement(const QDomNode& node);
const Document::Documents &parse, const QString& type, Draw::Draws mode); qint64 GetParametrId(const QDomElement& domElement) const;
void ParseIncrementsElement(const QDomNode& node); qint64 GetParametrLongLong(const QDomElement& domElement, const QString &name) const;
qint64 GetParametrId(const QDomElement& domElement) const; QString GetParametrString(const QDomElement& domElement, const QString &name) const;
qint64 GetParametrLongLong(const QDomElement& domElement, const QString &name) const; qreal GetParametrDouble(const QDomElement& domElement, const QString &name) const;
QString GetParametrString(const QDomElement& domElement, const QString &name) const; void CollectId(QDomElement node, QVector<qint64> &vector)const;
qreal GetParametrDouble(const QDomElement& domElement, const QString &name) const;
void CollectId(QDomElement node, QVector<qint64> &vector)const;
}; };
#pragma GCC diagnostic pop #pragma GCC diagnostic pop

View File

@ -27,27 +27,3 @@ VToolRecord::VToolRecord():id(0), typeTool(Tool::ArrowTool), nameDraw(QString())
VToolRecord::VToolRecord(const qint64 &id, const Tool::Tools &typeTool, const QString &nameDraw):id(id), VToolRecord::VToolRecord(const qint64 &id, const Tool::Tools &typeTool, const QString &nameDraw):id(id),
typeTool(typeTool), nameDraw(nameDraw){ typeTool(typeTool), nameDraw(nameDraw){
} }
QString VToolRecord::getNameDraw() const{
return nameDraw;
}
void VToolRecord::setNameDraw(const QString &value){
nameDraw = value;
}
Tool::Tools VToolRecord::getTypeTool() const{
return typeTool;
}
void VToolRecord::setTypeTool(const Tool::Tools &value){
typeTool = value;
}
qint64 VToolRecord::getId() const{
return id;
}
void VToolRecord::setId(const qint64 &value){
id = value;
}

View File

@ -22,27 +22,20 @@
#ifndef VTOOLRECORD_H #ifndef VTOOLRECORD_H
#define VTOOLRECORD_H #define VTOOLRECORD_H
#include <QString> class VToolRecord{
#include "options.h"
class VToolRecord
{
public: public:
VToolRecord(); VToolRecord();
VToolRecord(const qint64 &id, const Tool::Tools &typeTool, const QString &nameDraw); VToolRecord(const qint64 &id, const Tool::Tools &typeTool, const QString &nameDraw);
qint64 getId() const; inline qint64 getId() const {return id;}
void setId(const qint64 &value); inline void setId(const qint64 &value) {id = value;}
inline Tool::Tools getTypeTool() const {return typeTool;}
Tool::Tools getTypeTool() const; inline void setTypeTool(const Tool::Tools &value) {typeTool = value;}
void setTypeTool(const Tool::Tools &value); inline QString getNameDraw() const {return nameDraw;}
inline void setNameDraw(const QString &value) {nameDraw = value;}
QString getNameDraw() const;
void setNameDraw(const QString &value);
private: private:
qint64 id; qint64 id;
Tool::Tools typeTool; Tool::Tools typeTool;
QString nameDraw; QString nameDraw;
}; };
#endif // VTOOLRECORD_H #endif // VTOOLRECORD_H