Documentation for VToolRecord, VDomDocument classes. Fixed issue #2.

--HG--
branch : develop
This commit is contained in:
dismine 2014-01-27 16:05:58 +02:00
parent b96f83f238
commit b4841c1f25
2 changed files with 196 additions and 176 deletions

View file

@ -41,7 +41,7 @@
namespace Document namespace Document
{ {
/** /**
* @brief The Document enum * @brief The Document enum types parse.
*/ */
enum Document { LiteParse, FullParse}; enum Document { LiteParse, FullParse};
Q_DECLARE_FLAGS(Documents, Document) Q_DECLARE_FLAGS(Documents, Document)
@ -54,182 +54,195 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(Document::Documents)
#endif #endif
/** /**
* @brief The VDomDocument class * @brief The VDomDocument class working with pattern file.
*/ */
class VDomDocument : public QObject, public QDomDocument class VDomDocument : public QObject, public QDomDocument
{ {
Q_OBJECT Q_OBJECT
public: public:
/** /**
* @brief VDomDocument * @brief VDomDocument constructor.
* @param data container with variables * @param data container with variables.
* @param comboBoxDraws * @param comboBoxDraws combobox for pattern peaces names.
* @param mode * @param mode draw mode.
*/ */
VDomDocument(VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode, QObject *parent = 0); VDomDocument(VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode, QObject *parent = 0);
/** /**
* @brief VDomDocument * @brief VDomDocument constructor.
* @param name * @param name pattern peace name.
* @param data container with variables * @param data container with variables.
* @param comboBoxDraws * @param comboBoxDraws combobox for pattern peaces names.
* @param mode * @param mode draw mode.
*/ */
VDomDocument(const QString& name, VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode, VDomDocument(const QString& name, VContainer *data, QComboBox *comboBoxDraws, Draw::Draws *mode,
QObject *parent = 0); QObject *parent = 0);
/** /**
* @brief VDomDocument * @brief VDomDocument constructor.
* @param doc dom document containertype * @param doc dom document container type.
* @param data container with variables * @param data container with variables.
* @param comboBoxDraws * @param comboBoxDraws combobox for pattern peaces names.
* @param mode * @param mode draw mode.
*/ */
VDomDocument(const QDomDocumentType& doctype, VContainer *data, QComboBox *comboBoxDraws, VDomDocument(const QDomDocumentType& doctype, VContainer *data, QComboBox *comboBoxDraws,
Draw::Draws *mode, QObject *parent = 0); Draw::Draws *mode, QObject *parent = 0);
~VDomDocument(){} ~VDomDocument(){}
/** /**
* @brief elementById * @brief elementById find element by id.
* @param id * @param id value id attribute.
* @return * @return dom element.
*/ */
QDomElement elementById(const QString& id); QDomElement elementById(const QString& id);
/**
* @brief removeAllChilds remove all tag childs.
* @param element tag.
*/
void removeAllChilds(QDomElement &element); void removeAllChilds(QDomElement &element);
/** /**
* @brief CreateEmptyFile * @brief CreateEmptyFile create minimal empty file.
*/ */
void CreateEmptyFile(); void CreateEmptyFile();
/** /**
* @brief ChangeActivDraw * @brief ChangeActivDraw set new pattern peace name.
* @param name * @param name new name.
* @param parse parser file mode. * @param parse parser file mode.
*/ */
void ChangeActivDraw(const QString& name, const Document::Documents &parse = Document::FullParse); void ChangeActivDraw(const QString& name, const Document::Documents &parse = Document::FullParse);
/** /**
* @brief GetNameActivDraw * @brief GetNameActivDraw return current pattern peace name.
* @return * @return pattern peace name.
*/ */
inline QString GetNameActivDraw() const {return nameActivDraw;} inline QString GetNameActivDraw() const {return nameActivDraw;}
/** /**
* @brief GetActivDrawElement * @brief GetActivDrawElement return draw tag for current pattern peace.
* @param element * @param element draw tag.
* @return * @return true if found.
*/ */
bool GetActivDrawElement(QDomElement &element); bool GetActivDrawElement(QDomElement &element);
/** /**
* @brief GetActivCalculationElement * @brief GetActivCalculationElement return calculation tag for current pattern peace.
* @param element * @param element calculation tag.
* @return * @return true if found.
*/ */
bool GetActivCalculationElement(QDomElement &element); bool GetActivCalculationElement(QDomElement &element);
/** /**
* @brief GetActivModelingElement * @brief GetActivModelingElement return modeling tag for current pattern peace.
* @param element * @param element modeling tag
* @return * @return true if found.
*/ */
bool GetActivModelingElement(QDomElement &element); bool GetActivModelingElement(QDomElement &element);
/** /**
* @brief GetActivDetailsElement * @brief GetActivDetailsElement return details tag for current pattern peace.
* @param element * @param element details tag.
* @return * @return true if found.
*/ */
bool GetActivDetailsElement(QDomElement &element); bool GetActivDetailsElement(QDomElement &element);
/** /**
* @brief appendDraw * @brief appendDraw add new pattern peace structure to the file.
* @param name * @param name pattern peace name.
* @return * @return true if success.
*/ */
bool appendDraw(const QString& name); bool appendDraw(const QString& name);
/** /**
* @brief SetNameDraw * @brief SetNameDraw change current pattern peace.
* @param name * @param name pattern peace name.
* @return * @return true if success.
*/ */
bool SetNameDraw(const QString& name); bool SetNameDraw(const QString& name);
/** /**
* @brief Parse * @brief Parse parse file.
* @param parse parser file mode. * @param parse parser file mode.
* @param sceneDraw * @param sceneDraw pointer to draw scene.
* @param sceneDetail * @param sceneDetail pointer to details scene.
*/ */
void Parse(const Document::Documents &parse, VMainGraphicsScene *sceneDraw, void Parse(const Document::Documents &parse, VMainGraphicsScene *sceneDraw,
VMainGraphicsScene *sceneDetail); VMainGraphicsScene *sceneDetail);
/** /**
* @brief getTools * @brief getTools return list of tools pointers.
* @return * @return list.
*/ */
inline QHash<qint64, VDataTool*>* getTools() {return &tools;} inline QHash<qint64, VDataTool*>* getTools() {return &tools;}
/**
* @brief getTool return tool from tool list.
* @param id tool id.
* @return tool.
*/
VDataTool* getTool(const qint64 &id); VDataTool* getTool(const qint64 &id);
/** /**
* @brief getHistory * @brief getHistory return list with list of history records.
* @return * @return list of history records.
*/ */
inline QVector<VToolRecord> *getHistory() {return &history;} inline QVector<VToolRecord> *getHistory() {return &history;}
/** /**
* @brief getCursor * @brief getCursor return cursor.
* @return * @return cursor.
*/ */
inline qint64 getCursor() const {return cursor;} inline qint64 getCursor() const {return cursor;}
/** /**
* @brief setCursor * @brief setCursor set cursor.
* @param value * @param value cursor.
*/ */
void setCursor(const qint64 &value); void setCursor(const qint64 &value);
/** /**
* @brief setCurrentData * @brief setCurrentData set current data set.
*/ */
void setCurrentData(); void setCurrentData();
/** /**
* @brief AddTool * @brief AddTool add tool to list tools.
* @param id * @param id tool id.
* @param tool * @param tool tool.
*/ */
void AddTool(const qint64 &id, VDataTool *tool); void AddTool(const qint64 &id, VDataTool *tool);
/** /**
* @brief UpdateToolData * @brief UpdateToolData update tool in list tools.
* @param id * @param id tool id.
* @param data container with variables * @param data container with variables.
*/ */
void UpdateToolData(const qint64 &id, VContainer *data); void UpdateToolData(const qint64 &id, VContainer *data);
/** /**
* @brief IncrementReferens * @brief IncrementReferens increment reference parent objects.
* @param id * @param id parent object id.
*/ */
void IncrementReferens(qint64 id) const; void IncrementReferens(qint64 id) const;
/** /**
* @brief DecrementReferens * @brief DecrementReferens decrement reference parent objects.
* @param id * @param id parent object id.
*/ */
void DecrementReferens(qint64 id) const; void DecrementReferens(qint64 id) const;
/** /**
* @brief TestUniqueId * @brief TestUniqueId test exist unique id in pattern file. Each id must be unique.
*/ */
void TestUniqueId() const; void TestUniqueId() const;
/** /**
* @brief GetParametrLongLong * @brief GetParametrLongLong return long long value of attribute.
* @param domElement * @param domElement tag in xml tree.
* @param name * @param name attribute name.
* @return * @return long long value.
*/ */
qint64 GetParametrLongLong(const QDomElement& domElement, const QString &name, qint64 GetParametrLongLong(const QDomElement& domElement, const QString &name,
const QString &defValue) const; const QString &defValue) const;
/** /**
* @brief GetParametrString * @brief GetParametrString return string value of attribute.
* @param domElement * @param domElement tag in xml tree.
* @param name * @param name attribute name.
* @return * @return attribute value.
*/ */
QString GetParametrString(const QDomElement& domElement, const QString &name, const QString &defValue) const; QString GetParametrString(const QDomElement& domElement, const QString &name, const QString &defValue) const;
/** /**
* @brief GetParametrDouble * @brief GetParametrDouble return double value of attribute.
* @param domElement * @param domElement tag in xml tree.
* @param name * @param name attribute name.
* @return * @return double value.
*/ */
qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue) const; qreal GetParametrDouble(const QDomElement& domElement, const QString &name, const QString &defValue) const;
/**
* @brief SPointActiveDraw return id base point current pattern peace.
* @return id base point.
*/
qint64 SPointActiveDraw(); qint64 SPointActiveDraw();
signals: signals:
/** /**
* @brief ChangedActivDraw disable or enable context menu after change active pattern peace. * @brief ChangedActivDraw change active pattern peace.
* @param newName * @param newName new pattern peace name.
*/ */
void ChangedActivDraw(const QString &newName); void ChangedActivDraw(const QString &newName);
/** /**
@ -243,187 +256,194 @@ signals:
*/ */
void FullUpdateFromFile(); void FullUpdateFromFile();
/** /**
* @brief haveChange * @brief haveChange emit if we have unsaved change.
*/ */
void haveChange(); void haveChange();
/** /**
* @brief ShowTool highlight tool. * @brief ShowTool highlight tool.
* @param id * @param id tool id.
* @param color * @param color highlight color.
* @param enable * @param enable enable or disable highlight.
*/ */
void ShowTool(qint64 id, Qt::GlobalColor color, bool enable); void ShowTool(qint64 id, Qt::GlobalColor color, bool enable);
/** /**
* @brief ChangedCursor * @brief ChangedCursor change cursor position.
* @param id * @param id tool id.
*/ */
void ChangedCursor(qint64 id); void ChangedCursor(qint64 id);
public slots: public slots:
/** /**
* @brief FullUpdateTree * @brief FullUpdateTree lite parse file.
*/ */
void FullUpdateTree(); void FullUpdateTree();
/** /**
* @brief haveLiteChange * @brief haveLiteChange we have unsaved change.
*/ */
void haveLiteChange(); void haveLiteChange();
/** /**
* @brief ShowHistoryTool * @brief ShowHistoryTool hightlight tool.
* @param id * @param id tool id.
* @param color * @param color hightlight color.
* @param enable * @param enable enable or diasable hightlight.
*/ */
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)
/** /**
* @brief map * @brief map use for finding element by id.
*/ */
QHash<QString, QDomElement> map; QHash<QString, QDomElement> map;
/** /**
* @brief nameActivDraw * @brief nameActivDraw name current pattern peace.
*/ */
QString nameActivDraw; QString nameActivDraw;
/** /**
* @brief data container with data * @brief data container with data.
*/ */
VContainer *data; VContainer *data;
/** /**
* @brief tools * @brief tools list with pointer on tools.
*/ */
QHash<qint64, VDataTool*> tools; QHash<qint64, VDataTool*> tools;
/** /**
* @brief history * @brief history history records.
*/ */
QVector<VToolRecord> history; QVector<VToolRecord> history;
/** /**
* @brief cursor * @brief cursor cursor keep id tool after which we will add new tool in file.
*/ */
qint64 cursor; qint64 cursor;
/** /**
* @brief comboBoxDraws * @brief comboBoxDraws combobox with pattern peace names.
*/ */
QComboBox *comboBoxDraws; QComboBox *comboBoxDraws;
/** /**
* @brief mode * @brief mode current draw mode.
*/ */
Draw::Draws *mode; Draw::Draws *mode;
/** /**
* @brief find * @brief find find element by id.
* @param node * @param node node.
* @param id * @param id id value.
* @return * @return true if found.
*/ */
bool find(const QDomElement &node, const QString& id); bool find(const QDomElement &node, const QString& id);
/** /**
* @brief CheckNameDraw * @brief CheckNameDraw check if exist pattern peace with this name.
* @param name * @param name pattern peace name.
* @return * @return true if exist.
*/ */
bool CheckNameDraw(const QString& name) const; bool CheckNameDraw(const QString& name) const;
/** /**
* @brief SetActivDraw * @brief SetActivDraw set current pattern peace.
* @param name * @param name pattern peace name.
*/ */
void SetActivDraw(const QString& name); void SetActivDraw(const QString& name);
/** /**
* @brief GetActivNodeElement * @brief GetActivNodeElement find element in current pattern peace by name.
* @param name * @param name name tag.
* @param element * @param element element.
* @return * @return true if found.
*/ */
bool GetActivNodeElement(const QString& name, QDomElement& element); bool GetActivNodeElement(const QString& name, QDomElement& element);
/** /**
* @brief ParseDrawElement * @brief ParseDrawElement parse draw tag.
* @param sceneDraw * @param sceneDraw draw scene.
* @param sceneDetail * @param sceneDetail details scene.
* @param node * @param node node.
* @param parse parser file mode. * @param parse parser file mode.
*/ */
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);
/** /**
* @brief ParseDrawMode * @brief ParseDrawMode parse draw tag with draw mode.
* @param sceneDraw * @param sceneDraw draw scene.
* @param sceneDetail * @param sceneDetail details scene.
* @param node * @param node node.
* @param parse parser file mode. * @param parse parser file mode.
* @param mode * @param mode draw mode.
*/ */
void ParseDrawMode(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail, void ParseDrawMode(VMainGraphicsScene *sceneDraw, VMainGraphicsScene *sceneDetail,
const QDomNode& node, const Document::Documents &parse, const Draw::Draws &mode); const QDomNode& node, const Document::Documents &parse, const Draw::Draws &mode);
/** /**
* @brief ParseDetailElement * @brief ParseDetailElement parse detail tag.
* @param sceneDetail * @param sceneDetail detail scene.
* @param domElement * @param domElement tag in xml tree.
* @param parse parser file mode. * @param parse parser file mode.
*/ */
void ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDomElement &domElement, void ParseDetailElement(VMainGraphicsScene *sceneDetail, const QDomElement &domElement,
const Document::Documents &parse); const Document::Documents &parse);
/** /**
* @brief ParseDetails * @brief ParseDetails parse details tag.
* @param sceneDetail * @param sceneDetail detail scene.
* @param domElement * @param domElement tag in xml tree.
* @param parse parser file mode. * @param parse parser file mode.
*/ */
void ParseDetails(VMainGraphicsScene *sceneDetail, const QDomElement &domElement, void ParseDetails(VMainGraphicsScene *sceneDetail, const QDomElement &domElement,
const Document::Documents &parse); const Document::Documents &parse);
/** /**
* @brief ParsePointElement * @brief ParsePointElement parse point tag.
* @param scene * @param scene scene.
* @param domElement * @param domElement tag in xml tree.
* @param parse parser file mode. * @param parse parser file mode.
* @param type * @param type type of point.
* @param mode * @param mode draw mode.
*/ */
void ParsePointElement(VMainGraphicsScene *scene, const QDomElement& domElement, void ParsePointElement(VMainGraphicsScene *scene, const QDomElement& domElement,
const Document::Documents &parse, const QString &type); const Document::Documents &parse, const QString &type);
/** /**
* @brief ParseLineElement * @brief ParseLineElement parse line tag.
* @param scene * @param scene scene.
* @param domElement * @param domElement tag in xml tree.
* @param parse parser file mode. * @param parse parser file mode.
* @param mode * @param mode draw mode.
*/ */
void ParseLineElement(VMainGraphicsScene *scene, const QDomElement& domElement, void ParseLineElement(VMainGraphicsScene *scene, const QDomElement& domElement,
const Document::Documents &parse); const Document::Documents &parse);
/** /**
* @brief ParseSplineElement * @brief ParseSplineElement parse spline tag.
* @param scene * @param scene scene.
* @param domElement * @param domElement tag in xml tree.
* @param parse parser file mode. * @param parse parser file mode.
* @param type * @param type type of spline.
* @param mode * @param mode draw mode.
*/ */
void ParseSplineElement(VMainGraphicsScene *scene, const QDomElement& domElement, void ParseSplineElement(VMainGraphicsScene *scene, const QDomElement& domElement,
const Document::Documents &parse, const QString& type); const Document::Documents &parse, const QString& type);
/** /**
* @brief ParseArcElement * @brief ParseArcElement parse arc tag.
* @param scene * @param scene scene.
* @param domElement * @param domElement tag in xml tree.
* @param parse parser file mode. * @param parse parser file mode.
* @param type * @param type type of spline.
* @param mode * @param mode draw mode.
*/ */
void ParseArcElement(VMainGraphicsScene *scene, const QDomElement& domElement, void ParseArcElement(VMainGraphicsScene *scene, const QDomElement& domElement,
const Document::Documents &parse, const QString& type); const Document::Documents &parse, const QString& type);
/**
* @brief ParseToolsElement parse tools tag.
* @param scene scene.
* @param domElement tag in xml tree.
* @param parse parser file mode.
* @param type type of spline.
*/
void ParseToolsElement(VMainGraphicsScene *scene, const QDomElement& domElement, void ParseToolsElement(VMainGraphicsScene *scene, const QDomElement& domElement,
const Document::Documents &parse, const QString& type); const Document::Documents &parse, const QString& type);
/** /**
* @brief ParseIncrementsElement * @brief ParseIncrementsElement parse increments tag.
* @param node * @param node tag in xml tree.
*/ */
void ParseIncrementsElement(const QDomNode& node); void ParseIncrementsElement(const QDomNode& node);
/** /**
* @brief GetParametrId * @brief GetParametrId return value id attribute.
* @param domElement * @param domElement tag in xml tree.
* @return * @return id value.
*/ */
qint64 GetParametrId(const QDomElement& domElement) const; qint64 GetParametrId(const QDomElement& domElement) const;
/** /**
* @brief CollectId * @brief CollectId recursive function, try find id attribute in file. Throw exclusion if find not unique.
* @param node * @param node tag in xml tree.
* @param vector * @param vector list with ids.
*/ */
void CollectId(const QDomElement &node, QVector<qint64> &vector)const; void CollectId(const QDomElement &node, QVector<qint64> &vector)const;
}; };

