[TechDraw] Reimplement Rich Annotation parent linking
This commit is contained in:
@@ -80,6 +80,7 @@
|
||||
#include "QGIWeldSymbol.h"
|
||||
#include "QGSPage.h"
|
||||
#include "Rez.h"
|
||||
#include "ViewProviderDrawingView.h"
|
||||
#include "ViewProviderPage.h"
|
||||
#include "ZVALUE.h"
|
||||
|
||||
@@ -129,7 +130,6 @@ void QGSPage::addChildrenToPage()
|
||||
setDimensionGroups();
|
||||
setBalloonGroups();
|
||||
setLeaderGroups();
|
||||
setRichAnnoGroups();
|
||||
|
||||
App::DocumentObject* obj = m_vpPage->getDrawPage()->Template.getValue();
|
||||
auto pageTemplate(dynamic_cast<TechDraw::DrawTemplate*>(obj));
|
||||
@@ -251,23 +251,23 @@ int QGSPage::addQView(QGIView* view)
|
||||
if (!existing) {
|
||||
addItem(view);
|
||||
|
||||
TechDraw::DrawView *viewObj = view->getViewObject();
|
||||
// Preserve the desired position, as addToGroup() adjusts the child view's position
|
||||
QPointF viewPos(Rez::guiX(viewObj->X.getValue()), -Rez::guiX(viewObj->Y.getValue()));
|
||||
|
||||
// Find if it belongs to a parent
|
||||
QGIView* parent = nullptr;
|
||||
parent = findParent(view);
|
||||
|
||||
QPointF viewPos(Rez::guiX(view->getViewObject()->X.getValue()),
|
||||
Rez::guiX(view->getViewObject()->Y.getValue() * -1));
|
||||
|
||||
QGIView *parent = findParent(view);
|
||||
if (parent) {
|
||||
// move child view to center of parent
|
||||
QPointF posRef(0., 0.);
|
||||
QPointF mapPos = view->mapToItem(parent, posRef);
|
||||
view->moveBy(-mapPos.x(), -mapPos.y());
|
||||
|
||||
parent->addToGroup(view);
|
||||
}
|
||||
|
||||
view->setPos(viewPos);
|
||||
|
||||
auto viewProvider = dynamic_cast<ViewProviderDrawingView *>(QGIView::getViewProvider(view->getViewObject()));
|
||||
if (viewProvider) {
|
||||
view->setZValue(viewProvider->StackOrder.getValue());
|
||||
}
|
||||
|
||||
view->updateView(true);
|
||||
}
|
||||
return 0;
|
||||
@@ -447,19 +447,11 @@ QGIView* QGSPage::addDrawViewAnnotation(TechDraw::DrawViewAnnotation* annoFeat)
|
||||
|
||||
QGIView* QGSPage::addDrawViewSymbol(TechDraw::DrawViewSymbol* symbolFeat)
|
||||
{
|
||||
auto qview(new QGIViewSymbol);
|
||||
qview->setViewFeature(symbolFeat);
|
||||
QGIViewSymbol *symbolView = new QGIViewSymbol;
|
||||
symbolView->setViewFeature(symbolFeat);
|
||||
|
||||
auto owner = dynamic_cast<TechDraw::DrawView *>(symbolFeat->Owner.getValue());
|
||||
if (owner) {
|
||||
auto parent = dynamic_cast<QGIView *>(findQViewForDocObj(owner));
|
||||
if (parent) {
|
||||
qview->switchParentItem(parent);
|
||||
}
|
||||
}
|
||||
|
||||
addQView(qview);
|
||||
return qview;
|
||||
addQView(symbolView);
|
||||
return symbolView;
|
||||
}
|
||||
|
||||
QGIView* QGSPage::addDrawViewClip(TechDraw::DrawViewClip* view)
|
||||
@@ -631,27 +623,13 @@ void QGSPage::addLeaderToParent(QGILeaderLine* lead, QGIView* parent)
|
||||
|
||||
QGIView* QGSPage::addRichAnno(TechDraw::DrawRichAnno* richFeat)
|
||||
{
|
||||
QGIRichAnno* annoGroup = new QGIRichAnno();
|
||||
addItem(annoGroup);
|
||||
annoGroup->setViewFeature(richFeat);
|
||||
QGIRichAnno *richView = new QGIRichAnno;
|
||||
richView->setViewFeature(richFeat);
|
||||
|
||||
QGIView* parent = findParent(annoGroup);
|
||||
if (parent)
|
||||
addAnnoToParent(annoGroup, parent);
|
||||
|
||||
annoGroup->updateView(true);
|
||||
|
||||
return annoGroup;
|
||||
addQView(richView);
|
||||
return richView;
|
||||
}
|
||||
|
||||
void QGSPage::addAnnoToParent(QGIRichAnno* anno, QGIView* parent)
|
||||
{
|
||||
// Base::Console().Message("QGSP::addAnnoToParent()\n");
|
||||
parent->addToGroup(anno);
|
||||
anno->setZValue(ZVALUE::DIMENSION);
|
||||
}
|
||||
|
||||
|
||||
QGIView* QGSPage::addWeldSymbol(TechDraw::DrawWeldSymbol* weldFeat)
|
||||
{
|
||||
// Base::Console().Message("QGSP::addWeldSymbol()\n");
|
||||
@@ -729,24 +707,6 @@ void QGSPage::setLeaderGroups(void)
|
||||
}
|
||||
}
|
||||
|
||||
void QGSPage::setRichAnnoGroups(void)
|
||||
{
|
||||
// Base::Console().Message("QGSP::setRichAnnoGroups()\n");
|
||||
const std::vector<QGIView*>& allItems = getViews();
|
||||
int annoItemType = QGraphicsItem::UserType + 233;
|
||||
|
||||
//make sure that qgirichanno belongs to correct parent.
|
||||
for (auto& item : allItems) {
|
||||
if (item->type() == annoItemType && !item->group()) {
|
||||
QGIView* parent = findParent(item);
|
||||
if (parent) {
|
||||
QGIRichAnno* anno = dynamic_cast<QGIRichAnno*>(item);
|
||||
addAnnoToParent(anno, parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//! find the graphic for a DocumentObject
|
||||
QGIView* QGSPage::findQViewForDocObj(App::DocumentObject* obj) const
|
||||
{
|
||||
@@ -762,7 +722,7 @@ QGIView* QGSPage::findQViewForDocObj(App::DocumentObject* obj) const
|
||||
}
|
||||
|
||||
//! find the graphic for DocumentObject with name
|
||||
QGIView* QGSPage::getQGIVByName(std::string name)
|
||||
QGIView* QGSPage::getQGIVByName(std::string name) const
|
||||
{
|
||||
QList<QGraphicsItem*> qgItems = items();
|
||||
QList<QGraphicsItem*>::iterator it = qgItems.begin();
|
||||
@@ -785,6 +745,14 @@ QGIView* QGSPage::findParent(QGIView* view) const
|
||||
const std::vector<QGIView*> qviews = getViews();
|
||||
TechDraw::DrawView* myFeat = view->getViewObject();
|
||||
|
||||
TechDraw::DrawView *ownerFeat = myFeat->claimParent();
|
||||
if (ownerFeat) {
|
||||
QGIView *ownerView = getQGIVByName(ownerFeat->getNameInDocument());
|
||||
if (ownerView) {
|
||||
return ownerView;
|
||||
}
|
||||
}
|
||||
|
||||
//If type is dimension we check references first
|
||||
TechDraw::DrawViewDimension* dim = nullptr;
|
||||
dim = dynamic_cast<TechDraw::DrawViewDimension*>(myFeat);
|
||||
@@ -838,21 +806,6 @@ QGIView* QGSPage::findParent(QGIView* view) const
|
||||
}
|
||||
}
|
||||
|
||||
//if type is a RichTextAnno we check AnnoParent
|
||||
TechDraw::DrawRichAnno* anno = dynamic_cast<TechDraw::DrawRichAnno*>(myFeat);
|
||||
if (anno) {
|
||||
App::DocumentObject* obj = anno->AnnoParent.getValue();
|
||||
if (obj) {
|
||||
std::string parentName = obj->getNameInDocument();
|
||||
for (std::vector<QGIView*>::const_iterator it = qviews.begin(); it != qviews.end();
|
||||
++it) {
|
||||
if (strcmp((*it)->getViewName(), parentName.c_str()) == 0) {
|
||||
return *it;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if part of view collection
|
||||
for (std::vector<QGIView*>::const_iterator it = qviews.begin(); it != qviews.end(); ++it) {
|
||||
QGIViewCollection* grp = nullptr;
|
||||
@@ -1014,8 +967,6 @@ void QGSPage::fixOrphans(bool force)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setRichAnnoGroups();//hack to fix QGIRA parentage;
|
||||
}
|
||||
|
||||
bool QGSPage::orphanExists(const char* viewName, const std::vector<App::DocumentObject*>& list)
|
||||
|
||||
Reference in New Issue
Block a user