From 70441f48edc4b3137ad03a2730ee89211d7de178 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 15 Jun 2015 10:40:23 +0300 Subject: [PATCH] Refactoring. Preparetion for creation VWidgets static library. --HG-- branch : feature --- src/app/mainwindow.cpp | 12 +++---- src/app/options.h | 3 -- src/app/tools/vabstracttool.cpp | 37 ------------------- src/app/tools/vabstracttool.h | 1 - src/app/undocommands/addtocalc.cpp | 4 +-- src/app/undocommands/movedetail.cpp | 4 +-- src/app/undocommands/movelabel.cpp | 2 +- src/app/undocommands/movespline.cpp | 2 +- src/app/undocommands/movesplinepath.cpp | 2 +- src/app/undocommands/movespoint.cpp | 2 +- src/app/undocommands/savedetailoptions.cpp | 4 +-- src/app/widgets/doubledelegate.cpp | 2 +- src/app/widgets/textdelegate.cpp | 1 - src/app/widgets/vmaingraphicsscene.h | 2 +- src/app/widgets/vmaingraphicsview.cpp | 41 +++++++++++++++++++--- src/app/widgets/vmaingraphicsview.h | 2 ++ src/app/xml/vpattern.cpp | 4 +-- src/utils/def.h | 1 + 18 files changed, 60 insertions(+), 66 deletions(-) diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 39ac9fe8b..5d9f7f15c 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -2035,8 +2035,8 @@ void MainWindow::New() } //Set scene size to size scene view - VAbstractTool::NewSceneRect(sceneDraw, ui->view); - VAbstractTool::NewSceneRect(sceneDetails, ui->view); + VMainGraphicsView::NewSceneRect(sceneDraw, ui->view); + VMainGraphicsView::NewSceneRect(sceneDetails, ui->view); ToolBarOption(); AddPP(patternPieceName, path); @@ -2782,8 +2782,8 @@ void MainWindow::LoadPattern(const QString &fileName) #endif //QT_VERSION >= QT_VERSION_CHECK(5, 1, 0) // On this stage scene empty. Fit scene size to view size - VAbstractTool::NewSceneRect(sceneDraw, ui->view); - VAbstractTool::NewSceneRect(sceneDetails, ui->view); + VMainGraphicsView::NewSceneRect(sceneDraw, ui->view); + VMainGraphicsView::NewSceneRect(sceneDetails, ui->view); #ifdef Q_OS_WIN32 qt_ntfs_permission_lookup++; // turn checking on @@ -3102,8 +3102,8 @@ void MainWindow::ZoomFirstShow() ActionDraw(true); ui->view->ZoomFitBest(); - VAbstractTool::NewSceneRect(sceneDraw, ui->view); - VAbstractTool::NewSceneRect(sceneDetails, ui->view); + VMainGraphicsView::NewSceneRect(sceneDraw, ui->view); + VMainGraphicsView::NewSceneRect(sceneDetails, ui->view); ActionDetails(true); ui->view->ZoomFitBest(); diff --git a/src/app/options.h b/src/app/options.h index a008c89d9..b51c193fb 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -55,9 +55,6 @@ extern const QString degreeSymbol; extern const QString cursorArrowOpenHand; extern const QString cursorArrowCloseHand; -enum class SceneObject : char { Point, Line, Spline, Arc, SplinePath, Detail, Unknown }; - - enum class Source : char { FromGui, FromFile, FromTool }; enum class Contour : char { OpenContour, CloseContour }; diff --git a/src/app/tools/vabstracttool.cpp b/src/app/tools/vabstracttool.cpp index e0f63e15d..7bd1d356b 100644 --- a/src/app/tools/vabstracttool.cpp +++ b/src/app/tools/vabstracttool.cpp @@ -124,43 +124,6 @@ VAbstractTool::VAbstractTool(VPattern *doc, VContainer *data, quint32 id, QObjec VAbstractTool::~VAbstractTool() {} -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief NewSceneRect calculate scene rect what contains all items and doesn't less that size of scene view. - * @param sc scene. - * @param view view. - */ -void VAbstractTool::NewSceneRect(QGraphicsScene *sc, QGraphicsView *view) -{ - SCASSERT(sc != nullptr); - SCASSERT(view != nullptr); - - QRectF rect = sc->itemsBoundingRect(); - - QRect rec0 = view->rect(); - rec0 = QRect(0, 0, rec0.width()-2, rec0.height()-2); - - QTransform t = view->transform(); - - QRectF rec1; - if (t.m11() < 1) - { - qreal width = rec0.width()/t.m11(); - qreal height = rec0.height()/t.m22(); - rec1 = QRect(0, 0, static_cast(width), static_cast(height)); - - rec1.translate(rec0.center().x()-rec1.center().x(), rec0.center().y()-rec1.center().y()); - QPolygonF polygone = view->mapToScene(rec1.toRect()); - rec1 = polygone.boundingRect(); - } - else - { - rec1 = rec0; - } - rec1 = rec1.united(rect.toRect()); - sc->setSceneRect(rec1); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief DeleteTool full delete object form scene and file. diff --git a/src/app/tools/vabstracttool.h b/src/app/tools/vabstracttool.h index 0ccb20ea2..0d02d5a4d 100644 --- a/src/app/tools/vabstracttool.h +++ b/src/app/tools/vabstracttool.h @@ -53,7 +53,6 @@ class VAbstractTool: public VDataTool public: VAbstractTool(VPattern *doc, VContainer *data, quint32 id, QObject *parent = nullptr); virtual ~VAbstractTool(); - static void NewSceneRect(QGraphicsScene *sc, QGraphicsView *view); quint32 getId() const; static const QString AttrType; static const QString AttrMx; diff --git a/src/app/undocommands/addtocalc.cpp b/src/app/undocommands/addtocalc.cpp index 276973914..5f1d5a35c 100644 --- a/src/app/undocommands/addtocalc.cpp +++ b/src/app/undocommands/addtocalc.cpp @@ -81,7 +81,7 @@ void AddToCalc::undo() doc->setCursor(0); } emit NeedFullParsing(); - VAbstractTool::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); + VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo } @@ -121,7 +121,7 @@ void AddToCalc::redo() return; } RedoFullParsing(); - VAbstractTool::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); + VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView()); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/undocommands/movedetail.cpp b/src/app/undocommands/movedetail.cpp index 5de78f1a1..a05dc8817 100644 --- a/src/app/undocommands/movedetail.cpp +++ b/src/app/undocommands/movedetail.cpp @@ -72,7 +72,7 @@ void MoveDetail::undo() emit NeedLiteParsing(Document::LiteParse); QList list = scene->views(); - VAbstractTool::NewSceneRect(scene, list[0]); + VMainGraphicsView::NewSceneRect(scene, list[0]); } else { @@ -98,7 +98,7 @@ void MoveDetail::redo() redoFlag = true; QList list = scene->views(); - VAbstractTool::NewSceneRect(scene, list[0]); + VMainGraphicsView::NewSceneRect(scene, list[0]); } else { diff --git a/src/app/undocommands/movelabel.cpp b/src/app/undocommands/movelabel.cpp index cd5fe506a..4443975a2 100644 --- a/src/app/undocommands/movelabel.cpp +++ b/src/app/undocommands/movelabel.cpp @@ -123,7 +123,7 @@ void MoveLabel::Do(double mx, double my) emit NeedLiteParsing(Document::LitePPParse); QList list = scene->views(); - VAbstractTool::NewSceneRect(scene, list[0]); + VMainGraphicsView::NewSceneRect(scene, list[0]); } else { diff --git a/src/app/undocommands/movespline.cpp b/src/app/undocommands/movespline.cpp index 68731ff11..ca50e7226 100644 --- a/src/app/undocommands/movespline.cpp +++ b/src/app/undocommands/movespline.cpp @@ -100,7 +100,7 @@ void MoveSpline::Do(const VSpline &spl) emit NeedLiteParsing(Document::LiteParse); QList list = scene->views(); - VAbstractTool::NewSceneRect(scene, list[0]); + VMainGraphicsView::NewSceneRect(scene, list[0]); } else { diff --git a/src/app/undocommands/movesplinepath.cpp b/src/app/undocommands/movesplinepath.cpp index ba7526fa9..2520c3530 100644 --- a/src/app/undocommands/movesplinepath.cpp +++ b/src/app/undocommands/movesplinepath.cpp @@ -95,7 +95,7 @@ void MoveSplinePath::Do(const VSplinePath &splPath) emit NeedLiteParsing(Document::LiteParse); QList list = scene->views(); - VAbstractTool::NewSceneRect(scene, list[0]); + VMainGraphicsView::NewSceneRect(scene, list[0]); } else { diff --git a/src/app/undocommands/movespoint.cpp b/src/app/undocommands/movespoint.cpp index 1ea27044b..9a21d871f 100644 --- a/src/app/undocommands/movespoint.cpp +++ b/src/app/undocommands/movespoint.cpp @@ -125,7 +125,7 @@ void MoveSPoint::Do(double x, double y) emit NeedLiteParsing(Document::LitePPParse); QList list = scene->views(); - VAbstractTool::NewSceneRect(scene, list[0]); + VMainGraphicsView::NewSceneRect(scene, list[0]); } else { diff --git a/src/app/undocommands/savedetailoptions.cpp b/src/app/undocommands/savedetailoptions.cpp index 475a38a69..179bdc9f2 100644 --- a/src/app/undocommands/savedetailoptions.cpp +++ b/src/app/undocommands/savedetailoptions.cpp @@ -71,7 +71,7 @@ void SaveDetailOptions::undo() emit NeedLiteParsing(Document::LiteParse); QList list = scene->views(); - VAbstractTool::NewSceneRect(scene, list[0]); + VMainGraphicsView::NewSceneRect(scene, list[0]); } else { @@ -108,7 +108,7 @@ void SaveDetailOptions::redo() emit NeedLiteParsing(Document::LiteParse); QList listV = scene->views(); - VAbstractTool::NewSceneRect(scene, listV[0]); + VMainGraphicsView::NewSceneRect(scene, listV[0]); } else { diff --git a/src/app/widgets/doubledelegate.cpp b/src/app/widgets/doubledelegate.cpp index 46feb8e09..c883dfeb3 100644 --- a/src/app/widgets/doubledelegate.cpp +++ b/src/app/widgets/doubledelegate.cpp @@ -28,7 +28,7 @@ #include "doubledelegate.h" #include -#include "../options.h" +#include "../../utils/def.h" //--------------------------------------------------------------------------------------------------------------------- /** diff --git a/src/app/widgets/textdelegate.cpp b/src/app/widgets/textdelegate.cpp index 6be5f6b69..e33822289 100644 --- a/src/app/widgets/textdelegate.cpp +++ b/src/app/widgets/textdelegate.cpp @@ -28,7 +28,6 @@ #include "textdelegate.h" #include -#include "../options.h" #include "../libs/vpatterndb/vcontainer.h" //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/widgets/vmaingraphicsscene.h b/src/app/widgets/vmaingraphicsscene.h index 111e88755..dec5e3523 100644 --- a/src/app/widgets/vmaingraphicsscene.h +++ b/src/app/widgets/vmaingraphicsscene.h @@ -30,7 +30,7 @@ #define VMAINGRAPHICSSCENE_H #include -#include "../options.h" +#include "../../utils/def.h" /** * @brief The VMainGraphicsScene class main scene. diff --git a/src/app/widgets/vmaingraphicsview.cpp b/src/app/widgets/vmaingraphicsview.cpp index b38f99249..41e55d811 100644 --- a/src/app/widgets/vmaingraphicsview.cpp +++ b/src/app/widgets/vmaingraphicsview.cpp @@ -32,7 +32,6 @@ #include #include #include -#include "../tools/vabstracttool.h" #include "../visualization/vsimplecurve.h" #include @@ -193,7 +192,7 @@ VMainGraphicsView::VMainGraphicsView(QWidget *parent) void VMainGraphicsView::ZoomIn() { scale(1.1, 1.1); - VAbstractTool::NewSceneRect(this->scene(), this); + VMainGraphicsView::NewSceneRect(this->scene(), this); emit NewFactor(1.1); } @@ -201,7 +200,7 @@ void VMainGraphicsView::ZoomIn() void VMainGraphicsView::ZoomOut() { scale(1.0/1.1, 1.0/1.1); - VAbstractTool::NewSceneRect(this->scene(), this); + VMainGraphicsView::NewSceneRect(this->scene(), this); emit NewFactor(1.0/1.1); } @@ -254,7 +253,7 @@ void VMainGraphicsView::mousePressEvent(QMouseEvent *mousePress) } for (int i = 0; i < list.size(); ++i) { - if (qApp->getCurrentScene()->items().contains(list.at(i))) + if (this->scene()->items().contains(list.at(i))) { if (list.at(i)->type() <= VSimpleCurve::Type && list.at(i)->type() > QGraphicsItem::UserType) @@ -297,3 +296,37 @@ void VMainGraphicsView::setShowToolOptions(bool value) { showToolOptions = value; } + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief NewSceneRect calculate scene rect what contains all items and doesn't less that size of scene view. + * @param sc scene. + * @param view view. + */ +void VMainGraphicsView::NewSceneRect(QGraphicsScene *sc, QGraphicsView *view) +{ + SCASSERT(sc != nullptr); + SCASSERT(view != nullptr); + + const QRectF rect = sc->itemsBoundingRect(); + const QRect rec0 = QRect(0, 0, view->rect().width()-2, view->rect().height()-2); + const QTransform t = view->transform(); + + QRectF rec1; + if (t.m11() < 1) + { + const qreal width = rec0.width()/t.m11(); + const qreal height = rec0.height()/t.m22(); + rec1 = QRect(0, 0, static_cast(width), static_cast(height)); + + rec1.translate(rec0.center().x()-rec1.center().x(), rec0.center().y()-rec1.center().y()); + const QPolygonF polygone = view->mapToScene(rec1.toRect()); + rec1 = polygone.boundingRect(); + } + else + { + rec1 = rec0; + } + rec1 = rec1.united(rect.toRect()); + sc->setSceneRect(rec1); +} diff --git a/src/app/widgets/vmaingraphicsview.h b/src/app/widgets/vmaingraphicsview.h index cb0a488fa..a10007e71 100644 --- a/src/app/widgets/vmaingraphicsview.h +++ b/src/app/widgets/vmaingraphicsview.h @@ -104,6 +104,8 @@ public: explicit VMainGraphicsView(QWidget *parent = nullptr); void setShowToolOptions(bool value); + static void NewSceneRect(QGraphicsScene *sc, QGraphicsView *view); + signals: /** * @brief NewFactor send new scale factor. diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 6fd90b777..70f39d9a0 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -842,8 +842,8 @@ void VPattern::LiteParseTree(const Document &parse) setCurrentData(); emit FullUpdateFromFile(); // Recalculate scene rect - VAbstractTool::NewSceneRect(sceneDraw, qApp->getSceneView()); - VAbstractTool::NewSceneRect(sceneDetail, qApp->getSceneView()); + VMainGraphicsView::NewSceneRect(sceneDraw, qApp->getSceneView()); + VMainGraphicsView::NewSceneRect(sceneDetail, qApp->getSceneView()); qCDebug(vXML, "Scene size updated."); } diff --git a/src/utils/def.h b/src/utils/def.h index 0e9668877..19d66def4 100644 --- a/src/utils/def.h +++ b/src/utils/def.h @@ -34,6 +34,7 @@ #include enum class NodeDetail : char { Contour, Modeling }; +enum class SceneObject : char { Point, Line, Spline, Arc, SplinePath, Detail, Unknown }; enum class Tool : unsigned char {