Qt item parenting and garbage collection

Remove dupl/obsolete code
This commit is contained in:
WandererFan 2016-07-28 09:28:50 -04:00 committed by Yorik van Havre
parent 3588479ff5
commit 40fa4e0d40
13 changed files with 207 additions and 324 deletions

View File

@ -99,6 +99,8 @@ MDIViewPage::MDIViewPage(ViewProviderPage *pageVp, Gui::Document* doc, QWidget*
pageGui(pageVp), pageGui(pageVp),
m_frameState(true) m_frameState(true)
{ {
m_scene = new QGraphicsScene(this);
m_view = new QGVPage(pageVp,m_scene,this); m_view = new QGVPage(pageVp,m_scene,this);
m_exportSVGAction = new QAction(tr("&Export SVG"), this); m_exportSVGAction = new QAction(tr("&Export SVG"), this);

View File

@ -80,7 +80,7 @@ public:
QGVPage* getQGVPage(void) {return m_view;}; QGVPage* getQGVPage(void) {return m_view;};
QGraphicsScene m_scene; QGraphicsScene* m_scene;
public Q_SLOTS: public Q_SLOTS:
void setRenderer(QAction *action); void setRenderer(QAction *action);

View File

@ -51,17 +51,22 @@ QGISVGTemplate::QGISVGTemplate(QGraphicsScene *scene, QWidget* srWidget)
: QGITemplate(scene), : QGITemplate(scene),
qgview(srWidget) qgview(srWidget)
{ {
m_svgItem.setSharedRenderer(&m_svgRender);
m_svgItem.setFlags(QGraphicsItem::ItemClipsToShape); m_svgItem = new QGraphicsSvgItem(this);
m_svgItem.setCacheMode(QGraphicsItem::NoCache); m_svgRender = new QSvgRenderer();
addToGroup(&m_svgItem); m_svgItem->setSharedRenderer(m_svgRender);
m_svgItem->setFlags(QGraphicsItem::ItemClipsToShape);
m_svgItem->setCacheMode(QGraphicsItem::NoCache);
addToGroup(m_svgItem);
} }
QGISVGTemplate::~QGISVGTemplate() QGISVGTemplate::~QGISVGTemplate()
{ {
clearContents(); clearContents();
delete m_svgRender;
} }
QVariant QGISVGTemplate::itemChange(GraphicsItemChange change, QVariant QGISVGTemplate::itemChange(GraphicsItemChange change,
@ -97,11 +102,11 @@ void QGISVGTemplate::load(const QString &fileName)
if (!file.exists()) { if (!file.exists()) {
return; return;
} }
m_svgRender.load(file.fileName()); m_svgRender->load(file.fileName());
QSize size = m_svgRender.defaultSize(); QSize size = m_svgRender->defaultSize();
//Base::Console().Log("size of svg document <%i,%i>", size.width(), size.height()); //Base::Console().Log("size of svg document <%i,%i>", size.width(), size.height());
m_svgItem.setSharedRenderer(&m_svgRender); m_svgItem->setSharedRenderer(m_svgRender);
TechDraw::DrawSVGTemplate *tmplte = getSVGTemplate(); TechDraw::DrawSVGTemplate *tmplte = getSVGTemplate();
@ -196,7 +201,7 @@ void QGISVGTemplate::load(const QString &fileName)
QTransform qtrans; QTransform qtrans;
qtrans.translate(0.f, -tmplte->getHeight()); qtrans.translate(0.f, -tmplte->getHeight());
qtrans.scale(xaspect , yaspect); qtrans.scale(xaspect , yaspect);
m_svgItem.setTransform(qtrans); m_svgItem->setTransform(qtrans);
} }
TechDraw::DrawSVGTemplate * QGISVGTemplate::getSVGTemplate() TechDraw::DrawSVGTemplate * QGISVGTemplate::getSVGTemplate()

View File

@ -23,11 +23,10 @@
#ifndef DRAWINGGUI_QGRAPHICSITEMSVGTEMPLATE_H #ifndef DRAWINGGUI_QGRAPHICSITEMSVGTEMPLATE_H
#define DRAWINGGUI_QGRAPHICSITEMSVGTEMPLATE_H #define DRAWINGGUI_QGRAPHICSITEMSVGTEMPLATE_H
#include <QGraphicsSvgItem>
#include <QSvgRenderer>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QGraphicsScene; class QGraphicsScene;
class QGraphicsSvgItem;
class QSvgRenderer;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace TechDraw { namespace TechDraw {
@ -62,8 +61,8 @@ protected:
protected: protected:
TechDraw::DrawSVGTemplate * getSVGTemplate(); TechDraw::DrawSVGTemplate * getSVGTemplate();
QGraphicsSvgItem m_svgItem; QGraphicsSvgItem *m_svgItem;
QSvgRenderer m_svgRender; QSvgRenderer *m_svgRender;
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
}; // class QGISVGTemplate }; // class QGISVGTemplate

View File

@ -48,7 +48,11 @@
#include <Gui/Selection.h> #include <Gui/Selection.h>
#include <Gui/Command.h> #include <Gui/Command.h>
#include "QGCustomBorder.h"
#include "QGCustomLabel.h"
#include "QGIView.h" #include "QGIView.h"
#include "QGCustomBorder.h"
#include "QGCustomLabel.h"
#include "QGCustomClip.h" #include "QGCustomClip.h"
#include "QGIViewClip.h" #include "QGIViewClip.h"
@ -79,8 +83,10 @@ QGIView::QGIView()
m_decorPen.setStyle(Qt::DashLine); m_decorPen.setStyle(Qt::DashLine);
m_decorPen.setWidth(0); // 0 => 1px "cosmetic pen" m_decorPen.setWidth(0); // 0 => 1px "cosmetic pen"
addToGroup(&m_label); m_label = new QGCustomLabel();
addToGroup(&m_border); addToGroup(m_label);
m_border = new QGCustomBorder();
addToGroup(m_border);
isVisible(true); isVisible(true);
} }
@ -291,27 +297,27 @@ void QGIView::draw()
void QGIView::drawBorder() void QGIView::drawBorder()
{ {
if (!borderVisible) { if (!borderVisible) {
m_label.hide(); m_label->hide();
m_border.hide(); m_border->hide();
return; return;
} }
//double margin = 2.0; //double margin = 2.0;
m_label.hide(); m_label->hide();
m_border.hide(); m_border->hide();
m_label.setDefaultTextColor(m_colCurrent); m_label->setDefaultTextColor(m_colCurrent);
m_font.setFamily(getPrefFont()); m_font.setFamily(getPrefFont());
m_label.setFont(m_font); m_label->setFont(m_font);
QString labelStr = QString::fromUtf8(getViewObject()->Label.getValue()); QString labelStr = QString::fromUtf8(getViewObject()->Label.getValue());
m_label.setPlainText(labelStr); m_label->setPlainText(labelStr);
QRectF labelArea = m_label.boundingRect(); QRectF labelArea = m_label->boundingRect();
double labelWidth = m_label.boundingRect().width(); double labelWidth = m_label->boundingRect().width();
double labelHeight = m_label.boundingRect().height(); double labelHeight = m_label->boundingRect().height();
m_border.hide(); m_border->hide();
m_decorPen.setColor(m_colCurrent); m_decorPen.setColor(m_colCurrent);
m_border.setPen(m_decorPen); m_border->setPen(m_decorPen);
QRectF displayArea = customChildrenBoundingRect(); QRectF displayArea = customChildrenBoundingRect();
double displayWidth = displayArea.width(); double displayWidth = displayArea.width();
@ -324,19 +330,19 @@ void QGIView::drawBorder()
double frameHeight = labelHeight + displayHeight; double frameHeight = labelHeight + displayHeight;
QPointF displayCenter = displayArea.center(); QPointF displayCenter = displayArea.center();
m_label.setX(displayCenter.x() - labelArea.width()/2.); m_label->setX(displayCenter.x() - labelArea.width()/2.);
m_label.setY(displayArea.bottom()); m_label->setY(displayArea.bottom());
QRectF frameArea = QRectF(displayCenter.x() - frameWidth/2., QRectF frameArea = QRectF(displayCenter.x() - frameWidth/2.,
displayArea.top(), displayArea.top(),
frameWidth, frameWidth,
frameHeight); frameHeight);
prepareGeometryChange(); prepareGeometryChange();
m_border.setRect(frameArea); m_border->setRect(frameArea);
m_border.setPos(0.,0.); m_border->setPos(0.,0.);
m_label.show(); m_label->show();
m_border.show(); m_border->show();
} }
void QGIView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) void QGIView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
@ -365,7 +371,7 @@ QRectF QGIView::customChildrenBoundingRect() {
QRectF QGIView::boundingRect() const QRectF QGIView::boundingRect() const
{ {
return m_border.rect().adjusted(-2.,-2.,2.,2.); //allow for border line width //TODO: fiddle brect if border off? return m_border->rect().adjusted(-2.,-2.,2.,2.); //allow for border line width //TODO: fiddle brect if border off?
} }
QGIView* QGIView::getQGIVByName(std::string name) QGIView* QGIView::getQGIVByName(std::string name)

View File

@ -31,8 +31,7 @@
#include <Base/Parameter.h> #include <Base/Parameter.h>
#include <Mod/TechDraw/App/DrawView.h> #include <Mod/TechDraw/App/DrawView.h>
#include "QGCustomBorder.h"
#include "QGCustomLabel.h"
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QGraphicsScene; class QGraphicsScene;
@ -41,6 +40,8 @@ QT_END_NAMESPACE
namespace TechDrawGui namespace TechDrawGui
{ {
class QGCustomBorder;
class QGCustomLabel;
class TechDrawGuiExport QGIView : public QGraphicsItemGroup class TechDrawGuiExport QGIView : public QGraphicsItemGroup
{ {
@ -113,8 +114,8 @@ protected:
QColor m_colPre; QColor m_colPre;
QColor m_colSel; QColor m_colSel;
QFont m_font; QFont m_font;
QGCustomLabel m_label; QGCustomLabel* m_label;
QGCustomBorder m_border; QGCustomBorder* m_border;
QPen m_decorPen; QPen m_decorPen;
}; };

View File

@ -47,6 +47,8 @@
#include <Mod/TechDraw/App/DrawViewClip.h> #include <Mod/TechDraw/App/DrawViewClip.h>
#include "QGCustomRect.h"
#include "QGCustomClip.h"
#include "QGIViewClip.h" #include "QGIViewClip.h"
using namespace TechDrawGui; using namespace TechDrawGui;
@ -59,13 +61,15 @@ QGIViewClip::QGIViewClip()
setFlag(QGraphicsItem::ItemIsSelectable, true); setFlag(QGraphicsItem::ItemIsSelectable, true);
setFlag(QGraphicsItem::ItemIsMovable, true); setFlag(QGraphicsItem::ItemIsMovable, true);
addToGroup(&m_cliparea); m_cliparea = new QGCustomClip();
m_cliparea.setPos(0.,0.); addToGroup(m_cliparea);
m_cliparea.setRect(0.,0.,5.,5.); m_cliparea->setPos(0.,0.);
m_cliparea->setRect(0.,0.,5.,5.);
addToGroup(&m_frame); m_frame = new QGCustomRect();
m_frame.setPos(0.,0.); addToGroup(m_frame);
m_frame.setRect(0.,0.,5.,5.); m_frame->setPos(0.,0.);
m_frame->setRect(0.,0.,5.,5.);
} }
@ -116,15 +120,15 @@ void QGIViewClip::drawClip()
double h = viewClip->Height.getValue(); double h = viewClip->Height.getValue();
double w = viewClip->Width.getValue(); double w = viewClip->Width.getValue();
QRectF r = QRectF(0,0,w,h); QRectF r = QRectF(0,0,w,h);
m_frame.setRect(r); m_frame->setRect(r);
m_frame.setPos(0.,0.); m_frame->setPos(0.,0.);
if (viewClip->ShowFrame.getValue()) { if (viewClip->ShowFrame.getValue()) {
m_frame.show(); m_frame->show();
} else { } else {
m_frame.hide(); m_frame->hide();
} }
m_cliparea.setRect(r.adjusted(-1,-1,1,1)); //TODO: clip just outside frame or just inside?? m_cliparea->setRect(r.adjusted(-1,-1,1,1)); //TODO: clip just outside frame or just inside??
std::vector<std::string> childNames = viewClip->getChildViewNames(); std::vector<std::string> childNames = viewClip->getChildViewNames();
//for all child Views in Clip, add the graphics representation of the View to the Clip group //for all child Views in Clip, add the graphics representation of the View to the Clip group
@ -132,10 +136,10 @@ void QGIViewClip::drawClip()
QGIView* qgiv = getQGIVByName((*it)); QGIView* qgiv = getQGIVByName((*it));
if (qgiv) { if (qgiv) {
//TODO: why is qgiv never already in a group? //TODO: why is qgiv never already in a group?
if (qgiv->group() != &m_cliparea) { if (qgiv->group() != m_cliparea) {
qgiv->hide(); qgiv->hide();
scene()->removeItem(qgiv); scene()->removeItem(qgiv);
m_cliparea.addToGroup(qgiv); m_cliparea->addToGroup(qgiv);
qgiv->isInnerView(true); qgiv->isInnerView(true);
double x = qgiv->getViewObject()->X.getValue(); double x = qgiv->getViewObject()->X.getValue();
double y = qgiv->getViewObject()->Y.getValue(); double y = qgiv->getViewObject()->Y.getValue();
@ -153,14 +157,14 @@ void QGIViewClip::drawClip()
} }
//for all graphic views in qgigroup, remove from qgigroup the ones that aren't in ViewClip //for all graphic views in qgigroup, remove from qgigroup the ones that aren't in ViewClip
QList<QGraphicsItem*> qgItems = m_cliparea.childItems(); QList<QGraphicsItem*> qgItems = m_cliparea->childItems();
QList<QGraphicsItem*>::iterator it = qgItems.begin(); QList<QGraphicsItem*>::iterator it = qgItems.begin();
for (; it != qgItems.end(); it++) { for (; it != qgItems.end(); it++) {
QGIView* qv = dynamic_cast<QGIView*>((*it)); QGIView* qv = dynamic_cast<QGIView*>((*it));
if (qv) { if (qv) {
std::string qvName = std::string(qv->getViewName()); std::string qvName = std::string(qv->getViewName());
if (std::find(childNames.begin(),childNames.end(),qvName) == childNames.end()) { if (std::find(childNames.begin(),childNames.end(),qvName) == childNames.end()) {
m_cliparea.removeFromGroup(qv); m_cliparea->removeFromGroup(qv);
removeFromGroup(qv); removeFromGroup(qv);
qv->isInnerView(false); qv->isInnerView(false);
qv->toggleBorder(true); qv->toggleBorder(true);
@ -168,5 +172,3 @@ void QGIViewClip::drawClip()
} }
} }
} }

View File

@ -27,11 +27,11 @@
#include <QPainter> #include <QPainter>
#include "QGIView.h" #include "QGIView.h"
#include "QGCustomRect.h"
#include "QGCustomClip.h"
namespace TechDrawGui namespace TechDrawGui
{ {
class QGCustomRect;
class QGCustomClip;
class TechDrawGuiExport QGIViewClip : public QGIView class TechDrawGuiExport QGIViewClip : public QGIView
{ {
@ -52,8 +52,8 @@ protected:
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) override; virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
private: private:
QGCustomRect m_frame; QGCustomRect* m_frame;
QGCustomClip m_cliparea; QGCustomClip* m_cliparea;
}; };

View File

@ -28,29 +28,17 @@
# include <TopoDS_Edge.hxx> # include <TopoDS_Edge.hxx>
# include <TopoDS.hxx> # include <TopoDS.hxx>
# include <BRepAdaptor_Curve.hxx> # include <BRepAdaptor_Curve.hxx>
# include <Precision.hxx>
# include <QAction>
# include <QApplication>
# include <QContextMenuEvent>
# include <QGraphicsScene> # include <QGraphicsScene>
# include <QGraphicsSceneMouseEvent> # include <QGraphicsSceneMouseEvent>
# include <QGridLayout>
# include <QScopedPointer>
# include <QMenu>
# include <QMessageBox>
# include <QMouseEvent>
# include <QPainterPathStroker>
# include <QPainter> # include <QPainter>
# include <strstream>
# include <math.h>
# include <QGraphicsPathItem>
# include <QGraphicsTextItem>
# include <QPaintDevice> # include <QPaintDevice>
# include <QSvgGenerator> # include <QSvgGenerator>
#endif
#include <Precision.hxx> # include <strstream>
# include <math.h>
#endif
#include <App/Application.h> #include <App/Application.h>
#include <App/Material.h> #include <App/Material.h>
@ -66,8 +54,8 @@
#include <Mod/TechDraw/App/DrawUtil.h> #include <Mod/TechDraw/App/DrawUtil.h>
#include <Mod/TechDraw/App/Geometry.h> #include <Mod/TechDraw/App/Geometry.h>
#include "QGIViewDimension.h"
#include "QGIArrow.h" #include "QGIArrow.h"
#include "QGIViewDimension.h"
using namespace TechDrawGui; using namespace TechDrawGui;
@ -77,11 +65,8 @@ enum SnapMode{
HorizontalSnap HorizontalSnap
}; };
QGIDatumLabel::QGIDatumLabel(int ref, QGraphicsScene *scene ) : reference(ref) QGIDatumLabel::QGIDatumLabel()
{ {
if(scene) {
scene->addItem(this);
}
posX = 0; posX = 0;
posY = 0; posY = 0;
@ -158,35 +143,34 @@ QGIViewDimension::QGIViewDimension() :
setFlag(QGraphicsItem::ItemIsMovable, false); setFlag(QGraphicsItem::ItemIsMovable, false);
setCacheMode(QGraphicsItem::NoCache); setCacheMode(QGraphicsItem::NoCache);
QGIDatumLabel *dlabel = new QGIDatumLabel(); datumLabel = new QGIDatumLabel();
QGraphicsPathItem *arrws = new QGraphicsPathItem(); addToGroup(datumLabel);
QGraphicsPathItem *clines = new QGraphicsPathItem(); dimLines = new QGraphicsPathItem();
addToGroup(dimLines);
datumLabel = dlabel; centerMark = new QGraphicsPathItem();
dimLines = arrws; addToGroup(centerMark);
centerMark = clines; aHead1 = new QGIArrow();
addToGroup(aHead1);
aHead2 = new QGIArrow();
addToGroup(aHead2);
// connecting the needed slots and signals // connecting the needed slots and signals
QObject::connect( QObject::connect(
dlabel, SIGNAL(dragging()), datumLabel, SIGNAL(dragging()),
this , SLOT (datumLabelDragged())); this , SLOT (datumLabelDragged()));
QObject::connect( QObject::connect(
dlabel, SIGNAL(dragFinished()), datumLabel, SIGNAL(dragFinished()),
this , SLOT (datumLabelDragFinished())); this , SLOT (datumLabelDragFinished()));
QObject::connect( QObject::connect(
dlabel, SIGNAL(selected(bool)), datumLabel, SIGNAL(selected(bool)),
this , SLOT (select(bool))); this , SLOT (select(bool)));
QObject::connect( QObject::connect(
dlabel, SIGNAL(hover(bool)), datumLabel, SIGNAL(hover(bool)),
this , SLOT (hover(bool))); this , SLOT (hover(bool)));
addToGroup(dimLines);
addToGroup(datumLabel);
addToGroup(centerMark);
m_pen.setStyle(Qt::SolidLine); m_pen.setStyle(Qt::SolidLine);
m_clPen.setColor(QColor(128,128,128)); // TODO: centre line colour preference? m_clPen.setColor(QColor(128,128,128)); // TODO: centre line colour preference?
@ -205,8 +189,7 @@ void QGIViewDimension::setViewPartFeature(TechDraw::DrawViewDimension *obj)
float x = obj->X.getValue(); float x = obj->X.getValue();
float y = obj->Y.getValue(); float y = obj->Y.getValue();
QGIDatumLabel *dLabel = static_cast<QGIDatumLabel *>(datumLabel); datumLabel->setPosFromCenter(x, y);
dLabel->setPosFromCenter(x, y);
updateDim(); updateDim();
draw(); draw();
@ -230,21 +213,19 @@ void QGIViewDimension::updateView(bool update)
return; return;
TechDraw::DrawViewDimension *dim = dynamic_cast<TechDraw::DrawViewDimension*>(getViewObject()); TechDraw::DrawViewDimension *dim = dynamic_cast<TechDraw::DrawViewDimension*>(getViewObject());
QGIDatumLabel *dLabel = dynamic_cast<QGIDatumLabel *>(datumLabel);
// Identify what changed to prevent complete redraw // Identify what changed to prevent complete redraw
if(dim->Fontsize.isTouched() || if(dim->Fontsize.isTouched() ||
dim->Font.isTouched()) { dim->Font.isTouched()) {
QFont font = dLabel->font(); QFont font = datumLabel->font();
font.setPointSizeF(dim->Fontsize.getValue()); //scene units (mm), not points font.setPointSizeF(dim->Fontsize.getValue()); //scene units (mm), not points
font.setFamily(QString::fromAscii(dim->Font.getValue())); font.setFamily(QString::fromAscii(dim->Font.getValue()));
dLabel->setFont(font); datumLabel->setFont(font);
dLabel->setLabelCenter(); datumLabel->setLabelCenter();
updateDim(); updateDim();
} else if(dim->X.isTouched() || } else if(dim->X.isTouched() ||
dim->Y.isTouched()) { dim->Y.isTouched()) {
dLabel->setPosFromCenter(dim->X.getValue(), dim->Y.getValue()); datumLabel->setPosFromCenter(datumLabel->X(),datumLabel->Y());
updateDim(); updateDim();
} else { } else {
updateDim(); updateDim();
@ -261,15 +242,13 @@ void QGIViewDimension::updateDim()
const TechDraw::DrawViewDimension *dim = dynamic_cast<TechDraw::DrawViewDimension *>(getViewObject()); const TechDraw::DrawViewDimension *dim = dynamic_cast<TechDraw::DrawViewDimension *>(getViewObject());
QString labelText = QString::fromStdString(dim->getFormatedValue()); QString labelText = QString::fromStdString(dim->getFormatedValue());
QGIDatumLabel *dLabel = dynamic_cast<QGIDatumLabel *>(datumLabel); QFont font = datumLabel->font();
QFont font = dLabel->font();
font.setPointSizeF(dim->Fontsize.getValue()); //scene units (mm), not points font.setPointSizeF(dim->Fontsize.getValue()); //scene units (mm), not points
font.setFamily(QString::fromAscii(dim->Font.getValue())); font.setFamily(QString::fromAscii(dim->Font.getValue()));
dLabel->setPlainText(labelText); datumLabel->setPlainText(labelText);
dLabel->setFont(font); datumLabel->setFont(font);
dLabel->setPosFromCenter(dLabel->X(),dLabel->Y()); datumLabel->setPosFromCenter(datumLabel->X(),datumLabel->Y());
} }
void QGIViewDimension::datumLabelDragged() void QGIViewDimension::datumLabelDragged()
@ -283,10 +262,9 @@ void QGIViewDimension::datumLabelDragFinished()
return; return;
TechDraw::DrawViewDimension *dim = dynamic_cast<TechDraw::DrawViewDimension *>(getViewObject()); TechDraw::DrawViewDimension *dim = dynamic_cast<TechDraw::DrawViewDimension *>(getViewObject());
QGIDatumLabel *datumLbl = dynamic_cast<QGIDatumLabel *>(datumLabel);
double x = datumLbl->X(), double x = datumLabel->X(),
y = datumLbl->Y(); y = datumLabel->Y();
Gui::Command::openCommand("Drag Dimension"); Gui::Command::openCommand("Drag Dimension");
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.X = %f", dim->getNameInDocument(), x); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.X = %f", dim->getNameInDocument(), x);
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Y = %f", dim->getNameInDocument(), y); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Y = %f", dim->getNameInDocument(), y);
@ -307,7 +285,6 @@ void QGIViewDimension::draw()
return; return;
} }
QGIDatumLabel *lbl = dynamic_cast<QGIDatumLabel *>(datumLabel);
const TechDraw::DrawViewPart *refObj = dim->getViewPart(); const TechDraw::DrawViewPart *refObj = dim->getViewPart();
if(!refObj->hasGeometry()) { //nothing to draw yet (restoring) if(!refObj->hasGeometry()) { //nothing to draw yet (restoring)
return; return;
@ -325,8 +302,8 @@ void QGIViewDimension::draw()
m_pen.setColor(getNormalColor()); m_pen.setColor(getNormalColor());
} }
QString labelText = lbl->toPlainText(); QString labelText = datumLabel->toPlainText();
Base::Vector3d lblCenter(lbl->X(), lbl->Y(), 0); Base::Vector3d lblCenter(datumLabel->X(), datumLabel->Y(), 0);
//we always draw based on Projected geometry. //we always draw based on Projected geometry.
//const std::vector<App::DocumentObject*> &objects = dim->References2D.getValues(); //const std::vector<App::DocumentObject*> &objects = dim->References2D.getValues();
@ -354,7 +331,7 @@ void QGIViewDimension::draw()
distStart = Base::Vector3d(pnt1.fX, pnt1.fY, 0.); distStart = Base::Vector3d(pnt1.fX, pnt1.fY, 0.);
distEnd = Base::Vector3d(pnt2.fX, pnt2.fY, 0.); distEnd = Base::Vector3d(pnt2.fX, pnt2.fY, 0.);
} else { } else {
throw Base::Exception("FVD::draw - Original edge not found or is invalid type (1)"); throw Base::Exception("QGIVD::draw - Original edge not found or is invalid type (1)");
} }
} else if(dim->References2D.getValues().size() == 2 && } else if(dim->References2D.getValues().size() == 2 &&
TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Vertex" && TechDraw::DrawUtil::getGeomTypeFromName(SubNames[0]) == "Vertex" &&
@ -450,7 +427,7 @@ void QGIViewDimension::draw()
//Base::Vector3d midpos = (distStart_ + distEnd) / 2; //Base::Vector3d midpos = (distStart_ + distEnd) / 2;
QFontMetrics fm(lbl->font()); QFontMetrics fm(datumLabel->font());
int w = fm.width(labelText); int w = fm.width(labelText);
//int h = fm.height(); //int h = fm.height();
@ -518,66 +495,40 @@ void QGIViewDimension::draw()
path.moveTo(dim2Tip.x, dim2Tip.y); path.moveTo(dim2Tip.x, dim2Tip.y);
path.lineTo(dim2Tail.x, dim2Tail.y); path.lineTo(dim2Tail.x, dim2Tail.y);
QGraphicsPathItem *arrw = dynamic_cast<QGraphicsPathItem *> (dimLines); dimLines->setPath(path);
arrw->setPath(path);
arrw->setPen(m_pen);
// Note Bounding Box size is not the same width or height as text (only used for finding center) // Note Bounding Box size is not the same width or height as text (only used for finding center)
float bbX = lbl->boundingRect().width(); float bbX = datumLabel->boundingRect().width();
float bbY = lbl->boundingRect().height(); float bbY = datumLabel->boundingRect().height();
lbl->setTransformOriginPoint(bbX / 2, bbY /2); datumLabel->setTransformOriginPoint(bbX / 2, bbY /2);
double angleOption = 0.0; //put lblText angle adjustments here double angleOption = 0.0; //put lblText angle adjustments here
lbl->setRotation((angle * 180 / M_PI) + angleOption); datumLabel->setRotation((angle * 180 / M_PI) + angleOption);
if(arrowHeads.size() != 2) {
prepareGeometryChange();
for(std::vector<QGraphicsPathItem*>::iterator it = arrowHeads.begin(); it != arrowHeads.end(); ++it) {
removeFromGroup(*it);
delete (*it);
}
arrowHeads.clear();
// These items are added to the scene-graph so should be handled by the canvas
QGIArrow *ar1 = new QGIArrow(); //arrowhead
QGIArrow *ar2 = new QGIArrow();
arrowHeads.push_back(ar1);
arrowHeads.push_back(ar2);
ar1->draw();
ar2->flip(true);
ar2->draw();
addToGroup(arrowHeads.at(0));
addToGroup(arrowHeads.at(1));
}
QGIArrow *ar1 = dynamic_cast<QGIArrow *>(arrowHeads.at(0));
QGIArrow *ar2 = dynamic_cast<QGIArrow *>(arrowHeads.at(1));
aHead1->draw();
aHead2->flip(true);
aHead2->draw();
angle = atan2f(dir[1],dir[0]); angle = atan2f(dir[1],dir[0]);
float arrowAngle = angle * 180 / M_PI; float arrowAngle = angle * 180 / M_PI;
arrowAngle -= 180.; arrowAngle -= 180.;
if(flipTriang){ if(flipTriang){
ar1->setRotation(arrowAngle + 180.); aHead1->setRotation(arrowAngle + 180.);
ar2->setRotation(arrowAngle + 180.); aHead2->setRotation(arrowAngle + 180.);
} else { } else {
ar1->setRotation(arrowAngle); aHead1->setRotation(arrowAngle);
ar2->setRotation(arrowAngle); aHead2->setRotation(arrowAngle);
} }
ar1->setPos(dim1Tip.x, dim1Tip.y); aHead1->setPos(dim1Tip.x, dim1Tip.y);
ar2->setPos(dim2Tail.x, dim2Tail.y); aHead2->setPos(dim2Tail.x, dim2Tail.y);
ar1->setHighlighted(isSelected() || hasHover); aHead1->setHighlighted(isSelected() || hasHover); //setPrettyxxx??
ar2->setHighlighted(isSelected() || hasHover); aHead2->setHighlighted(isSelected() || hasHover);
} else if(strcmp(dimType, "Diameter") == 0) { } else if(strcmp(dimType, "Diameter") == 0) {
// terminology: Dimension Text, Dimension Line(s), Extension Lines, Arrowheads // terminology: Dimension Text, Dimension Line(s), Extension Lines, Arrowheads
// was datumLabel, datum line/parallel line, perpendicular line, arw // was datumLabel, datum line/parallel line, perpendicular line, arw
Base::Vector3d arrow1Tip, arrow2Tip, dirDimLine, centre; //was p1,p2,dir Base::Vector3d arrow1Tip, arrow2Tip, dirDimLine, centre; //was p1,p2,dir
QGIDatumLabel *label = dynamic_cast<QGIDatumLabel *>(datumLabel); Base::Vector3d lblCenter(datumLabel->X(), datumLabel->Y(), 0);
Base::Vector3d lblCenter(label->X(), label->Y(), 0);
double radius; double radius;
if(dim->References2D.getValues().size() == 1 && if(dim->References2D.getValues().size() == 1 &&
@ -602,8 +553,8 @@ void QGIViewDimension::draw()
throw Base::Exception("FVD ::draw - Invalid reference for dimension type (2)"); throw Base::Exception("FVD ::draw - Invalid reference for dimension type (2)");
} }
// Note Bounding Box size is not the same width or height as text (only used for finding center) // Note Bounding Box size is not the same width or height as text (only used for finding center)
float bbX = label->boundingRect().width(); float bbX = datumLabel->boundingRect().width();
float bbY = label->boundingRect().height(); float bbY = datumLabel->boundingRect().height();
dirDimLine = (lblCenter - centre).Normalize(); //if lblCenter == centre, this is (0,0,0)?? dirDimLine = (lblCenter - centre).Normalize(); //if lblCenter == centre, this is (0,0,0)??
if (fabs(dirDimLine.Length()) < (Precision::Confusion())) { if (fabs(dirDimLine.Length()) < (Precision::Confusion())) {
@ -614,7 +565,7 @@ void QGIViewDimension::draw()
arrow1Tip = centre - dirDimLine * radius; //endpoint of diameter arrowhead1 arrow1Tip = centre - dirDimLine * radius; //endpoint of diameter arrowhead1
arrow2Tip = centre + dirDimLine * radius; //endpoint of diameter arrowhead2 arrow2Tip = centre + dirDimLine * radius; //endpoint of diameter arrowhead2
QFontMetrics fm(label->font()); QFontMetrics fm(datumLabel->font());
int w = fm.width(labelText); int w = fm.width(labelText);
//int h = fm.height(); //int h = fm.height();
@ -632,7 +583,7 @@ void QGIViewDimension::draw()
} }
// Reset transformation origin for datum label // Reset transformation origin for datum label
label->setTransformOriginPoint(bbX / 2, bbY /2); datumLabel->setTransformOriginPoint(bbX / 2, bbY /2);
int posMode = NoSnap; int posMode = NoSnap;
QPainterPath path; QPainterPath path;
@ -685,7 +636,7 @@ void QGIViewDimension::draw()
path.moveTo(dLine2Tail.x, dLine2Tail.y); path.moveTo(dLine2Tail.x, dLine2Tail.y);
path.lineTo(arrow2Tip.x, arrow2Tip.y); path.lineTo(arrow2Tip.x, arrow2Tip.y);
label->setRotation(0.); datumLabel->setRotation(0.);
} else if(posMode == HorizontalSnap) { } else if(posMode == HorizontalSnap) {
// Snapped Horizontally // Snapped Horizontally
@ -719,7 +670,7 @@ void QGIViewDimension::draw()
path.moveTo(dLine2Tail.x, dLine2Tail.y); path.moveTo(dLine2Tail.x, dLine2Tail.y);
path.lineTo(arrow2Tip.x, arrow2Tip.y); path.lineTo(arrow2Tip.x, arrow2Tip.y);
label->setRotation(90.); datumLabel->setRotation(90.);
} else { //outer placement, NoSnap } else { //outer placement, NoSnap
float tip = (margin + w / 2); // spacer + 0.5*lblText.width() tip is actually tail? float tip = (margin + w / 2); // spacer + 0.5*lblText.width() tip is actually tail?
@ -739,11 +690,11 @@ void QGIViewDimension::draw()
path.lineTo(arrow2Tip.x, arrow2Tip.y); path.lineTo(arrow2Tip.x, arrow2Tip.y);
label->setRotation(0.); datumLabel->setRotation(0.);
} }
} else { //NOT outerplacement ie dimLines are inside circle } else { //NOT outerplacement ie dimLines are inside circle
//text always rightside up inside circle //text always rightside up inside circle
label->setRotation(0); datumLabel->setRotation(0);
dLine1Tail = centre - dirDimLine * margin; dLine1Tail = centre - dirDimLine * margin;
dLine2Tail = centre + dirDimLine * margin; dLine2Tail = centre + dirDimLine * margin;
@ -754,12 +705,9 @@ void QGIViewDimension::draw()
path.lineTo(arrow2Tip.x, arrow2Tip.y); path.lineTo(arrow2Tip.x, arrow2Tip.y);
} }
QGraphicsPathItem *arrw = dynamic_cast<QGraphicsPathItem *> (dimLines); dimLines->setPath(path);
arrw->setPath(path);
arrw->setPen(m_pen);
// Add or remove centre lines // Add or remove centre lines
QGraphicsPathItem *clines = dynamic_cast<QGraphicsPathItem *> (centerMark);
QPainterPath clpath; QPainterPath clpath;
if(dim->CentreLines.getValue()) { if(dim->CentreLines.getValue()) {
@ -779,66 +727,44 @@ void QGIViewDimension::draw()
clpath.lineTo(centre.x + clDist, centre.y); clpath.lineTo(centre.x + clDist, centre.y);
} }
clines->setPath(clpath); centerMark->setPath(clpath);
// Create Two Arrows always (but sometimes hide one!) aHead1->draw();
if(arrowHeads.size() != 2) { aHead2->flip(true);
prepareGeometryChange(); aHead2->draw();
for(std::vector<QGraphicsPathItem*>::iterator it = arrowHeads.begin(); it != arrowHeads.end(); ++it) {
removeFromGroup(*it);
delete (*it);
}
arrowHeads.clear();
// These items are added to the group so group will handle deletion
QGIArrow *ar1 = new QGIArrow();
QGIArrow *ar2 = new QGIArrow();
arrowHeads.push_back(ar1);
arrowHeads.push_back(ar2);
ar1->draw();
ar2->flip(true);
ar2->draw();
addToGroup(arrowHeads.at(0));
addToGroup(arrowHeads.at(1));
}
QGIArrow *ar1 = dynamic_cast<QGIArrow *>(arrowHeads.at(0));
QGIArrow *ar2 = dynamic_cast<QGIArrow *>(arrowHeads.at(1));
float arAngle = atan2(dirDimLine.y, dirDimLine.x) * 180 / M_PI; float arAngle = atan2(dirDimLine.y, dirDimLine.x) * 180 / M_PI;
ar1->setHighlighted(isSelected() || hasHover); aHead1->setHighlighted(isSelected() || hasHover);
ar2->setHighlighted(isSelected() || hasHover); aHead2->setHighlighted(isSelected() || hasHover);
ar2->show(); aHead2->show();
if(outerPlacement) { if(outerPlacement) {
if(posMode > NoSnap) { if(posMode > NoSnap) {
ar1->setPos(arrow2Tip.x, arrow2Tip.y); //arrow 1's endpoint is arrow2Tip!? aHead1->setPos(arrow2Tip.x, arrow2Tip.y); //arrow 1's endpoint is arrow2Tip!?
ar2->setPos(arrow1Tip.x, arrow1Tip.y); aHead2->setPos(arrow1Tip.x, arrow1Tip.y);
ar1->setRotation((posMode == HorizontalSnap) ? 90 : 0); aHead1->setRotation((posMode == HorizontalSnap) ? 90 : 0);
ar2->setRotation((posMode == HorizontalSnap) ? 90 : 0); aHead2->setRotation((posMode == HorizontalSnap) ? 90 : 0);
} else { } else {
Base::Vector3d vec = (arrow2Tip - centre).Normalize(); Base::Vector3d vec = (arrow2Tip - centre).Normalize();
float arAngle = atan2(-vec.y, -vec.x) * 180 / M_PI; float arAngle = atan2(-vec.y, -vec.x) * 180 / M_PI;
ar1->setPos(arrow2Tip.x, arrow2Tip.y); aHead1->setPos(arrow2Tip.x, arrow2Tip.y);
ar1->setRotation(arAngle); aHead1->setRotation(arAngle);
ar2->hide(); //only 1 arrowhead for NoSnap + outerplacement (ie a leader) aHead2->hide(); //only 1 arrowhead for NoSnap + outerplacement (ie a leader)
} }
} else { } else {
ar1->setRotation(arAngle); aHead1->setRotation(arAngle);
ar2->setRotation(arAngle); aHead2->setRotation(arAngle);
ar1->setPos(arrow2Tip.x, arrow2Tip.y); aHead1->setPos(arrow2Tip.x, arrow2Tip.y);
ar2->show(); aHead2->show();
ar2->setPos(arrow1Tip.x, arrow1Tip.y); aHead2->setPos(arrow1Tip.x, arrow1Tip.y);
} }
} else if(strcmp(dimType, "Radius") == 0) { } else if(strcmp(dimType, "Radius") == 0) {
// preferred terminology: Dimension Text, Dimension Line(s), Extension Lines, Arrowheads // preferred terminology: Dimension Text, Dimension Line(s), Extension Lines, Arrowheads
// radius gets 1 dimension line from the dimension text to a point on the curve // radius gets 1 dimension line from the dimension text to a point on the curve
QGIDatumLabel *label = dynamic_cast<QGIDatumLabel *>(datumLabel); Base::Vector3d lblCenter(datumLabel->X(), datumLabel->Y(),0.0);
Base::Vector3d lblCenter(label->X(), label->Y(),0.0);
Base::Vector3d pointOnCurve,curveCenter; Base::Vector3d pointOnCurve,curveCenter;
double radius; double radius;
@ -868,13 +794,13 @@ void QGIViewDimension::draw()
throw Base::Exception("FVD::draw - Invalid reference for dimension type (3)"); throw Base::Exception("FVD::draw - Invalid reference for dimension type (3)");
} }
QFontMetrics fm(label->font()); QFontMetrics fm(datumLabel->font());
int w = fm.width(labelText); int w = fm.width(labelText);
// Note Bounding Box size is not the same width or height as text (only used for finding center) // Note Bounding Box size is not the same width or height as text (only used for finding center)
float bbX = label->boundingRect().width(); float bbX = datumLabel->boundingRect().width();
float bbY = label->boundingRect().height(); float bbY = datumLabel->boundingRect().height();
label->setTransformOriginPoint(bbX / 2, bbY /2); datumLabel->setTransformOriginPoint(bbX / 2, bbY /2);
label->setRotation(0.0); //label is always right side up & horizontal datumLabel->setRotation(0.0); //label is always right side up & horizontal
//if inside the arc (len(DimLine < radius)) arrow goes from center to edge away from label //if inside the arc (len(DimLine < radius)) arrow goes from center to edge away from label
//if inside the arc arrow kinks, then goes to edge nearest label //if inside the arc arrow kinks, then goes to edge nearest label
@ -916,12 +842,9 @@ void QGIViewDimension::draw()
dLinePath.lineTo(kinkPoint.x, kinkPoint.y); dLinePath.lineTo(kinkPoint.x, kinkPoint.y);
dLinePath.lineTo(pointOnCurve.x, pointOnCurve.y); dLinePath.lineTo(pointOnCurve.x, pointOnCurve.y);
QGraphicsPathItem *arrw = dynamic_cast<QGraphicsPathItem *> (dimLines); dimLines->setPath(dLinePath);
arrw->setPath(dLinePath);
arrw->setPen(m_pen);
// Add or remove centre lines (wf - this is centermark, not centerlines) // Add or remove centre lines (wf - this is centermark, not centerlines)
QGraphicsPathItem *clines = dynamic_cast<QGraphicsPathItem *> (centerMark);
QPainterPath clpath; QPainterPath clpath;
if(dim->CentreLines.getValue()) { if(dim->CentreLines.getValue()) {
// Add centre lines to the circle // Add centre lines to the circle
@ -937,45 +860,22 @@ void QGIViewDimension::draw()
clpath.moveTo(curveCenter.x - clDist, curveCenter.y); clpath.moveTo(curveCenter.x - clDist, curveCenter.y);
clpath.lineTo(curveCenter.x + clDist, curveCenter.y); clpath.lineTo(curveCenter.x + clDist, curveCenter.y);
} }
clines->setPath(clpath); centerMark->setPath(clpath);
// Always create Two Arrows (but sometimes hide 1!) aHead1->flip(true);
QGIArrow *ar1; aHead1->draw();
QGIArrow *ar2; aHead2->draw();
if(arrowHeads.size() != 2) {
prepareGeometryChange();
for(std::vector<QGraphicsPathItem*>::iterator it = arrowHeads.begin(); it != arrowHeads.end(); ++it) {
removeFromGroup(*it);
delete (*it);
}
arrowHeads.clear();
// These items are added to the scene-graph so should be handled by the canvas
ar1 = new QGIArrow();
ar2 = new QGIArrow();
arrowHeads.push_back(ar1);
arrowHeads.push_back(ar2);
ar1->flip(true);
ar1->draw();
ar2->draw();
addToGroup(arrowHeads.at(0));
addToGroup(arrowHeads.at(1));
}
ar1 = dynamic_cast<QGIArrow *>(arrowHeads.at(0));
ar2 = dynamic_cast<QGIArrow *>(arrowHeads.at(1));
Base::Vector3d ar1Pos = pointOnCurve; Base::Vector3d ar1Pos = pointOnCurve;
float arAngle = atan2(dirDimLine.y, dirDimLine.x) * 180 / M_PI; float arAngle = atan2(dirDimLine.y, dirDimLine.x) * 180 / M_PI;
ar1->setPos(ar1Pos.x, ar1Pos.y); aHead1->setPos(ar1Pos.x, ar1Pos.y);
ar1->setRotation(arAngle); aHead1->setRotation(arAngle);
ar1->setHighlighted(isSelected() || hasHover); aHead1->setHighlighted(isSelected() || hasHover);
ar1->show(); aHead1->show();
ar2->setRotation(arAngle); aHead2->setRotation(arAngle);
ar2->setHighlighted(isSelected() || hasHover); aHead2->setHighlighted(isSelected() || hasHover);
ar2->hide(); aHead2->hide();
} else if(strcmp(dimType, "Angle") == 0) { } else if(strcmp(dimType, "Angle") == 0) {
// Only use two straight line edeges for angle // Only use two straight line edeges for angle
if(dim->References2D.getValues().size() == 2 && if(dim->References2D.getValues().size() == 2 &&
@ -1042,14 +942,13 @@ void QGIViewDimension::draw()
double endangle = startangle + range; double endangle = startangle + range;
// Obtain the Label Position and measure the length between intersection // Obtain the Label Position and measure the length between intersection
QGIDatumLabel *label = dynamic_cast<QGIDatumLabel *>(datumLabel); Base::Vector3d lblCenter(datumLabel->X(), datumLabel->Y(), 0);
Base::Vector3d lblCenter(label->X(), label->Y(), 0);
float bbX = label->boundingRect().width(); float bbX = datumLabel->boundingRect().width();
float bbY = label->boundingRect().height(); float bbY = datumLabel->boundingRect().height();
// Get font height // Get font height
QFontMetrics fm(label->font()); QFontMetrics fm(datumLabel->font());
int h = fm.height(); int h = fm.height();
double length = labelVec.Length(); double length = labelVec.Length();
@ -1154,35 +1053,11 @@ void QGIViewDimension::draw()
path.arcTo(arcRect, endangle * 180 / M_PI, -range * 180 / M_PI); path.arcTo(arcRect, endangle * 180 / M_PI, -range * 180 / M_PI);
} }
QGraphicsPathItem *arrw = dynamic_cast<QGraphicsPathItem *> (dimLines); dimLines->setPath(path);
arrw->setPath(path);
arrw->setPen(m_pen);
// Add the dimLines aHead1->flip(true);
if(arrowHeads.size() != 2) { aHead1->draw();
prepareGeometryChange(); aHead2->draw();
for(std::vector<QGraphicsPathItem*>::iterator it = arrowHeads.begin(); it != arrowHeads.end(); ++it) {
removeFromGroup(*it);
delete (*it);
}
arrowHeads.clear();
// These items are added to the scene-graph so should be handled by the canvas
QGIArrow *ar1 = new QGIArrow();
QGIArrow *ar2 = new QGIArrow();
arrowHeads.push_back(ar1);
arrowHeads.push_back(ar2);
ar1->flip(true);
ar1->draw();
ar2->draw();
addToGroup(arrowHeads.at(0));
addToGroup(arrowHeads.at(1));
}
QGIArrow *ar1 = dynamic_cast<QGIArrow *>(arrowHeads.at(0));
QGIArrow *ar2 = dynamic_cast<QGIArrow *>(arrowHeads.at(1));
Base::Vector3d norm1 = p1-p0; //(-dir1.y, dir1.x, 0.); Base::Vector3d norm1 = p1-p0; //(-dir1.y, dir1.x, 0.);
Base::Vector3d norm2 = p2-p0; //(-dir2.y, dir2.x, 0.); Base::Vector3d norm2 = p2-p0; //(-dir2.y, dir2.x, 0.);
@ -1192,22 +1067,22 @@ void QGIViewDimension::draw()
norm1 = norm1.ProjectToLine(avg, norm1); norm1 = norm1.ProjectToLine(avg, norm1);
norm2 = norm2.ProjectToLine(avg, norm2); norm2 = norm2.ProjectToLine(avg, norm2);
ar1->setPos(ar1Pos.x,ar1Pos.y ); aHead1->setPos(ar1Pos.x,ar1Pos.y );
ar2->setPos(ar2Pos.x,ar2Pos.y ); aHead2->setPos(ar2Pos.x,ar2Pos.y );
float ar1angle = atan2(-norm1.y, -norm1.x) * 180 / M_PI; float ar1angle = atan2(-norm1.y, -norm1.x) * 180 / M_PI;
float ar2angle = atan2(norm2.y, norm2.x) * 180 / M_PI; float ar2angle = atan2(norm2.y, norm2.x) * 180 / M_PI;
if(isOutside) { if(isOutside) {
ar1->setRotation(ar1angle + 180.); aHead1->setRotation(ar1angle + 180.);
ar2->setRotation(ar2angle + 180.); aHead2->setRotation(ar2angle + 180.);
} else { } else {
ar1->setRotation(ar1angle); aHead1->setRotation(ar1angle);
ar2->setRotation(ar2angle); aHead2->setRotation(ar2angle);
} }
ar1->setHighlighted(isSelected() || hasHover); aHead1->setHighlighted(isSelected() || hasHover);
ar2->setHighlighted(isSelected() || hasHover); aHead2->setHighlighted(isSelected() || hasHover);
// Set the angle of the datum text // Set the angle of the datum text
@ -1220,9 +1095,9 @@ void QGIViewDimension::draw()
lAngle += M_PI; lAngle += M_PI;
} }
label->setTransformOriginPoint(bbX / 2., bbY /2.); datumLabel->setTransformOriginPoint(bbX / 2., bbY /2.);
label->setRotation(lAngle * 180 / M_PI); datumLabel->setRotation(lAngle * 180 / M_PI);
} else { } else {
throw Base::Exception("FVD::draw - Invalid reference for dimension type (4)"); throw Base::Exception("FVD::draw - Invalid reference for dimension type (4)");
@ -1250,12 +1125,10 @@ void QGIViewDimension::drawBorder(void)
QVariant QGIViewDimension::itemChange(GraphicsItemChange change, const QVariant &value) QVariant QGIViewDimension::itemChange(GraphicsItemChange change, const QVariant &value)
{ {
if (change == ItemSelectedHasChanged && scene()) { if (change == ItemSelectedHasChanged && scene()) {
QGIDatumLabel *dLabel = dynamic_cast<QGIDatumLabel *>(datumLabel);
if(isSelected()) { if(isSelected()) {
dLabel->setSelected(true); datumLabel->setSelected(true);
} else { } else {
dLabel->setSelected(false); datumLabel->setSelected(false);
} }
draw(); draw();
} }
@ -1285,9 +1158,8 @@ void QGIViewDimension::setSvgPens(void)
double svgLineFactor = 3.0; //magic number. should be a setting somewhere. double svgLineFactor = 3.0; //magic number. should be a setting somewhere.
m_pen.setWidthF(m_pen.widthF()/svgLineFactor); m_pen.setWidthF(m_pen.widthF()/svgLineFactor);
dimLines->setPen(m_pen); dimLines->setPen(m_pen);
for (auto& a:arrowHeads) { aHead1->setPen(m_pen);
a->setPen(m_pen); aHead2->setPen(m_pen);
}
m_clPen.setWidthF(m_clPen.widthF()/svgLineFactor); m_clPen.setWidthF(m_clPen.widthF()/svgLineFactor);
centerMark->setPen(m_clPen); centerMark->setPen(m_clPen);
} }
@ -1295,9 +1167,8 @@ void QGIViewDimension::setSvgPens(void)
void QGIViewDimension::setPens(void) void QGIViewDimension::setPens(void)
{ {
dimLines->setPen(m_pen); dimLines->setPen(m_pen);
for (auto& a:arrowHeads) { aHead1->setPen(m_pen);
a->setPen(m_pen); aHead2->setPen(m_pen);
}
centerMark->setPen(m_clPen); centerMark->setPen(m_clPen);
} }

View File

@ -26,6 +26,7 @@
#include <QObject> #include <QObject>
#include <QGraphicsView> #include <QGraphicsView>
#include <QStyleOptionGraphicsItem> #include <QStyleOptionGraphicsItem>
#include <QGraphicsPathItem>
#include "QGIView.h" #include "QGIView.h"
#include "QGCustomText.h" #include "QGCustomText.h"
@ -39,13 +40,14 @@ class BaseGeom;
namespace TechDrawGui namespace TechDrawGui
{ {
class QGIArrow;
class QGIDatumLabel : public QGCustomText class QGIDatumLabel : public QGCustomText
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit QGIDatumLabel(int ref = -1, QGraphicsScene *scene = 0 ); explicit QGIDatumLabel();
~QGIDatumLabel() {} ~QGIDatumLabel() {}
enum {Type = QGraphicsItem::UserType + 107}; enum {Type = QGraphicsItem::UserType + 107};
@ -70,15 +72,10 @@ protected:
// Selection detection // Selection detection
QVariant itemChange(GraphicsItemChange change, const QVariant &value); QVariant itemChange(GraphicsItemChange change, const QVariant &value);
int reference;
double posX; double posX;
double posY; double posY;
private: private:
//QPen m_pen;
QColor m_colNormal;
QColor m_colPre;
QColor m_colSel;
}; };
class TechDrawGuiExport QGIViewDimension : public QObject, public QGIView class TechDrawGuiExport QGIViewDimension : public QObject, public QGIView
@ -114,10 +111,11 @@ protected:
protected: protected:
bool hasHover; bool hasHover;
QGIDatumLabel* datumLabel; //dimension text QGIDatumLabel* datumLabel; //dimension text
QGraphicsPathItem *dimLines; //dimension lines + extension lines QGraphicsPathItem* dimLines; //dimension lines + extension lines
QGraphicsPathItem* centerMark; QGraphicsPathItem* centerMark;
std::vector<QGraphicsPathItem *> arrowHeads; QGIArrow* aHead1;
QPen m_pen; QGIArrow* aHead2;
//QPen m_pen;
QPen m_clPen; QPen m_clPen;
}; };

