From a0ea8b656beb16ed2b987b68558bf8ea11e07e73 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Sat, 25 May 2019 11:48:23 -0400 Subject: [PATCH] Fix Balloon Next Index Persistance - next sequential number for balloon on Page was not being preserved across save/restore --- src/Mod/TechDraw/App/DrawPage.cpp | 11 +++++++++ src/Mod/TechDraw/App/DrawPage.h | 6 ++++- src/Mod/TechDraw/Gui/QGIViewBalloon.cpp | 31 +++++++++++++++++-------- src/Mod/TechDraw/Gui/QGIViewBalloon.h | 8 +++---- src/Mod/TechDraw/Gui/QGVPage.cpp | 2 -- src/Mod/TechDraw/Gui/QGVPage.h | 11 ++++----- 6 files changed, 46 insertions(+), 23 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawPage.cpp b/src/Mod/TechDraw/App/DrawPage.cpp index 47c60adfc0..61ad4e9d86 100644 --- a/src/Mod/TechDraw/App/DrawPage.cpp +++ b/src/Mod/TechDraw/App/DrawPage.cpp @@ -101,6 +101,9 @@ DrawPage::DrawPage(void) } ADD_PROPERTY_TYPE(Scale, (1.0), group, (App::PropertyType)(App::Prop_None), "Scale factor for this Page"); + ADD_PROPERTY_TYPE(NextBalloonIndex, (1), group, (App::PropertyType)(App::Prop_None), + "Auto-numbering for Balloons"); + Scale.setConstraints(&scaleRange); double defScale = hGrp->GetFloat("DefaultScale",1.0); Scale.setValue(defScale); @@ -406,6 +409,14 @@ void DrawPage::unsetupObject() Template.setValue(nullptr); } +int DrawPage::getNextBalloonIndex(void) +{ + int result = NextBalloonIndex.getValue(); + int newValue = result + 1; + NextBalloonIndex.setValue(newValue); + return result; +} + void DrawPage::Restore(Base::XMLReader &reader) { reader.readElement("Properties"); diff --git a/src/Mod/TechDraw/App/DrawPage.h b/src/Mod/TechDraw/App/DrawPage.h index 140818f5e7..51e59bfd06 100644 --- a/src/Mod/TechDraw/App/DrawPage.h +++ b/src/Mod/TechDraw/App/DrawPage.h @@ -49,6 +49,8 @@ public: App::PropertyFloatConstraint Scale; App::PropertyEnumeration ProjectionType; // First or Third Angle + + App::PropertyInteger NextBalloonIndex; /** @name methods override Feature */ //@{ @@ -91,7 +93,9 @@ public: void requestPaint(void); std::vector getAllViews(void) ; bool balloonPlacing; - DrawViewPart *balloonParent; + DrawViewPart *balloonParent; //could be many balloons on page? + + int getNextBalloonIndex(void); protected: void onBeforeChange(const App::Property* prop); diff --git a/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp b/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp index 31ef0af112..f97106bbdc 100644 --- a/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp @@ -53,6 +53,7 @@ #include +#include #include #include #include @@ -150,25 +151,35 @@ void QGIViewBalloon::placeBalloon(QPointF pos) { auto balloon( dynamic_cast(getViewObject()) ); - if( balloon == nullptr ) + if( balloon == nullptr ) { return; + } + DrawView* balloonParent = nullptr; + App::DocumentObject* docObj = balloon->sourceView.getValue(); + if (docObj == nullptr) { + return; + } else { + balloonParent = dynamic_cast(docObj); + } + + auto featPage = balloonParent->findParentPage(); + if (featPage == nullptr) { + return; + } + auto vp = static_cast(getViewProvider(getViewObject())); if ( vp == nullptr ) { return; } - MDIViewPage* mdi = getMDIViewPage(); - QGVPage* page; - if (mdi != nullptr) { - page = mdi->getQGVPage(); - balloon->OriginX.setValue(mapFromScene(pos).x()); balloon->OriginY.setValue(mapFromScene(pos).y()); - QString labelText = QString::fromUtf8(std::to_string(page->balloonIndex).c_str()); - balloon->Text.setValue(std::to_string(page->balloonIndex++).c_str()); - + int idx = featPage->getNextBalloonIndex(); + QString labelText = QString::number(idx); + balloon->Text.setValue(std::to_string(idx).c_str()); + QFont font = balloonLabel->getFont(); font.setPointSizeF(Rez::guiX(vp->Fontsize.getValue())); font.setFamily(QString::fromUtf8(vp->Font.getValue())); @@ -178,7 +189,7 @@ void QGIViewBalloon::placeBalloon(QPointF pos) // Default label position balloonLabel->setPosFromCenter(mapFromScene(pos).x() + 200, mapFromScene(pos).y() -200); balloonLabel->setDimString(labelText, Rez::guiX(balloon->TextWrapLen.getValue())); - } +// } draw(); } diff --git a/src/Mod/TechDraw/Gui/QGIViewBalloon.h b/src/Mod/TechDraw/Gui/QGIViewBalloon.h index e4f1930670..1140d33b6e 100644 --- a/src/Mod/TechDraw/Gui/QGIViewBalloon.h +++ b/src/Mod/TechDraw/Gui/QGIViewBalloon.h @@ -21,8 +21,8 @@ * * ***************************************************************************/ -#ifndef DRAWINGGUI_QGRAPHICSITEMVIEWBALLOON_H -#define DRAWINGGUI_QGRAPHICSITEMVIEWBALLOON_H +#ifndef TECHDRAWGUI_QGIVBALLOON_H +#define TECHDRAWGUI_QGIVBALLOON_H #include #include @@ -121,6 +121,6 @@ protected: }; -} // namespace MDIViewPageGui +} // namespace -#endif // DRAWINGGUI_QGRAPHICSITEMVIEWBALLOON_H +#endif // TECHDRAWGUI_QGIVBALLOON_H diff --git a/src/Mod/TechDraw/Gui/QGVPage.cpp b/src/Mod/TechDraw/Gui/QGVPage.cpp index d55ab3190d..b2f60beda5 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.cpp +++ b/src/Mod/TechDraw/Gui/QGVPage.cpp @@ -149,8 +149,6 @@ QGVPage::QGVPage(ViewProviderPage *vp, QGraphicsScene* s, QWidget *parent) bkgBrush = new QBrush(getBackgroundColor()); - balloonIndex = 1; - balloonCursor = new QLabel(this); balloonCursor->setPixmap(QPixmap(QString::fromUtf8(":/icons/cursor-balloon.png"))); balloonCursor->hide(); diff --git a/src/Mod/TechDraw/Gui/QGVPage.h b/src/Mod/TechDraw/Gui/QGVPage.h index 4c7606d2e1..950676087a 100644 --- a/src/Mod/TechDraw/Gui/QGVPage.h +++ b/src/Mod/TechDraw/Gui/QGVPage.h @@ -20,8 +20,8 @@ * * ***************************************************************************/ -#ifndef DRAWINGGUI_CANVASVIEW_H -#define DRAWINGGUI_CANVASVIEW_H +#ifndef TECHDRAWGUI_QGVIEW_H +#define TECHDRAWGUI_QGVIEW_H #include #include @@ -117,7 +117,7 @@ public: void saveSvg(QString filename); void postProcessXml(QTemporaryFile* tempFile, QString filename, QString pagename); - int balloonIndex; +/* int balloonIndex;*/ public Q_SLOTS: void setHighQualityAntialiasing(bool highQualityAntialiasing); @@ -140,7 +140,6 @@ protected: QGITemplate *pageTemplate; -// std::vector views; //<<< why? scene already has a list of all the views. private: RendererType m_renderer; @@ -161,6 +160,6 @@ private: void cancelBalloonPlacing(void); }; -} // namespace MDIViewPageGui +} // namespace -#endif // DRAWINGGUI_CANVASVIEW_H +#endif // TECHDRAWGUI_QGVIEW_H