Refactor method to base View
Auto allocate member attributes
This commit is contained in:
parent
aa8fea7ba4
commit
cb51799f60
|
@ -48,9 +48,6 @@
|
||||||
#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 "QGCustomClip.h"
|
#include "QGCustomClip.h"
|
||||||
#include "QGIViewClip.h"
|
#include "QGIViewClip.h"
|
||||||
|
@ -82,11 +79,8 @@ 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"
|
||||||
|
|
||||||
m_label = new QGCustomLabel();
|
addToGroup(&m_label);
|
||||||
addToGroup(m_label);
|
addToGroup(&m_border);
|
||||||
|
|
||||||
m_border = new QGCustomBorder();
|
|
||||||
addToGroup(m_border);
|
|
||||||
|
|
||||||
isVisible(true);
|
isVisible(true);
|
||||||
}
|
}
|
||||||
|
@ -298,27 +292,27 @@ void QGIView::drawBorder()
|
||||||
{
|
{
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
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();
|
||||||
|
@ -331,18 +325,18 @@ 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);
|
||||||
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)
|
||||||
|
@ -371,7 +365,23 @@ 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)
|
||||||
|
{
|
||||||
|
QList<QGraphicsItem*> qgItems = scene()->items();
|
||||||
|
QList<QGraphicsItem*>::iterator it = qgItems.begin();
|
||||||
|
for (; it != qgItems.end(); it++) {
|
||||||
|
QGIView* qv = dynamic_cast<QGIView*>((*it));
|
||||||
|
if (qv) {
|
||||||
|
const char* qvName = qv->getViewName();
|
||||||
|
if(name.compare(qvName) == 0) {
|
||||||
|
return (qv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor QGIView::getNormalColor()
|
QColor QGIView::getNormalColor()
|
||||||
|
|
|
@ -31,6 +31,8 @@
|
||||||
#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;
|
||||||
|
@ -39,8 +41,6 @@ QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace TechDrawGui
|
namespace TechDrawGui
|
||||||
{
|
{
|
||||||
class QGCustomBorder;
|
|
||||||
class QGCustomLabel;
|
|
||||||
|
|
||||||
class TechDrawGuiExport QGIView : public QGraphicsItemGroup
|
class TechDrawGuiExport QGIView : public QGraphicsItemGroup
|
||||||
{
|
{
|
||||||
|
@ -79,6 +79,7 @@ public:
|
||||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
|
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
QGIView* getQGIVByName(std::string name);
|
||||||
|
|
||||||
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||||
// Mouse handling
|
// Mouse handling
|
||||||
|
@ -112,8 +113,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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -47,8 +47,6 @@
|
||||||
|
|
||||||
#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;
|
||||||
|
@ -61,15 +59,13 @@ QGIViewClip::QGIViewClip()
|
||||||
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
setFlag(QGraphicsItem::ItemIsSelectable, true);
|
||||||
setFlag(QGraphicsItem::ItemIsMovable, true);
|
setFlag(QGraphicsItem::ItemIsMovable, true);
|
||||||
|
|
||||||
m_cliparea = new QGCustomClip();
|
addToGroup(&m_cliparea);
|
||||||
addToGroup(m_cliparea);
|
m_cliparea.setPos(0.,0.);
|
||||||
m_cliparea->setPos(0.,0.);
|
m_cliparea.setRect(0.,0.,5.,5.);
|
||||||
m_cliparea->setRect(0.,0.,5.,5.);
|
|
||||||
|
|
||||||
m_frame = new QGCustomRect();
|
addToGroup(&m_frame);
|
||||||
addToGroup(m_frame);
|
m_frame.setPos(0.,0.);
|
||||||
m_frame->setPos(0.,0.);
|
m_frame.setRect(0.,0.,5.,5.);
|
||||||
m_frame->setRect(0.,0.,5.,5.);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -120,15 +116,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
|
||||||
|
@ -136,10 +132,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();
|
||||||
|
@ -157,14 +153,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);
|
||||||
|
@ -173,19 +169,4 @@ void QGIViewClip::drawClip()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: at least move to QGIView
|
|
||||||
QGIView* QGIViewClip::getQGIVByName(std::string name) //should probably be method in MDIViewPage?? but qgiv can't get drawingView? or QGVPage!
|
|
||||||
{
|
|
||||||
QList<QGraphicsItem*> qgItems = scene()->items();
|
|
||||||
QList<QGraphicsItem*>::iterator it = qgItems.begin();
|
|
||||||
for (; it != qgItems.end(); it++) {
|
|
||||||
QGIView* qv = dynamic_cast<QGIView*>((*it));
|
|
||||||
if (qv) {
|
|
||||||
const char* qvName = qv->getViewName();
|
|
||||||
if(name.compare(qvName) == 0) {
|
|
||||||
return (qv);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
|
@ -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
|
||||||
{
|
{
|
||||||
|
@ -50,11 +50,10 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void drawClip();
|
void drawClip();
|
||||||
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||||
QGIView* getQGIVByName(std::string name);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QGCustomRect* m_frame;
|
QGCustomRect m_frame;
|
||||||
QGCustomClip* m_cliparea;
|
QGCustomClip m_cliparea;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user