View File

@ -28,7 +28,6 @@
#include <Base/Parameter.h> #include <Base/Parameter.h>
#include <Mod/TechDraw/App/Geometry.h> #include <Mod/TechDraw/App/Geometry.h>
#include "QGCustomBorder.h"
#include "QGIView.h" #include "QGIView.h"
namespace TechDraw { namespace TechDraw {

View File

@ -80,7 +80,7 @@
using namespace TechDrawGui; using namespace TechDrawGui;
QGVPage::QGVPage(ViewProviderPage *vp, QGraphicsScene& s, QWidget *parent) QGVPage::QGVPage(ViewProviderPage *vp, QGraphicsScene* s, QWidget *parent)
: QGraphicsView(parent) : QGraphicsView(parent)
, pageTemplate(0) , pageTemplate(0)
, m_renderer(Native) , m_renderer(Native)
@ -92,7 +92,7 @@ QGVPage::QGVPage(ViewProviderPage *vp, QGraphicsScene& s, QWidget *parent)
const char* name = vp->getPageObject()->getNameInDocument(); const char* name = vp->getPageObject()->getNameInDocument();
setObjectName(QString::fromLocal8Bit(name)); setObjectName(QString::fromLocal8Bit(name));
setScene(&s); setScene(s);
//setViewportUpdateMode(QGraphicsView::FullViewportUpdate); //setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
setCacheMode(QGraphicsView::CacheBackground); setCacheMode(QGraphicsView::CacheBackground);
setTransformationAnchor(AnchorUnderMouse); setTransformationAnchor(AnchorUnderMouse);

View File

@ -53,7 +53,7 @@ class TechDrawGuiExport QGVPage : public QGraphicsView
public: public:
enum RendererType { Native, OpenGL, Image }; enum RendererType { Native, OpenGL, Image };
QGVPage(ViewProviderPage *vp, QGraphicsScene& s, QWidget *parent = 0); QGVPage(ViewProviderPage *vp, QGraphicsScene* s, QWidget *parent = 0);
~QGVPage(); ~QGVPage();
void setRenderer(RendererType type = Native); void setRenderer(RendererType type = Native);