Fix Balloon Next Index Persistance

- next sequential number for balloon on Page was
  not being preserved across save/restore
This commit is contained in:
wandererfan
2019-05-25 11:48:23 -04:00
committed by wmayer
parent e2519d6424
commit e759f91d68
6 changed files with 46 additions and 23 deletions

View File

@@ -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");

View File

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

View File

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

View File

@@ -21,8 +21,8 @@
* *
***************************************************************************/
#ifndef DRAWINGGUI_QGRAPHICSITEMVIEWBALLOON_H
#define DRAWINGGUI_QGRAPHICSITEMVIEWBALLOON_H
#ifndef TECHDRAWGUI_QGIVBALLOON_H
#define TECHDRAWGUI_QGIVBALLOON_H
#include <QObject>
#include <QGraphicsView>
@@ -121,6 +121,6 @@ protected:
};
} // namespace MDIViewPageGui
} // namespace
#endif // DRAWINGGUI_QGRAPHICSITEMVIEWBALLOON_H
#endif // TECHDRAWGUI_QGIVBALLOON_H

View File

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

View File

@@ -20,8 +20,8 @@
* *
***************************************************************************/
#ifndef DRAWINGGUI_CANVASVIEW_H
#define DRAWINGGUI_CANVASVIEW_H
#ifndef TECHDRAWGUI_QGVIEW_H
#define TECHDRAWGUI_QGVIEW_H
#include <QGraphicsView>
#include <QGraphicsScene>
@@ -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<QGIView *> 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