Merge with feature

--HG--
branch : develop
This commit is contained in:
dismine 2014-01-15 00:08:58 +02:00
commit 7c268f2544
28 changed files with 302 additions and 59 deletions

View File

@ -579,7 +579,6 @@ QVector<QPointF> VContainer::CheckLoops(const QVector<QPointF> &points) const
/*We found loop.*/ /*We found loop.*/
ekvPoints.append(points.at(i)); ekvPoints.append(points.at(i));
ekvPoints.append(crosPoint); ekvPoints.append(crosPoint);
ekvPoints.append(points.at(j+1));
i = j + 2; i = j + 2;
} }
} }
@ -774,7 +773,7 @@ void VContainer::UpdateGObject(qint64 id, VGObject* obj)
UpdateObject(gObjects, id, obj); UpdateObject(gObjects, id, obj);
} }
void VContainer::UpdateDetail(qint64 id, VDetail detail) void VContainer::UpdateDetail(qint64 id, const VDetail &detail)
{ {
Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0"); Q_ASSERT_X(id > 0, Q_FUNC_INFO, "id <= 0");
details[id] = detail; details[id] = detail;

View File

@ -223,7 +223,7 @@ public:
* @param id id of existing detail * @param id id of existing detail
* @param detail detail * @param detail detail
*/ */
void UpdateDetail(qint64 id, VDetail detail); void UpdateDetail(qint64 id, const VDetail &detail);
/** /**
* @brief UpdateStandartTableCell update standart table row by name * @brief UpdateStandartTableCell update standart table row by name
* @param name name of row * @param name name of row
@ -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();
} }
} }
@ -165,9 +168,12 @@ void DialogDetail::setDetails(const VDetail &value)
ui.lineEditNameDetail->setText(details.getName()); ui.lineEditNameDetail->setText(details.getName());
ui.checkBoxSeams->setChecked(details.getSupplement()); ui.checkBoxSeams->setChecked(details.getSupplement());
ui.checkBoxClosed->setChecked(details.getClosed()); ui.checkBoxClosed->setChecked(details.getClosed());
ClickedClosed(details.getClosed());
ClickedSeams(details.getSupplement());
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)
@ -213,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

@ -60,7 +60,7 @@ MainWindow::MainWindow(QWidget *parent)
dialogCutSpline(QSharedPointer<DialogCutSpline>()), dialogCutSplinePath (QSharedPointer<DialogCutSplinePath>()), dialogCutSpline(QSharedPointer<DialogCutSpline>()), dialogCutSplinePath (QSharedPointer<DialogCutSplinePath>()),
dialogUnionDetails(QSharedPointer<DialogUnionDetails>()), dialogCutArc(QSharedPointer<DialogCutArc>()), dialogUnionDetails(QSharedPointer<DialogUnionDetails>()), dialogCutArc(QSharedPointer<DialogCutArc>()),
dialogHistory(0), comboBoxDraws(0), fileName(QString()), changeInFile(false), dialogHistory(0), comboBoxDraws(0), fileName(QString()), changeInFile(false),
mode(Draw::Calculation), currentDrawIndex(0), currentToolBoxIndex(0) mode(Draw::Calculation), currentDrawIndex(0), currentToolBoxIndex(0), drawMode(true)
{ {
ui->setupUi(this); ui->setupUi(this);
static const char * GENERIC_ICON_TO_CHECK = "document-open"; static const char * GENERIC_ICON_TO_CHECK = "document-open";
@ -701,6 +701,7 @@ void MainWindow::ToolBarDraws()
ui->toolBarDraws->addAction(ui->actionLayout); ui->toolBarDraws->addAction(ui->actionLayout);
connect(ui->actionLayout, &QAction::triggered, this, &MainWindow::ActionLayout); connect(ui->actionLayout, &QAction::triggered, this, &MainWindow::ActionLayout);
ui->actionLayout->setEnabled(false);
} }
void MainWindow::currentDrawChanged( int index ) void MainWindow::currentDrawChanged( int index )
@ -709,11 +710,15 @@ void MainWindow::currentDrawChanged( int index )
{ {
doc->setCurrentData(); doc->setCurrentData();
doc->ChangeActivDraw(comboBoxDraws->itemText(index)); doc->ChangeActivDraw(comboBoxDraws->itemText(index));
qint64 id = doc->SPointActiveDraw(); if(drawMode)
if (id != 0)
{ {
const VPointF *p = pattern->GeometricObject<const VPointF *>(id); ArrowTool();
view->centerOn(p->toQPointF()); qint64 id = doc->SPointActiveDraw();
if (id != 0)
{
const VPointF *p = pattern->GeometricObject<const VPointF *>(id);
view->centerOn(p->toQPointF());
}
} }
} }
} }
@ -915,15 +920,22 @@ void MainWindow::ActionDraw(bool checked)
currentScene = sceneDraw; currentScene = sceneDraw;
view->setScene(currentScene); view->setScene(currentScene);
connect(view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor);
RestoreCurrentScene(); RestoreCurrentScene();
mode = Draw::Calculation; mode = Draw::Calculation;
comboBoxDraws->setEnabled(true); comboBoxDraws->setEnabled(true);
comboBoxDraws->setCurrentIndex(currentDrawIndex);//restore current pattern peace comboBoxDraws->setCurrentIndex(currentDrawIndex);//restore current pattern peace
drawMode = true;
SetEnableTool(true); SetEnableTool(true);
doc->setCurrentData(); doc->setCurrentData();
ui->toolBox->setCurrentIndex(currentToolBoxIndex); ui->toolBox->setCurrentIndex(currentToolBoxIndex);
ui->actionHistory->setEnabled(true);
ui->actionLayout->setEnabled(false);
ui->actionOptionDraw->setEnabled(true);
ui->actionNewDraw->setEnabled(true);
} }
else else
{ {
@ -940,16 +952,24 @@ void MainWindow::ActionDetails(bool checked)
currentScene = sceneDetails; currentScene = sceneDetails;
view->setScene(sceneDetails); view->setScene(sceneDetails);
disconnect(view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor);
RestoreCurrentScene(); RestoreCurrentScene();
drawMode = false;
currentDrawIndex = comboBoxDraws->currentIndex();//save current pattern peace currentDrawIndex = comboBoxDraws->currentIndex();//save current pattern peace
comboBoxDraws->setCurrentIndex(comboBoxDraws->count()-1); comboBoxDraws->setCurrentIndex(comboBoxDraws->count()-1);
comboBoxDraws->setEnabled(false); comboBoxDraws->setEnabled(false);
mode = Draw::Modeling; mode = Draw::Modeling;
SetEnableTool(true); SetEnableTool(true);
currentToolBoxIndex = ui->toolBox->currentIndex(); currentToolBoxIndex = ui->toolBox->currentIndex();
ui->toolBox->setCurrentIndex(4); ui->toolBox->setCurrentIndex(4);
ui->actionHistory->setEnabled(false);
ui->actionLayout->setEnabled(true);
ui->actionOptionDraw->setEnabled(false);
ui->actionNewDraw->setEnabled(false);
} }
else else
{ {
@ -1014,10 +1034,26 @@ void MainWindow::ActionOpen()
if (fileName.isEmpty() && changeInFile == false) if (fileName.isEmpty() && changeInFile == false)
{ {
OpenPattern(fName); OpenPattern(fName);
sceneDraw->setSceneRect(QRectF(0, 0, view->contentsRect().width()-view->contentsRect().x(),
view->contentsRect().height()-view->contentsRect().y())); QRectF rect = sceneDraw->itemsBoundingRect();
sceneDetails->setSceneRect(QRectF(0, 0, view->contentsRect().width()-view->contentsRect().x(), //Correct BoundingRect
view->contentsRect().height()-view->contentsRect().y())); rect = QRectF(0, 0, rect.width() + rect.x(), rect.height() + rect.y());
QRect rec = view->contentsRect();
//Correct contentsRect
rec = QRect(0, 0, rec.width() - rec.x(), rec.height() - rec.y());
if(rec.contains(rect.toRect()))
{
sceneDraw->setSceneRect(rec);
sceneDetails->setSceneRect(rec);
}
else
{
rect = rect.united(rec);
sceneDraw->setSceneRect(rect);
sceneDetails->setSceneRect(rect);
}
} }
else else
{ {

View File

@ -511,6 +511,7 @@ private:
Draw::Draws mode; Draw::Draws mode;
qint32 currentDrawIndex; qint32 currentDrawIndex;
qint32 currentToolBoxIndex; qint32 currentToolBoxIndex;
bool drawMode;
/** /**
* @brief ToolBarOption * @brief ToolBarOption
*/ */

View File

@ -115,23 +115,31 @@ QVariant VToolSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change,
QGraphicsScene *sc = this->scene(); QGraphicsScene *sc = this->scene();
QRectF rect = sc->itemsBoundingRect(); QRectF rect = sc->itemsBoundingRect();
//Correct BoundingRect
rect = QRectF(0, 0, rect.width() + rect.x(), rect.height() + rect.y());
QList<QGraphicsView*> list = sc->views(); QList<QGraphicsView*> list = sc->views();
QRect rec = list[0]->contentsRect(); QRect rec0 = list[0]->rect();
//Correct contentsRect rec0 = QRect(0, 0, rec0.width()-2, rec0.height()-2);
rec = QRect(0, 0, rec.width() - rec.x(), rec.height() - rec.y());
if(rec.contains(rect.toRect())) QTransform t = list[0]->transform();
QRectF rec1;
if(t.m11() < 1)
{ {
sc->setSceneRect(rec); rec1 = QRect(0, 0, rec0.width()/t.m11(), rec0.height()/t.m22());
rec1.translate(rec0.center().x()-rec1.center().x(), rec0.center().y()-rec1.center().y());
QPolygonF polygone = list[0]->mapToScene(rec1.toRect());
rec1 = polygone.boundingRect();
} }
else else
{ {
rect = rect.united(rec); rec1 = rec0;
sc->setSceneRect(rect);
} }
rec1 = rec1.united(rect.toRect());
sc->setSceneRect(rec1);
//I don't now why but signal does not work. //I don't now why but signal does not work.
doc->FullUpdateTree(); doc->FullUpdateTree();
} }

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