View file

@ -34,63 +34,63 @@
#include <QString> #include <QString>
/** /**
* @brief The VToolRecord class * @brief The VToolRecord class record about tool in history.
*/ */
class VToolRecord class VToolRecord
{ {
public: public:
/** /**
* @brief VToolRecord * @brief VToolRecord default constructor.
*/ */
VToolRecord(); VToolRecord();
/** /**
* @brief VToolRecord * @brief VToolRecord constructor.
* @param id * @param id tool id.
* @param typeTool * @param typeTool tool type.
* @param nameDraw * @param nameDraw pattern peace name.
*/ */
VToolRecord(const qint64 &id, const Tool::Tools &typeTool, const QString &nameDraw); VToolRecord(const qint64 &id, const Tool::Tools &typeTool, const QString &nameDraw);
/** /**
* @brief getId * @brief getId return tool id.
* @return * @return id.
*/ */
inline qint64 getId() const {return id;} inline qint64 getId() const {return id;}
/** /**
* @brief setId * @brief setId set tool id.
* @param value * @param value id.
*/ */
inline void setId(const qint64 &value) {id = value;} inline void setId(const qint64 &value) {id = value;}
/** /**
* @brief getTypeTool * @brief getTypeTool return tool type.
* @return * @return tool type.
*/ */
inline Tool::Tools getTypeTool() const {return typeTool;} inline Tool::Tools getTypeTool() const {return typeTool;}
/** /**
* @brief setTypeTool * @brief setTypeTool set tool type.
* @param value * @param value tool type.
*/ */
inline void setTypeTool(const Tool::Tools &value) {typeTool = value;} inline void setTypeTool(const Tool::Tools &value) {typeTool = value;}
/** /**
* @brief getNameDraw * @brief getNameDraw return pattern peace name.
* @return * @return pattern peace name.
*/ */
inline QString getNameDraw() const {return nameDraw;} inline QString getNameDraw() const {return nameDraw;}
/** /**
* @brief setNameDraw * @brief setNameDraw set pattern peace name.
* @param value * @param value pattern peace name.
*/ */
inline void setNameDraw(const QString &value) {nameDraw = value;} inline void setNameDraw(const QString &value) {nameDraw = value;}
private: private:
/** /**
* @brief id * @brief id tool id.
*/ */
qint64 id; qint64 id;
/** /**
* @brief typeTool * @brief typeTool tool type.
*/ */
Tool::Tools typeTool; Tool::Tools typeTool;
/** /**
* @brief nameDraw * @brief nameDraw pattern peace name.
*/ */
QString nameDraw; QString nameDraw;
}; };