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
*/
inline void ClearLineAngles() {lineAngles.clear();}
inline void ClearDetails() {details.clear();}
/**
* @brief SetSize set value of size
* @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.checkBoxClosed, &QCheckBox::clicked, this, &DialogDetail::ClickedClosed);
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)
@ -80,6 +82,7 @@ void DialogDetail::ChoosedObject(qint64 id, const Scene::Scenes &type)
qWarning()<<tr("Got wrong scene object. Ignore.");
break;
}
ui.toolButtonDelete->setEnabled(true);
this->show();
}
}
@ -170,6 +173,7 @@ void DialogDetail::setDetails(const VDetail &value)
ui.doubleSpinBoxSeams->setValue(details.getWidth());
ui.listWidget->setCurrentRow(0);
ui.listWidget->setFocus(Qt::OtherFocusReason);
ui.toolButtonDelete->setEnabled(true);
}
void DialogDetail::BiasXChanged(qreal d)
@ -215,3 +219,9 @@ void DialogDetail::ObjectChanged(int row)
ui.doubleSpinBoxBiasX->setValue(toMM(node.getMx()));
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
*/
void ObjectChanged(int row);
void DeleteItem();
private:
/**
* @brief ui keeps information about user interface

View file

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

View file

@ -232,6 +232,29 @@ VDetail VDetail::RemoveEdge(const ptrdiff_t &index) const
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> list;

View file

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

View file

@ -39,6 +39,40 @@ VAbstractNode::VAbstractNode(VDomDocument *doc, VContainer *data, const qint64 &
_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)
{
QDomElement modelingElement;

View file

@ -54,6 +54,7 @@ public:
*/
static const QString AttrIdObject;
static const QString AttrIdTool;
virtual void DeleteNode();
protected:
/**
* @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()
{
RefreshGeometry();

View file

@ -70,6 +70,7 @@ public:
* @brief ToolType
*/
static const QString ToolType;
virtual void DeleteNode();
public slots:
/**
* @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()
{
RefreshPointGeometry(*VAbstractTool::data.GeometricObject<const VPointF *>(id));

View file

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

View file

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

View file

@ -72,6 +72,7 @@ public:
* @brief ToolType
*/
static const QString ToolType;
virtual void DeleteNode();
public slots:
/**
* @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()
{
RefreshGeometry();

View file

@ -71,6 +71,7 @@ public:
* @brief ToolType
*/
static const QString ToolType;
virtual void DeleteNode();
public slots:
/**
* @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)
{
if (_referens <= 1)
@ -198,7 +199,8 @@ void VAbstractTool::DeleteTool(QGraphicsItem *tool)
{
scene->removeItem(tool);//remove form scene
}
emit toolhaveChange();//set enabled save button
doc->FullUpdateTree();
//emit toolhaveChange();//set enabled save button
}
else
{

View file

@ -185,6 +185,17 @@ void VToolDetail::FullUpdateFromGui(int result)
{
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();
}
}

View file

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