@ -304,7 +304,7 @@ protected:
* @brief RemoveAllChild * @brief RemoveAllChild
* @param domElement * @param domElement
*/ */
void RemoveAllChild(QDomElement &domElement); void RemoveAllChild(QDomElement &domElement);
virtual void DeleteTool(QGraphicsItem *tool); virtual void DeleteTool(QGraphicsItem *tool);
template <typename T> template <typename T>
/** /**

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();
} }
} }
@ -247,6 +258,34 @@ QVariant VToolDetail::itemChange(QGraphicsItem::GraphicsItemChange change, const
{ {
domElement.setAttribute(AttrMx, QString().setNum(toMM(newPos.x()))); domElement.setAttribute(AttrMx, QString().setNum(toMM(newPos.x())));
domElement.setAttribute(AttrMy, QString().setNum(toMM(newPos.y()))); domElement.setAttribute(AttrMy, QString().setNum(toMM(newPos.y())));
QGraphicsScene *sc = this->scene();
QRectF rect = sc->itemsBoundingRect();
QList<QGraphicsView*> list = sc->views();
QRect rec0 = list[0]->rect();
rec0 = QRect(0, 0, rec0.width()-2, rec0.height()-2);
QTransform t = list[0]->transform();
QRectF rec1;
if(t.m11() < 1)
{
rec1 = QRect(0, 0, rec0.width()/t.m11(), rec0.height()/t.m22());
rec1.translate(rec0.center().x()-rec1.center().x(), rec0.center().y()-rec1.center().y());
QPolygonF polygone = list[0]->mapToScene(rec1.toRect());
rec1 = polygone.boundingRect();
}
else
{
rec1 = rec0;
}
rec1 = rec1.united(rect.toRect());
sc->setSceneRect(rec1);
doc->haveLiteChange(); doc->haveLiteChange();
} }
} }

View File

@ -139,10 +139,10 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContai
BiasRotatePoint(p1, dx, dy, data->GeometricObject<const VPointF *>(pRotate)->toQPointF(), angle); BiasRotatePoint(p1, dx, dy, data->GeometricObject<const VPointF *>(pRotate)->toQPointF(), angle);
qint64 idP1 = data->AddGObject(p1); qint64 idP1 = data->AddGObject(p1);
VPointF p2 = VPointF(spline->GetP2().x(), spline->GetP2().y(), "A", 0, 0); VPointF p2 = VPointF(spline->GetP2());
BiasRotatePoint(&p2, dx, dy, data->GeometricObject<const VPointF *>(pRotate)->toQPointF(), angle); BiasRotatePoint(&p2, dx, dy, data->GeometricObject<const VPointF *>(pRotate)->toQPointF(), angle);
VPointF p3 = VPointF(spline->GetP3().x(), spline->GetP3().y(), "A", 0, 0); VPointF p3 = VPointF(spline->GetP3());
BiasRotatePoint(&p3, dx, dy, data->GeometricObject<const VPointF *>(pRotate)->toQPointF(), angle); BiasRotatePoint(&p3, dx, dy, data->GeometricObject<const VPointF *>(pRotate)->toQPointF(), angle);
VPointF *p4 = new VPointF(spline->GetP4()); VPointF *p4 = new VPointF(spline->GetP4());
@ -150,9 +150,9 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContai
BiasRotatePoint(p4, dx, dy, data->GeometricObject<const VPointF *>(pRotate)->toQPointF(), angle); BiasRotatePoint(p4, dx, dy, data->GeometricObject<const VPointF *>(pRotate)->toQPointF(), angle);
qint64 idP4 = data->AddGObject(p4); qint64 idP4 = data->AddGObject(p4);
VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve()); VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve(), 0,
Draw::Modeling);
Q_ASSERT(spl != 0); Q_ASSERT(spl != 0);
spl->setMode(Draw::Modeling);
idObject = data->AddGObject(spl); idObject = data->AddGObject(spl);
VSpline *spl1 = new VSpline(*spl); VSpline *spl1 = new VSpline(*spl);
@ -208,10 +208,10 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContai
if (i==1) if (i==1)
{ {
path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1(), path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1(),
splinePath->at(i-1).KAsm1())); splinePath->at(i-1).KAsm2()));
} }
path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle1(), path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle2()+180,
splinePath->at(i).KAsm1())); splinePath->at(i).KAsm2()));
} }
while(k>=0) while(k>=0)
{ {
@ -310,9 +310,10 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c
++idCount; ++idCount;
data->UpdateGObject(idDetail+idCount, p4); data->UpdateGObject(idDetail+idCount, p4);
VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve()); VSpline *spl = new VSpline(*p1, p2.toQPointF(), p3.toQPointF(), *p4, spline->GetKcurve(), 0,
Draw::Modeling);
Q_ASSERT(spl != 0); Q_ASSERT(spl != 0);
spl->setMode(Draw::Modeling);
++idCount; ++idCount;
data->UpdateGObject(idDetail+idCount, spl); data->UpdateGObject(idDetail+idCount, spl);
@ -364,10 +365,10 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c
if (i==1) if (i==1)
{ {
path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1(), path->append(VSplinePoint(*p1, splinePath->at(i-1).KAsm1(), spl.GetAngle1(),
splinePath->at(i-1).KAsm1())); splinePath->at(i-1).KAsm2()));
} }
path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle1(), path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle2()+180,
splinePath->at(i).KAsm1())); splinePath->at(i).KAsm2()));
} }
while(k>=0) while(k>=0)

View File

@ -31,10 +31,14 @@
#include <QtWidgets> #include <QtWidgets>
VMainGraphicsScene::VMainGraphicsScene() VMainGraphicsScene::VMainGraphicsScene()
:QGraphicsScene(), horScrollBar(0), verScrollBar(0), scaleFactor(1), _transform(QTransform()){} :QGraphicsScene(), horScrollBar(0), verScrollBar(0), scaleFactor(1), _transform(QTransform())
{
}
VMainGraphicsScene::VMainGraphicsScene(const QRectF & sceneRect, QObject * parent) VMainGraphicsScene::VMainGraphicsScene(const QRectF & sceneRect, QObject * parent)
:QGraphicsScene ( sceneRect, parent ), horScrollBar(0), verScrollBar(0), scaleFactor(1), _transform(QTransform()){} :QGraphicsScene ( sceneRect, parent ), horScrollBar(0), verScrollBar(0), scaleFactor(1), _transform(QTransform())
{
}
void VMainGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event) void VMainGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
{ {

View File

@ -43,48 +43,88 @@ VMainGraphicsView::VMainGraphicsView(QWidget *parent)
void VMainGraphicsView::wheelEvent(QWheelEvent *event) void VMainGraphicsView::wheelEvent(QWheelEvent *event)
{ {
int numDegrees = event->delta() / 8; int numSteps = event->delta() / 8 / 15; // see QWheelEvent documentation
int numSteps = numDegrees / 15; // see QWheelEvent documentation
_numScheduledScalings += numSteps; _numScheduledScalings += numSteps;
if (_numScheduledScalings * numSteps < 0) if (_numScheduledScalings * numSteps < 0)
{ // if user moved the wheel in another direction, we reset { // if user moved the wheel in another direction, we reset
_numScheduledScalings = numSteps; // previously scheduled scalings _numScheduledScalings = numSteps; // previously scheduled scalings
} }
QTimeLine *anim = new QTimeLine(350, this); QTimeLine *anim = new QTimeLine(300, this);
Q_ASSERT(anim != 0); Q_ASSERT(anim != 0);
anim->setUpdateInterval(20); anim->setUpdateInterval(20);
connect(anim, &QTimeLine::valueChanged, this, &VMainGraphicsView::scalingTime); if (QApplication::keyboardModifiers() == Qt::ControlModifier)
{// If you press CTRL this code will be executed
connect(anim, &QTimeLine::valueChanged, this, &VMainGraphicsView::scalingTime);
}
else
{
connect(anim, &QTimeLine::valueChanged, this, &VMainGraphicsView::scrollingTime);
}
connect(anim, &QTimeLine::finished, this, &VMainGraphicsView::animFinished); connect(anim, &QTimeLine::finished, this, &VMainGraphicsView::animFinished);
anim->start(); anim->start();
} }
void VMainGraphicsView::scalingTime(qreal x) void VMainGraphicsView::scalingTime(qreal x)
{
Q_UNUSED(x);
const QPointF p0scene = mapToScene(mapFromGlobal(QCursor::pos()));
qreal factor = 1.0 + static_cast<qreal>(_numScheduledScalings) / 50.0;
scale(factor, factor);
const QPointF p1mouse = mapFromScene(p0scene);
const QPointF move = p1mouse - this->mapFromGlobal(QCursor::pos()); // The move
horizontalScrollBar()->setValue(move.x() + horizontalScrollBar()->value());
verticalScrollBar()->setValue(move.y() + verticalScrollBar()->value());
QGraphicsScene *sc = this->scene();
QRectF rect = sc->itemsBoundingRect();
QRect rec0 = this->rect();
rec0 = QRect(0, 0, rec0.width()-2, rec0.height()-2);
QTransform t = this->transform();
QRectF rec1;
if(t.m11() < 1)
{
rec1 = QRect(0, 0, rec0.width()/t.m11(), rec0.height()/t.m22());
rec1.translate(rec0.center().x()-rec1.center().x(), rec0.center().y()-rec1.center().y());
QPolygonF polygone = this->mapToScene(rec1.toRect());
rec1 = polygone.boundingRect();
}
else
{
rec1 = rec0;
}
rec1 = rec1.united(rect.toRect());
sc->setSceneRect(rec1);
emit NewFactor(factor);
}
void VMainGraphicsView::scrollingTime(qreal x)
{ {
Q_UNUSED(x); Q_UNUSED(x);
qreal factor = 1.0; qreal factor = 1.0;
if (QApplication::keyboardModifiers() == Qt::ControlModifier) if (_numScheduledScalings < 0)
{// If you press CTRL this code will be executed {
factor = 1.0 + static_cast<qreal>(_numScheduledScalings) / 300.0; verticalScrollBar()->setValue(qRound(verticalScrollBar()->value() + factor*3.5));
scale(factor, factor);
emit NewFactor(factor); emit NewFactor(factor);
} }
else else
{ {
if (_numScheduledScalings < 0) // if (verticalScrollBar()->value() > 0)
{ // {
verticalScrollBar()->setValue(qRound(verticalScrollBar()->value() + factor*3.5)); verticalScrollBar()->setValue(qRound(verticalScrollBar()->value() - factor*3.5));
emit NewFactor(factor); emit NewFactor(factor);
} // }
else
{
if (verticalScrollBar()->value() > 0)
{
verticalScrollBar()->setValue(qRound(verticalScrollBar()->value() - factor*3.5));
emit NewFactor(factor);
}
}
} }
} }

View File

@ -55,6 +55,7 @@ public slots:
* @param x * @param x
*/ */
void scalingTime(qreal x); void scalingTime(qreal x);
void scrollingTime(qreal x);
/** /**
* @brief animFinished * @brief animFinished
*/ */

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();