Skip to content

Commit

Permalink
Fix Balloon Next Index Persistance
Browse files Browse the repository at this point in the history
- next sequential number for balloon on Page was
  not being preserved across save/restore
  • Loading branch information
WandererFan authored and wwmayer committed May 25, 2019
1 parent da047ab commit a0ea8b6
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 23 deletions.
11 changes: 11 additions & 0 deletions src/Mod/TechDraw/App/DrawPage.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
6 changes: 5 additions & 1 deletion src/Mod/TechDraw/App/DrawPage.h
Expand Up @@ -49,6 +49,8 @@ class TechDrawExport DrawPage: public App::DocumentObject

App::PropertyFloatConstraint Scale;
App::PropertyEnumeration ProjectionType; // First or Third Angle

App::PropertyInteger NextBalloonIndex;

/** @name methods override Feature */
//@{
Expand Down Expand Up @@ -91,7 +93,9 @@ class TechDrawExport DrawPage: public App::DocumentObject
void requestPaint(void);
std::vector<App::DocumentObject*> getAllViews(void) ;
bool balloonPlacing;
DrawViewPart *balloonParent;
DrawViewPart *balloonParent; //could be many balloons on page?

int getNextBalloonIndex(void);

protected:
void onBeforeChange(const App::Property* prop);
Expand Down
31 changes: 21 additions & 10 deletions src/Mod/TechDraw/Gui/QGIViewBalloon.cpp
Expand Up @@ -53,6 +53,7 @@

#include <Mod/Part/App/PartFeature.h>

#include <Mod/TechDraw/App/DrawPage.h>
#include <Mod/TechDraw/App/DrawViewBalloon.h>
#include <Mod/TechDraw/App/DrawViewPart.h>
#include <Mod/TechDraw/App/DrawUtil.h>
Expand Down Expand Up @@ -150,25 +151,35 @@ void QGIViewBalloon::placeBalloon(QPointF pos)
{

auto balloon( dynamic_cast<TechDraw::DrawViewBalloon*>(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<DrawView*>(docObj);
}

auto featPage = balloonParent->findParentPage();
if (featPage == nullptr) {
return;
}

auto vp = static_cast<ViewProviderBalloon*>(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()));
Expand All @@ -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();
}
Expand Down
8 changes: 4 additions & 4 deletions src/Mod/TechDraw/Gui/QGIViewBalloon.h
Expand Up @@ -21,8 +21,8 @@
* *
***************************************************************************/

#ifndef DRAWINGGUI_QGRAPHICSITEMVIEWBALLOON_H
#define DRAWINGGUI_QGRAPHICSITEMVIEWBALLOON_H
#ifndef TECHDRAWGUI_QGIVBALLOON_H
#define TECHDRAWGUI_QGIVBALLOON_H

#include <QObject>
#include <QGraphicsView>
Expand Down Expand Up @@ -121,6 +121,6 @@ public Q_SLOTS:

};

} // namespace MDIViewPageGui
} // namespace

#endif // DRAWINGGUI_QGRAPHICSITEMVIEWBALLOON_H
#endif // TECHDRAWGUI_QGIVBALLOON_H
2 changes: 0 additions & 2 deletions src/Mod/TechDraw/Gui/QGVPage.cpp
Expand Up @@ -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();
Expand Down
11 changes: 5 additions & 6 deletions src/Mod/TechDraw/Gui/QGVPage.h
Expand Up @@ -20,8 +20,8 @@
* *
***************************************************************************/

#ifndef DRAWINGGUI_CANVASVIEW_H
#define DRAWINGGUI_CANVASVIEW_H
#ifndef TECHDRAWGUI_QGVIEW_H
#define TECHDRAWGUI_QGVIEW_H

#include <QGraphicsView>
#include <QGraphicsScene>
Expand Down Expand Up @@ -117,7 +117,7 @@ class TechDrawGuiExport QGVPage : public QGraphicsView
void saveSvg(QString filename);
void postProcessXml(QTemporaryFile* tempFile, QString filename, QString pagename);

int balloonIndex;
/* int balloonIndex;*/

public Q_SLOTS:
void setHighQualityAntialiasing(bool highQualityAntialiasing);
Expand All @@ -140,7 +140,6 @@ public Q_SLOTS:


QGITemplate *pageTemplate;
// std::vector<QGIView *> views; //<<< why? scene already has a list of all the views.

private:
RendererType m_renderer;
Expand All @@ -161,6 +160,6 @@ public Q_SLOTS:
void cancelBalloonPlacing(void);
};

} // namespace MDIViewPageGui
} // namespace

#endif // DRAWINGGUI_CANVASVIEW_H
#endif // TECHDRAWGUI_QGVIEW_H

0 comments on commit a0ea8b6

Please sign in to comment.