Refactoring. More good looking code.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2015-02-11 12:43:50 +02:00
parent f6e511e43c
commit 28f806a779
28 changed files with 45 additions and 38 deletions

View File

@ -200,7 +200,7 @@ void DialogHistory::FillTable()
*/ */
QString DialogHistory::Record(const VToolRecord &tool) QString DialogHistory::Record(const VToolRecord &tool)
{ {
const QDomElement domElem = doc->elementById(QString().setNum(tool.getId())); const QDomElement domElem = doc->elementById(tool.getId());
if (domElem.isElement() == false) if (domElem.isElement() == false)
{ {
qDebug()<<"Can't find element by id"<<Q_FUNC_INFO; qDebug()<<"Can't find element by id"<<Q_FUNC_INFO;

View File

@ -678,7 +678,7 @@ void DialogIncrements::clickedToolButtonRemove()
data->RemoveIncrement(itemName->text()); data->RemoveIncrement(itemName->text());
quint32 id = qvariant_cast<quint32>(itemName->data(Qt::UserRole)); quint32 id = qvariant_cast<quint32>(itemName->data(Qt::UserRole));
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(id);
if (domElement.isElement()) if (domElement.isElement())
{ {
QDomNodeList list = doc->elementsByTagName(VPattern::TagIncrements); QDomNodeList list = doc->elementsByTagName(VPattern::TagIncrements);
@ -750,7 +750,7 @@ void DialogIncrements::IncrementChanged ( qint32 row, qint32 column )
const QTableWidgetItem *itemName = ui->tableWidgetIncrement->item(row, 0); const QTableWidgetItem *itemName = ui->tableWidgetIncrement->item(row, 0);
const QTableWidgetItem *item = ui->tableWidgetIncrement->item(row, column); const QTableWidgetItem *item = ui->tableWidgetIncrement->item(row, column);
const quint32 id = qvariant_cast<quint32>(itemName->data(Qt::UserRole)); const quint32 id = qvariant_cast<quint32>(itemName->data(Qt::UserRole));
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(id);
if (domElement.isElement() == false) if (domElement.isElement() == false)
{ {
qCDebug(vDialog)<<"Cant't find increment with id = "<<id<<Q_FUNC_INFO; qCDebug(vDialog)<<"Cant't find increment with id = "<<id<<Q_FUNC_INFO;

View File

@ -114,7 +114,7 @@ void VDrawTool::FullUpdateFromGuiApply()
void VDrawTool::SaveDialogChange() void VDrawTool::SaveDialogChange()
{ {
qCDebug(vTool)<<"Saving tool options after using dialog"; qCDebug(vTool)<<"Saving tool options after using dialog";
QDomElement oldDomElement = doc->elementById(QString().setNum(id)); QDomElement oldDomElement = doc->elementById(id);
if (oldDomElement.isElement()) if (oldDomElement.isElement())
{ {
QDomElement newDomElement = oldDomElement.cloneNode().toElement(); QDomElement newDomElement = oldDomElement.cloneNode().toElement();
@ -148,7 +148,7 @@ void VDrawTool::AddToFile()
*/ */
void VDrawTool::RefreshDataInFile() void VDrawTool::RefreshDataInFile()
{ {
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(id);
if (domElement.isElement()) if (domElement.isElement())
{ {
QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(id); QSharedPointer<VGObject> obj = VAbstractTool::data.GetGObject(id);
@ -176,7 +176,7 @@ QColor VDrawTool::CorrectColor(const QColor &color) const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VDrawTool::ReadAttributes() void VDrawTool::ReadAttributes()
{ {
const QDomElement domElement = doc->elementById(QString().setNum(id)); const QDomElement domElement = doc->elementById(id);
if (domElement.isElement()) if (domElement.isElement())
{ {
ReadToolAttributes(domElement); ReadToolAttributes(domElement);

View File

@ -146,7 +146,7 @@ void VToolCut::FullUpdateCurveFromFile(const QString &attrCurve)
{ {
Q_ASSERT_X(attrCurve.isEmpty() == false, Q_FUNC_INFO, "attribute name is empty"); Q_ASSERT_X(attrCurve.isEmpty() == false, Q_FUNC_INFO, "attribute name is empty");
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(id);
if (domElement.isElement()) if (domElement.isElement())
{ {
formula = domElement.attribute(AttrLength, ""); formula = domElement.attribute(AttrLength, "");

View File

@ -275,7 +275,7 @@ void VToolLine::AddToFile()
*/ */
void VToolLine::RefreshDataInFile() void VToolLine::RefreshDataInFile()
{ {
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(id);
if (domElement.isElement()) if (domElement.isElement())
{ {
QSharedPointer<VGObject> obj = QSharedPointer<VGObject> (); QSharedPointer<VGObject> obj = QSharedPointer<VGObject> ();

View File

@ -335,7 +335,7 @@ void VToolSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
*/ */
void VToolSplinePath::RefreshDataInFile() void VToolSplinePath::RefreshDataInFile()
{ {
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(id);
if (domElement.isElement() == false) if (domElement.isElement() == false)
{ {
qDebug()<<"Can't find element with id="<<id<<"in pattern file"; qDebug()<<"Can't find element with id="<<id<<"in pattern file";

View File

@ -99,7 +99,7 @@ void VAbstractNode::decrementReferens()
if (_referens <= 0) if (_referens <= 0)
{ {
doc->DecrementReferens(idNode); doc->DecrementReferens(idNode);
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(id);
if (domElement.isElement()) if (domElement.isElement())
{ {
QDomNode element = domElement.parentNode(); QDomNode element = domElement.parentNode();

View File

@ -164,7 +164,7 @@ void VNodeArc::AddToFile()
*/ */
void VNodeArc::RefreshDataInFile() void VNodeArc::RefreshDataInFile()
{ {
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(id);
if (domElement.isElement()) if (domElement.isElement())
{ {
doc->SetAttribute(domElement, AttrIdObject, idNode); doc->SetAttribute(domElement, AttrIdObject, idNode);

View File

@ -180,7 +180,7 @@ void VNodePoint::AddToFile()
void VNodePoint::RefreshDataInFile() void VNodePoint::RefreshDataInFile()
{ {
const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id); const QSharedPointer<VPointF> point = VAbstractTool::data.GeometricObject<VPointF>(id);
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(id);
if (domElement.isElement()) if (domElement.isElement())
{ {
doc->SetAttribute(domElement, AttrIdObject, idNode); doc->SetAttribute(domElement, AttrIdObject, idNode);
@ -253,7 +253,7 @@ void VNodePoint::NameChangePosition(const QPointF &pos)
*/ */
void VNodePoint::UpdateNamePosition(qreal mx, qreal my) void VNodePoint::UpdateNamePosition(qreal mx, qreal my)
{ {
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(id);
if (domElement.isElement()) if (domElement.isElement())
{ {
doc->SetAttribute(domElement, AttrMx, QString().setNum(qApp->fromPixel(mx))); doc->SetAttribute(domElement, AttrMx, QString().setNum(qApp->fromPixel(mx)));

View File

@ -167,7 +167,7 @@ void VNodeSpline::AddToFile()
*/ */
void VNodeSpline::RefreshDataInFile() void VNodeSpline::RefreshDataInFile()
{ {
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(id);
if (domElement.isElement()) if (domElement.isElement())
{ {
doc->SetAttribute(domElement, AttrIdObject, QString().setNum(idNode)); doc->SetAttribute(domElement, AttrIdObject, QString().setNum(idNode));

View File

@ -170,7 +170,7 @@ void VNodeSplinePath::AddToFile()
*/ */
void VNodeSplinePath::RefreshDataInFile() void VNodeSplinePath::RefreshDataInFile()
{ {
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(id);
if (domElement.isElement()) if (domElement.isElement())
{ {
doc->SetAttribute(domElement, AttrIdObject, QString().setNum(idNode)); doc->SetAttribute(domElement, AttrIdObject, QString().setNum(idNode));

View File

@ -310,7 +310,7 @@ int VAbstractTool::ConfirmDeletion()
void VAbstractTool::SaveOption(QSharedPointer<VGObject> &obj) void VAbstractTool::SaveOption(QSharedPointer<VGObject> &obj)
{ {
qCDebug(vTool)<<"Saving tool options"; qCDebug(vTool)<<"Saving tool options";
QDomElement oldDomElement = doc->elementById(QString().setNum(id)); QDomElement oldDomElement = doc->elementById(id);
if (oldDomElement.isElement()) if (oldDomElement.isElement())
{ {
QDomElement newDomElement = oldDomElement.cloneNode().toElement(); QDomElement newDomElement = oldDomElement.cloneNode().toElement();

View File

@ -304,7 +304,7 @@ void VToolDetail::AddToFile()
*/ */
void VToolDetail::RefreshDataInFile() void VToolDetail::RefreshDataInFile()
{ {
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(id);
if (domElement.isElement()) if (domElement.isElement())
{ {
VDetail det = VAbstractTool::data.GetDetail(id); VDetail det = VAbstractTool::data.GetDetail(id);

View File

@ -750,7 +750,7 @@ void VToolUnionDetails::AddToFile()
*/ */
void VToolUnionDetails::RefreshDataInFile() void VToolUnionDetails::RefreshDataInFile()
{ {
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(id);
if (domElement.isElement()) if (domElement.isElement())
{ {
doc->SetAttribute(domElement, AttrIndexD1, indexD1); doc->SetAttribute(domElement, AttrIndexD1, indexD1);

View File

@ -50,7 +50,7 @@ void AddDet::undo()
QDomElement element; QDomElement element;
if (doc->GetActivNodeElement(VPattern::TagDetails, element)) if (doc->GetActivNodeElement(VPattern::TagDetails, element))
{ {
QDomElement domElement = doc->elementById(QString().setNum(nodeId)); QDomElement domElement = doc->elementById(nodeId);
if (domElement.isElement()) if (domElement.isElement())
{ {
if (element.removeChild(domElement).isNull()) if (element.removeChild(domElement).isNull())

View File

@ -49,7 +49,7 @@ void AddDetNode::undo()
QDomElement modelingElement; QDomElement modelingElement;
if (doc->GetActivNodeElement(VPattern::TagModeling, modelingElement)) if (doc->GetActivNodeElement(VPattern::TagModeling, modelingElement))
{ {
QDomElement domElement = doc->elementById(QString().setNum(nodeId)); QDomElement domElement = doc->elementById(nodeId);
if (domElement.isElement()) if (domElement.isElement())
{ {
if (modelingElement.removeChild(domElement).isNull()) if (modelingElement.removeChild(domElement).isNull())

View File

@ -56,7 +56,7 @@ void AddToCalc::undo()
QDomElement calcElement; QDomElement calcElement;
if (doc->GetActivNodeElement(VPattern::TagCalculation, calcElement)) if (doc->GetActivNodeElement(VPattern::TagCalculation, calcElement))
{ {
QDomElement domElement = doc->elementById(QString().setNum(nodeId)); QDomElement domElement = doc->elementById(nodeId);
if (domElement.isElement()) if (domElement.isElement())
{ {
if (calcElement.removeChild(domElement).isNull()) if (calcElement.removeChild(domElement).isNull())
@ -102,7 +102,7 @@ void AddToCalc::redo()
} }
else else
{ {
QDomElement refElement = doc->elementById(QString().setNum(cursor)); QDomElement refElement = doc->elementById(cursor);
if (refElement.isElement()) if (refElement.isElement())
{ {
calcElement.insertAfter(xml, refElement); calcElement.insertAfter(xml, refElement);

View File

@ -49,7 +49,7 @@ void AddUnionDetails::undo()
QDomElement modelingElement; QDomElement modelingElement;
if (doc->GetActivNodeElement(VPattern::TagModeling, modelingElement)) if (doc->GetActivNodeElement(VPattern::TagModeling, modelingElement))
{ {
QDomElement domElement = doc->elementById(QString().setNum(nodeId)); QDomElement domElement = doc->elementById(nodeId);
if (domElement.isElement()) if (domElement.isElement())
{ {
if (modelingElement.removeChild(domElement).isNull()) if (modelingElement.removeChild(domElement).isNull())

View File

@ -36,7 +36,7 @@ DeleteDetail::DeleteDetail(VPattern *doc, quint32 id, QUndoCommand *parent)
{ {
setText(tr("Delete tool")); setText(tr("Delete tool"));
nodeId = id; nodeId = id;
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(id);
if (domElement.isElement()) if (domElement.isElement())
{ {
xml = domElement.cloneNode().toElement(); xml = domElement.cloneNode().toElement();
@ -77,7 +77,7 @@ void DeleteDetail::redo()
{ {
qCDebug(vUndo)<<"Redo."; qCDebug(vUndo)<<"Redo.";
QDomElement domElement = doc->elementById(QString().setNum(nodeId)); QDomElement domElement = doc->elementById(nodeId);
if (domElement.isElement()) if (domElement.isElement())
{ {
parentNode.removeChild(domElement); parentNode.removeChild(domElement);

View File

@ -42,7 +42,7 @@ MoveDetail::MoveDetail(VPattern *doc, const double &x, const double &y, const qu
nodeId = id; nodeId = id;
SCASSERT(scene != nullptr); SCASSERT(scene != nullptr);
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(id);
if (domElement.isElement()) if (domElement.isElement())
{ {
oldX = qApp->toPixel(doc->GetParametrDouble(domElement, VAbstractTool::AttrMx, "0.0")); oldX = qApp->toPixel(doc->GetParametrDouble(domElement, VAbstractTool::AttrMx, "0.0"));
@ -64,7 +64,7 @@ void MoveDetail::undo()
{ {
qCDebug(vUndo)<<"Undo."; qCDebug(vUndo)<<"Undo.";
QDomElement domElement = doc->elementById(QString().setNum(nodeId)); QDomElement domElement = doc->elementById(nodeId);
if (domElement.isElement()) if (domElement.isElement())
{ {
SaveCoordinates(domElement, oldX, oldY); SaveCoordinates(domElement, oldX, oldY);
@ -86,7 +86,7 @@ void MoveDetail::redo()
{ {
qCDebug(vUndo)<<"Redo."; qCDebug(vUndo)<<"Redo.";
QDomElement domElement = doc->elementById(QString().setNum(nodeId)); QDomElement domElement = doc->elementById(nodeId);
if (domElement.isElement()) if (domElement.isElement())
{ {
SaveCoordinates(domElement, newX, newY); SaveCoordinates(domElement, newX, newY);

View File

@ -46,7 +46,7 @@ MoveLabel::MoveLabel(VPattern *doc, const double &x, const double &y, const quin
qCDebug(vUndo)<<"Label new My"<<newMy; qCDebug(vUndo)<<"Label new My"<<newMy;
SCASSERT(scene != nullptr); SCASSERT(scene != nullptr);
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(id);
if (domElement.isElement()) if (domElement.isElement())
{ {
oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, VAbstractTool::AttrMx, "0.0")); oldMx = qApp->toPixel(doc->GetParametrDouble(domElement, VAbstractTool::AttrMx, "0.0"));
@ -114,7 +114,7 @@ void MoveLabel::Do(double mx, double my)
qCDebug(vUndo)<<"New mx"<<mx; qCDebug(vUndo)<<"New mx"<<mx;
qCDebug(vUndo)<<"New my"<<my; qCDebug(vUndo)<<"New my"<<my;
QDomElement domElement = doc->elementById(QString().setNum(nodeId)); QDomElement domElement = doc->elementById(nodeId);
if (domElement.isElement()) if (domElement.isElement())
{ {
doc->SetAttribute(domElement, VAbstractTool::AttrMx, QString().setNum(qApp->fromPixel(mx))); doc->SetAttribute(domElement, VAbstractTool::AttrMx, QString().setNum(qApp->fromPixel(mx)));

View File

@ -88,7 +88,7 @@ int MoveSpline::id() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MoveSpline::Do(const VSpline &spl) void MoveSpline::Do(const VSpline &spl)
{ {
QDomElement domElement = doc->elementById(QString().setNum(nodeId)); QDomElement domElement = doc->elementById(nodeId);
if (domElement.isElement()) if (domElement.isElement())
{ {
doc->SetAttribute(domElement, VAbstractTool::AttrAngle1, QString().setNum(spl.GetAngle1())); doc->SetAttribute(domElement, VAbstractTool::AttrAngle1, QString().setNum(spl.GetAngle1()));

View File

@ -86,7 +86,7 @@ int MoveSplinePath::id() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MoveSplinePath::Do(const VSplinePath &splPath) void MoveSplinePath::Do(const VSplinePath &splPath)
{ {
QDomElement domElement = doc->elementById(QString().setNum(nodeId)); QDomElement domElement = doc->elementById(nodeId);
if (domElement.isElement()) if (domElement.isElement())
{ {
doc->SetAttribute(domElement, VToolSplinePath::AttrKCurve, QString().setNum(splPath.GetKCurve())); doc->SetAttribute(domElement, VToolSplinePath::AttrKCurve, QString().setNum(splPath.GetKCurve()));

View File

@ -46,7 +46,7 @@ MoveSPoint::MoveSPoint(VPattern *doc, const double &x, const double &y, const qu
qCDebug(vUndo)<<"SPoint newY"<<newY; qCDebug(vUndo)<<"SPoint newY"<<newY;
SCASSERT(scene != nullptr); SCASSERT(scene != nullptr);
QDomElement domElement = doc->elementById(QString().setNum(id)); QDomElement domElement = doc->elementById(id);
if (domElement.isElement()) if (domElement.isElement())
{ {
oldX = qApp->toPixel(doc->GetParametrDouble(domElement, VAbstractTool::AttrX, "0.0")); oldX = qApp->toPixel(doc->GetParametrDouble(domElement, VAbstractTool::AttrX, "0.0"));
@ -114,7 +114,7 @@ void MoveSPoint::Do(double x, double y)
qCDebug(vUndo)<<"Move to x"<<x; qCDebug(vUndo)<<"Move to x"<<x;
qCDebug(vUndo)<<"Move to y"<<y; qCDebug(vUndo)<<"Move to y"<<y;
QDomElement domElement = doc->elementById(QString().setNum(nodeId)); QDomElement domElement = doc->elementById(nodeId);
if (domElement.isElement()) if (domElement.isElement())
{ {
doc->SetAttribute(domElement, VAbstractTool::AttrX, QString().setNum(qApp->fromPixel(x))); doc->SetAttribute(domElement, VAbstractTool::AttrX, QString().setNum(qApp->fromPixel(x)));

View File

@ -48,7 +48,7 @@ void SaveDetailOptions::undo()
{ {
qCDebug(vUndo)<<"Undo."; qCDebug(vUndo)<<"Undo.";
QDomElement domElement = doc->elementById(QString().setNum(nodeId)); QDomElement domElement = doc->elementById(nodeId);
if (domElement.isElement()) if (domElement.isElement())
{ {
SaveDet(domElement, oldDet); SaveDet(domElement, oldDet);
@ -85,7 +85,7 @@ void SaveDetailOptions::redo()
{ {
qCDebug(vUndo)<<"Redo."; qCDebug(vUndo)<<"Redo.";
QDomElement domElement = doc->elementById(QString().setNum(nodeId)); QDomElement domElement = doc->elementById(nodeId);
if (domElement.isElement()) if (domElement.isElement())
{ {
SaveDet(domElement, newDet); SaveDet(domElement, newDet);

View File

@ -48,7 +48,7 @@ void SaveToolOptions::undo()
{ {
qCDebug(vUndo)<<"Undo."; qCDebug(vUndo)<<"Undo.";
QDomElement domElement = doc->elementById(QString().setNum(nodeId)); QDomElement domElement = doc->elementById(nodeId);
if (domElement.isElement()) if (domElement.isElement())
{ {
domElement.parentNode().replaceChild(oldXml, domElement); domElement.parentNode().replaceChild(oldXml, domElement);
@ -67,7 +67,7 @@ void SaveToolOptions::redo()
{ {
qCDebug(vUndo)<<"Redo."; qCDebug(vUndo)<<"Redo.";
QDomElement domElement = doc->elementById(QString().setNum(nodeId)); QDomElement domElement = doc->elementById(nodeId);
if (domElement.isElement()) if (domElement.isElement())
{ {
domElement.parentNode().replaceChild(newXml, domElement); domElement.parentNode().replaceChild(newXml, domElement);

View File

@ -134,6 +134,12 @@ QDomElement VDomDocument::elementById(const QString& id)
return QDomElement(); return QDomElement();
} }
//---------------------------------------------------------------------------------------------------------------------
QDomElement VDomDocument::elementById(quint32 id)
{
return elementById(QString().setNum(id));
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief Removes all children of a given element tag. RENAME: removeAllChildren * @brief Removes all children of a given element tag. RENAME: removeAllChildren

View File

@ -81,6 +81,7 @@ public:
VDomDocument(); VDomDocument();
virtual ~VDomDocument(); virtual ~VDomDocument();
QDomElement elementById(const QString& id); QDomElement elementById(const QString& id);
QDomElement elementById(quint32 id);
void removeAllChilds(QDomElement &element); void removeAllChilds(QDomElement &element);
template <typename T> template <typename T>
/** /**