diff --git a/src/container/vcontainer.cpp b/src/container/vcontainer.cpp index 9cc2f9419..ab3b8e490 100644 --- a/src/container/vcontainer.cpp +++ b/src/container/vcontainer.cpp @@ -579,7 +579,6 @@ QVector VContainer::CheckLoops(const QVector &points) const /*We found loop.*/ ekvPoints.append(points.at(i)); ekvPoints.append(crosPoint); - ekvPoints.append(points.at(j+1)); i = j + 2; } } @@ -774,7 +773,7 @@ void VContainer::UpdateGObject(qint64 id, VGObject* 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"); details[id] = detail; diff --git a/src/container/vcontainer.h b/src/container/vcontainer.h index a250d2e2c..c91009ada 100644 --- a/src/container/vcontainer.h +++ b/src/container/vcontainer.h @@ -223,7 +223,7 @@ public: * @param id id of existing 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 * @param name name of row @@ -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 diff --git a/src/dialogs/dialogdetail.cpp b/src/dialogs/dialogdetail.cpp index 7051ed1a6..d0801cfff 100644 --- a/src/dialogs/dialogdetail.cpp +++ b/src/dialogs/dialogdetail.cpp @@ -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()<setEnabled(true); this->show(); } } @@ -165,9 +168,12 @@ void DialogDetail::setDetails(const VDetail &value) ui.lineEditNameDetail->setText(details.getName()); ui.checkBoxSeams->setChecked(details.getSupplement()); ui.checkBoxClosed->setChecked(details.getClosed()); + ClickedClosed(details.getClosed()); + ClickedSeams(details.getSupplement()); ui.doubleSpinBoxSeams->setValue(details.getWidth()); ui.listWidget->setCurrentRow(0); ui.listWidget->setFocus(Qt::OtherFocusReason); + ui.toolButtonDelete->setEnabled(true); } void DialogDetail::BiasXChanged(qreal d) @@ -213,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 ); +} diff --git a/src/dialogs/dialogdetail.h b/src/dialogs/dialogdetail.h index 476b7cc90..4328afef9 100644 --- a/src/dialogs/dialogdetail.h +++ b/src/dialogs/dialogdetail.h @@ -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 diff --git a/src/dialogs/dialogdetail.ui b/src/dialogs/dialogdetail.ui index 3775555bd..6519b344d 100644 --- a/src/dialogs/dialogdetail.ui +++ b/src/dialogs/dialogdetail.ui @@ -6,8 +6,8 @@ 0 0 - 544 - 327 + 565 + 324 @@ -211,6 +211,16 @@ + + + + false + + + Delete + + + diff --git a/src/geometry/vdetail.cpp b/src/geometry/vdetail.cpp index 59dfd3a3a..d771cdd59 100644 --- a/src/geometry/vdetail.cpp +++ b/src/geometry/vdetail.cpp @@ -232,6 +232,29 @@ VDetail VDetail::RemoveEdge(const ptrdiff_t &index) const return det; } +QList VDetail::Missing(const VDetail &det) const +{ + QList 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 VDetail::listNodePoint() const { QVector list; diff --git a/src/geometry/vdetail.h b/src/geometry/vdetail.h index 9edbdfdbf..4825a8a13 100644 --- a/src/geometry/vdetail.h +++ b/src/geometry/vdetail.h @@ -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 Missing(const VDetail &det) const; private: qint64 _id; /** diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 93e9f110e..8f1c41184 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -60,7 +60,7 @@ MainWindow::MainWindow(QWidget *parent) dialogCutSpline(QSharedPointer()), dialogCutSplinePath (QSharedPointer()), dialogUnionDetails(QSharedPointer()), dialogCutArc(QSharedPointer()), 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); static const char * GENERIC_ICON_TO_CHECK = "document-open"; @@ -701,6 +701,7 @@ void MainWindow::ToolBarDraws() ui->toolBarDraws->addAction(ui->actionLayout); connect(ui->actionLayout, &QAction::triggered, this, &MainWindow::ActionLayout); + ui->actionLayout->setEnabled(false); } void MainWindow::currentDrawChanged( int index ) @@ -709,11 +710,15 @@ void MainWindow::currentDrawChanged( int index ) { doc->setCurrentData(); doc->ChangeActivDraw(comboBoxDraws->itemText(index)); - qint64 id = doc->SPointActiveDraw(); - if (id != 0) + if(drawMode) { - const VPointF *p = pattern->GeometricObject(id); - view->centerOn(p->toQPointF()); + ArrowTool(); + qint64 id = doc->SPointActiveDraw(); + if (id != 0) + { + const VPointF *p = pattern->GeometricObject(id); + view->centerOn(p->toQPointF()); + } } } } @@ -915,15 +920,22 @@ void MainWindow::ActionDraw(bool checked) currentScene = sceneDraw; view->setScene(currentScene); + connect(view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor); RestoreCurrentScene(); mode = Draw::Calculation; comboBoxDraws->setEnabled(true); comboBoxDraws->setCurrentIndex(currentDrawIndex);//restore current pattern peace + drawMode = true; SetEnableTool(true); doc->setCurrentData(); ui->toolBox->setCurrentIndex(currentToolBoxIndex); + + ui->actionHistory->setEnabled(true); + ui->actionLayout->setEnabled(false); + ui->actionOptionDraw->setEnabled(true); + ui->actionNewDraw->setEnabled(true); } else { @@ -940,16 +952,24 @@ void MainWindow::ActionDetails(bool checked) currentScene = sceneDetails; view->setScene(sceneDetails); + disconnect(view, &VMainGraphicsView::NewFactor, sceneDraw, &VMainGraphicsScene::SetFactor); RestoreCurrentScene(); + drawMode = false; currentDrawIndex = comboBoxDraws->currentIndex();//save current pattern peace comboBoxDraws->setCurrentIndex(comboBoxDraws->count()-1); comboBoxDraws->setEnabled(false); + mode = Draw::Modeling; SetEnableTool(true); currentToolBoxIndex = ui->toolBox->currentIndex(); ui->toolBox->setCurrentIndex(4); + + ui->actionHistory->setEnabled(false); + ui->actionLayout->setEnabled(true); + ui->actionOptionDraw->setEnabled(false); + ui->actionNewDraw->setEnabled(false); } else { @@ -1014,10 +1034,26 @@ void MainWindow::ActionOpen() if (fileName.isEmpty() && changeInFile == false) { OpenPattern(fName); - sceneDraw->setSceneRect(QRectF(0, 0, view->contentsRect().width()-view->contentsRect().x(), - view->contentsRect().height()-view->contentsRect().y())); - sceneDetails->setSceneRect(QRectF(0, 0, view->contentsRect().width()-view->contentsRect().x(), - view->contentsRect().height()-view->contentsRect().y())); + + QRectF rect = sceneDraw->itemsBoundingRect(); + //Correct BoundingRect + 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 { diff --git a/src/mainwindow.h b/src/mainwindow.h index 04f775398..72122d673 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -511,6 +511,7 @@ private: Draw::Draws mode; qint32 currentDrawIndex; qint32 currentToolBoxIndex; + bool drawMode; /** * @brief ToolBarOption */ diff --git a/src/tools/drawTools/vtoolsinglepoint.cpp b/src/tools/drawTools/vtoolsinglepoint.cpp index 3c37b53fc..5154af819 100644 --- a/src/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/tools/drawTools/vtoolsinglepoint.cpp @@ -115,23 +115,31 @@ QVariant VToolSinglePoint::itemChange(QGraphicsItem::GraphicsItemChange change, QGraphicsScene *sc = this->scene(); QRectF rect = sc->itemsBoundingRect(); - //Correct BoundingRect - rect = QRectF(0, 0, rect.width() + rect.x(), rect.height() + rect.y()); QList list = sc->views(); - QRect rec = list[0]->contentsRect(); - //Correct contentsRect - rec = QRect(0, 0, rec.width() - rec.x(), rec.height() - rec.y()); + QRect rec0 = list[0]->rect(); + rec0 = QRect(0, 0, rec0.width()-2, rec0.height()-2); - 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 { - rect = rect.united(rec); - sc->setSceneRect(rect); + rec1 = rec0; } + + rec1 = rec1.united(rect.toRect()); + sc->setSceneRect(rec1); + //I don't now why but signal does not work. doc->FullUpdateTree(); } diff --git a/src/tools/nodeDetails/vabstractnode.cpp b/src/tools/nodeDetails/vabstractnode.cpp index 0b964aea2..4a9464eb2 100644 --- a/src/tools/nodeDetails/vabstractnode.cpp +++ b/src/tools/nodeDetails/vabstractnode.cpp @@ -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"<GetP2()); BiasRotatePoint(&p2, dx, dy, data->GeometricObject(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(pRotate)->toQPointF(), angle); VPointF *p4 = new VPointF(spline->GetP4()); @@ -150,9 +150,9 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContai BiasRotatePoint(p4, dx, dy, data->GeometricObject(pRotate)->toQPointF(), angle); 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); - spl->setMode(Draw::Modeling); idObject = data->AddGObject(spl); VSpline *spl1 = new VSpline(*spl); @@ -208,10 +208,10 @@ void VToolUnionDetails::AddToNewDetail(QObject *tool, VDomDocument *doc, VContai if (i==1) { 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(), - splinePath->at(i).KAsm1())); + path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle2()+180, + splinePath->at(i).KAsm2())); } while(k>=0) { @@ -310,9 +310,10 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c ++idCount; 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); - spl->setMode(Draw::Modeling); ++idCount; data->UpdateGObject(idDetail+idCount, spl); @@ -364,10 +365,10 @@ void VToolUnionDetails::UpdatePoints(const qint64 &idDetail, VContainer *data, c if (i==1) { 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(), - splinePath->at(i).KAsm1())); + path->append(VSplinePoint(*p4, splinePath->at(i).KAsm1(), spl.GetAngle2()+180, + splinePath->at(i).KAsm2())); } while(k>=0) diff --git a/src/widgets/vmaingraphicsscene.cpp b/src/widgets/vmaingraphicsscene.cpp index 9bb9d9abd..e2bd07775 100644 --- a/src/widgets/vmaingraphicsscene.cpp +++ b/src/widgets/vmaingraphicsscene.cpp @@ -31,10 +31,14 @@ #include 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) - :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) { diff --git a/src/widgets/vmaingraphicsview.cpp b/src/widgets/vmaingraphicsview.cpp index 02fe36dcf..7b9b4f71a 100644 --- a/src/widgets/vmaingraphicsview.cpp +++ b/src/widgets/vmaingraphicsview.cpp @@ -43,48 +43,88 @@ VMainGraphicsView::VMainGraphicsView(QWidget *parent) void VMainGraphicsView::wheelEvent(QWheelEvent *event) { - int numDegrees = event->delta() / 8; - int numSteps = numDegrees / 15; // see QWheelEvent documentation + int numSteps = event->delta() / 8 / 15; // see QWheelEvent documentation + _numScheduledScalings += numSteps; if (_numScheduledScalings * numSteps < 0) { // if user moved the wheel in another direction, we reset _numScheduledScalings = numSteps; // previously scheduled scalings } - QTimeLine *anim = new QTimeLine(350, this); + QTimeLine *anim = new QTimeLine(300, this); Q_ASSERT(anim != 0); 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); anim->start(); } void VMainGraphicsView::scalingTime(qreal x) +{ + Q_UNUSED(x); + const QPointF p0scene = mapToScene(mapFromGlobal(QCursor::pos())); + + qreal factor = 1.0 + static_cast(_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); qreal factor = 1.0; - if (QApplication::keyboardModifiers() == Qt::ControlModifier) - {// If you press CTRL this code will be executed - factor = 1.0 + static_cast(_numScheduledScalings) / 300.0; - scale(factor, factor); + if (_numScheduledScalings < 0) + { + verticalScrollBar()->setValue(qRound(verticalScrollBar()->value() + factor*3.5)); emit NewFactor(factor); } else { - if (_numScheduledScalings < 0) - { - verticalScrollBar()->setValue(qRound(verticalScrollBar()->value() + factor*3.5)); +// if (verticalScrollBar()->value() > 0) +// { + verticalScrollBar()->setValue(qRound(verticalScrollBar()->value() - factor*3.5)); emit NewFactor(factor); - } - else - { - if (verticalScrollBar()->value() > 0) - { - verticalScrollBar()->setValue(qRound(verticalScrollBar()->value() - factor*3.5)); - emit NewFactor(factor); - } - } +// } } } diff --git a/src/widgets/vmaingraphicsview.h b/src/widgets/vmaingraphicsview.h index a42d53967..63cc710cf 100644 --- a/src/widgets/vmaingraphicsview.h +++ b/src/widgets/vmaingraphicsview.h @@ -55,6 +55,7 @@ public slots: * @param x */ void scalingTime(qreal x); + void scrollingTime(qreal x); /** * @brief animFinished */ diff --git a/src/xml/vdomdocument.cpp b/src/xml/vdomdocument.cpp index 395cdbb87..51a034214 100644 --- a/src/xml/vdomdocument.cpp +++ b/src/xml/vdomdocument.cpp @@ -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();