Delete nodes from detail. Fix for union details.

--HG--
branch : feature
This commit is contained in:
dismine 2014-01-13 02:48:31 +02:00
parent 1cffddc672
commit 666dd664eb
19 changed files with 126 additions and 3 deletions

View File

@ -279,6 +279,7 @@ public:
* @brief ClearLineAngles clear angles of lines * @brief ClearLineAngles clear angles of lines
*/ */
inline void ClearLineAngles() {lineAngles.clear();} inline void ClearLineAngles() {lineAngles.clear();}
inline void ClearDetails() {details.clear();}
/** /**
* @brief SetSize set value of size * @brief SetSize set value of size
* @param size value of size in mm * @param size value of size in mm

View File

@ -56,6 +56,8 @@ DialogDetail::DialogDetail(const VContainer *data, QWidget *parent)
connect(ui.checkBoxSeams, &QCheckBox::clicked, this, &DialogDetail::ClickedSeams); connect(ui.checkBoxSeams, &QCheckBox::clicked, this, &DialogDetail::ClickedSeams);
connect(ui.checkBoxClosed, &QCheckBox::clicked, this, &DialogDetail::ClickedClosed); connect(ui.checkBoxClosed, &QCheckBox::clicked, this, &DialogDetail::ClickedClosed);
connect(ui.lineEditNameDetail, &QLineEdit::textChanged, this, &DialogDetail::NamePointChanged); connect(ui.lineEditNameDetail, &QLineEdit::textChanged, this, &DialogDetail::NamePointChanged);
connect(ui.toolButtonDelete, &QToolButton::clicked, this, &DialogDetail::DeleteItem);
} }
void DialogDetail::ChoosedObject(qint64 id, const Scene::Scenes &type) void DialogDetail::ChoosedObject(qint64 id, const Scene::Scenes &type)
@ -80,6 +82,7 @@ void DialogDetail::ChoosedObject(qint64 id, const Scene::Scenes &type)
qWarning()<<tr("Got wrong scene object. Ignore."); qWarning()<<tr("Got wrong scene object. Ignore.");
break; break;
} }
ui.toolButtonDelete->setEnabled(true);
this->show(); this->show();
} }
} }
@ -170,6 +173,7 @@ void DialogDetail::setDetails(const VDetail &value)
ui.doubleSpinBoxSeams->setValue(details.getWidth()); ui.doubleSpinBoxSeams->setValue(details.getWidth());
ui.listWidget->setCurrentRow(0); ui.listWidget->setCurrentRow(0);
ui.listWidget->setFocus(Qt::OtherFocusReason); ui.listWidget->setFocus(Qt::OtherFocusReason);
ui.toolButtonDelete->setEnabled(true);
} }
void DialogDetail::BiasXChanged(qreal d) void DialogDetail::BiasXChanged(qreal d)
@ -215,3 +219,9 @@ void DialogDetail::ObjectChanged(int row)
ui.doubleSpinBoxBiasX->setValue(toMM(node.getMx())); ui.doubleSpinBoxBiasX->setValue(toMM(node.getMx()));
ui.doubleSpinBoxBiasY->setValue(toMM(node.getMy())); ui.doubleSpinBoxBiasY->setValue(toMM(node.getMy()));
} }
void DialogDetail::DeleteItem()
{
qint32 row = ui.listWidget->currentRow();
delete ui.listWidget->item( row );
}

View File

@ -91,6 +91,7 @@ public slots:
* @param row number of row * @param row number of row
*/ */
void ObjectChanged(int row); void ObjectChanged(int row);
void DeleteItem();
private: private:
/** /**
* @brief ui keeps information about user interface * @brief ui keeps information about user interface

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>544</width> <width>565</width>
<height>327</height> <height>324</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -211,6 +211,16 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QToolButton" name="toolButtonDelete">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Delete</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

View File

@ -232,6 +232,29 @@ VDetail VDetail::RemoveEdge(const ptrdiff_t &index) const
return det; return det;
} }
QList<qint64> VDetail::Missing(const VDetail &det) const
{
QList<qint64> list;
if(nodes.size() == det.CountNode())
{
return list;
}
qint32 j = 0;
for(qint32 i = 0; i < nodes.size(); ++i)
{
if(nodes[i].getId() == det.at(j).getId())
{
++j;
}
else
{
list.append(nodes[i].getId());
}
}
return list;
}
QVector<VNodeDetail> VDetail::listNodePoint() const QVector<VNodeDetail> VDetail::listNodePoint() const
{ {
QVector<VNodeDetail> list; QVector<VNodeDetail> list;

View File

@ -183,6 +183,7 @@ public:
ptrdiff_t Edge(const qint64 &p1, const qint64 &p2)const; ptrdiff_t Edge(const qint64 &p1, const qint64 &p2)const;
void NodeOnEdge(const ptrdiff_t &index, VNodeDetail &p1, VNodeDetail &p2)const; void NodeOnEdge(const ptrdiff_t &index, VNodeDetail &p1, VNodeDetail &p2)const;
VDetail RemoveEdge(const ptrdiff_t &index) const; VDetail RemoveEdge(const ptrdiff_t &index) const;
QList<qint64> Missing(const VDetail &det) const;
private: private:
qint64 _id; qint64 _id;
/** /**

View File

@ -39,6 +39,40 @@ VAbstractNode::VAbstractNode(VDomDocument *doc, VContainer *data, const qint64 &
_referens = 0; _referens = 0;
} }
void VAbstractNode::DeleteNode()
{
if (_referens <= 1)
{
//remove from xml file
QDomElement domElement = doc->elementById(QString().setNum(id));
if (domElement.isElement())
{
QDomNode element = domElement.parentNode();
if (element.isNull() == false)
{
if (element.isElement())
{
RemoveReferens();//deincrement referens
element.removeChild(domElement);//remove form file
emit toolhaveChange();//set enabled save button
}
else
{
qWarning()<<"parent isn't element"<<Q_FUNC_INFO;
}
}
else
{
qWarning()<<"parent isNull"<<Q_FUNC_INFO;
}
}
else
{
qWarning()<<"Can't get element by id form file = "<<id<<Q_FUNC_INFO;
}
}
}
void VAbstractNode::AddToModeling(const QDomElement &domElement) void VAbstractNode::AddToModeling(const QDomElement &domElement)
{ {
QDomElement modelingElement; QDomElement modelingElement;

View File

@ -54,6 +54,7 @@ public:
*/ */
static const QString AttrIdObject; static const QString AttrIdObject;
static const QString AttrIdTool; static const QString AttrIdTool;
virtual void DeleteNode();
protected: protected:
/** /**
* @brief idNode * @brief idNode

View File

@ -78,6 +78,12 @@ void VNodeArc::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 idA
} }
} }
void VNodeArc::DeleteNode()
{
VAbstractNode::DeleteNode();
this->setVisible(false);
}
void VNodeArc::FullUpdateFromFile() void VNodeArc::FullUpdateFromFile()
{ {
RefreshGeometry(); RefreshGeometry();

View File

@ -70,6 +70,7 @@ public:
* @brief ToolType * @brief ToolType
*/ */
static const QString ToolType; static const QString ToolType;
virtual void DeleteNode();
public slots: public slots:
/** /**
* @brief FullUpdateFromFile * @brief FullUpdateFromFile

View File

@ -89,6 +89,12 @@ void VNodePoint::Create(VDomDocument *doc, VContainer *data, qint64 id, qint64 i
} }
} }
void VNodePoint::DeleteNode()
{
VAbstractNode::DeleteNode();
this->setVisible(false);
}
void VNodePoint::FullUpdateFromFile() void VNodePoint::FullUpdateFromFile()
{ {
RefreshPointGeometry(*VAbstractTool::data.GeometricObject<const VPointF *>(id)); RefreshPointGeometry(*VAbstractTool::data.GeometricObject<const VPointF *>(id));

View File

@ -71,6 +71,7 @@ public:
* @brief ToolType * @brief ToolType
*/ */
static const QString ToolType; static const QString ToolType;
virtual void DeleteNode();
public slots: public slots:
/** /**
* @brief FullUpdateFromFile * @brief FullUpdateFromFile

View File

@ -81,6 +81,12 @@ VNodeSpline *VNodeSpline::Create(VDomDocument *doc, VContainer *data, qint64 id,
return spl; return spl;
} }
void VNodeSpline::DeleteNode()
{
VAbstractNode::DeleteNode();
this->setVisible(false);
}
void VNodeSpline::FullUpdateFromFile() void VNodeSpline::FullUpdateFromFile()
{ {
RefreshGeometry(); RefreshGeometry();

View File

@ -72,6 +72,7 @@ public:
* @brief ToolType * @brief ToolType
*/ */
static const QString ToolType; static const QString ToolType;
virtual void DeleteNode();
public slots: public slots:
/** /**
* @brief FullUpdateFromFile * @brief FullUpdateFromFile

View File

@ -85,6 +85,12 @@ void VNodeSplinePath::Create(VDomDocument *doc, VContainer *data, qint64 id, qin
} }
} }
void VNodeSplinePath::DeleteNode()
{
VAbstractNode::DeleteNode();
this->setVisible(false);
}
void VNodeSplinePath::FullUpdateFromFile() void VNodeSplinePath::FullUpdateFromFile()
{ {
RefreshGeometry(); RefreshGeometry();

View File

@ -71,6 +71,7 @@ public:
* @brief ToolType * @brief ToolType
*/ */
static const QString ToolType; static const QString ToolType;
virtual void DeleteNode();
public slots: public slots:
/** /**
* @brief FullUpdateFromFile * @brief FullUpdateFromFile

View File

@ -178,6 +178,7 @@ void VAbstractTool::RemoveAllChild(QDomElement &domElement)
} }
} }
//TODO see method deleteNode. I think no need have QGraphicsItem. QObject can delete yourself.
void VAbstractTool::DeleteTool(QGraphicsItem *tool) void VAbstractTool::DeleteTool(QGraphicsItem *tool)
{ {
if (_referens <= 1) if (_referens <= 1)
@ -198,7 +199,8 @@ void VAbstractTool::DeleteTool(QGraphicsItem *tool)
{ {
scene->removeItem(tool);//remove form scene scene->removeItem(tool);//remove form scene
} }
emit toolhaveChange();//set enabled save button doc->FullUpdateTree();
//emit toolhaveChange();//set enabled save button
} }
else else
{ {

View File

@ -185,6 +185,17 @@ void VToolDetail::FullUpdateFromGui(int result)
{ {
AddNode(domElement, det[i]); AddNode(domElement, det[i]);
} }
VDetail detail = VAbstractTool::data.GetDetail(id);
QList<qint64> list = detail.Missing(det);
QHash<qint64, VDataTool*>* tools = doc->getTools();
if(list.size()>0)
{
for(qint32 i = 0; i < list.size(); ++i)
{
VAbstractNode *node = qobject_cast<VAbstractNode *>(tools->value(list[i]));
node->DeleteNode();
}
}
emit FullUpdateTree(); emit FullUpdateTree();
} }
} }

View File

@ -350,6 +350,7 @@ void VDomDocument::Parse(const Document::Documents &parse, VMainGraphicsScene *s
data->ClearLengthArcs(); data->ClearLengthArcs();
data->ClearLengthSplines(); data->ClearLengthSplines();
data->ClearLineAngles(); data->ClearLineAngles();
data->ClearDetails();
history.clear(); history.clear();
QDomElement rootElement = this->documentElement(); QDomElement rootElement = this->documentElement();
QDomNode domNode = rootElement.firstChild(); QDomNode domNode = rootElement.firstChild();