Skip to content

Commit

Permalink
handle Leaders, Welds, Tiles and RichAnnos
Browse files Browse the repository at this point in the history
  • Loading branch information
donovaly authored and WandererFan committed Mar 5, 2020
1 parent 398bf68 commit f8d90c2
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 10 deletions.
33 changes: 33 additions & 0 deletions src/Mod/TechDraw/Gui/ViewProviderLeader.cpp
Expand Up @@ -25,6 +25,8 @@
#include "PreCompiled.h"

#ifndef _PreComp_
# include <QMessageBox>
# include <QTextStream>
#endif

#include <QMessageBox>
Expand Down Expand Up @@ -230,3 +232,34 @@ void ViewProviderLeader::handleChangedPropertyType(Base::XMLReader &reader, cons
}
}

bool ViewProviderLeader::onDelete(const std::vector<std::string> &)
{
// a leader line cannot be deleted if it has a child weld symbol

// get childs
auto childs = claimChildren();

if (!childs.empty()) {
QString bodyMessage;
QTextStream bodyMessageStream(&bodyMessage);
bodyMessageStream << qApp->translate("Std_Delete",
"You cannot delete this leader line because\n it has a weld symbol that would become broken.");
QMessageBox::warning(Gui::getMainWindow(),
qApp->translate("Std_Delete", "Object dependencies"), bodyMessage,
QMessageBox::Ok);
return false;
}
else {
return true;
}
}

bool ViewProviderLeader::canDelete(App::DocumentObject *obj) const
{
// deletions of Leader line objects don't destroy anything
// thus we can pass this action
// that the parent view cannot be deleted is handled
// in its onDelete() function
Q_UNUSED(obj)
return true;
}
2 changes: 2 additions & 0 deletions src/Mod/TechDraw/Gui/ViewProviderLeader.h
Expand Up @@ -61,6 +61,8 @@ class TechDrawGuiExport ViewProviderLeader : public ViewProviderDrawingView
virtual bool setEdit(int ModNum);
virtual void unsetEdit(int ModNum);
virtual bool doubleClicked(void);
virtual bool onDelete(const std::vector<std::string> &);
virtual bool canDelete(App::DocumentObject* obj) const;

std::vector<App::DocumentObject*> claimChildren(void) const;

Expand Down
9 changes: 9 additions & 0 deletions src/Mod/TechDraw/Gui/ViewProviderProjGroupItem.cpp
Expand Up @@ -168,6 +168,7 @@ bool ViewProviderProjGroupItem::onDelete(const std::vector<std::string> &)
// get child views
auto viewSection = getObject()->getSectionRefs();
auto viewDetail = getObject()->getDetailRefs();
auto viewLeader = getObject()->getLeaders();

if (isAnchor)
{
Expand Down Expand Up @@ -196,6 +197,14 @@ bool ViewProviderProjGroupItem::onDelete(const std::vector<std::string> &)
QMessageBox::Ok);
return false;
}
else if (!viewLeader.empty()) {
bodyMessageStream << qApp->translate("Std_Delete",
"You cannot delete this view because it has a leader line that would become broken.");
QMessageBox::warning(Gui::getMainWindow(),
qApp->translate("Std_Delete", "Object dependencies"), bodyMessage,
QMessageBox::Ok);
return false;
}
else {
return true;
}
Expand Down
9 changes: 9 additions & 0 deletions src/Mod/TechDraw/Gui/ViewProviderRichAnno.cpp
Expand Up @@ -221,3 +221,12 @@ void ViewProviderRichAnno::handleChangedPropertyType(Base::XMLReader &reader, co
}
}

bool ViewProviderRichAnno::canDelete(App::DocumentObject *obj) const
{
// deletions of RichAnno objects don't destroy anything
// thus we can pass this action
// only for information: RichAnnos that have a parent
// view will get the page as new parent if the view is deleted
Q_UNUSED(obj)
return true;
}
2 changes: 1 addition & 1 deletion src/Mod/TechDraw/Gui/ViewProviderRichAnno.h
Expand Up @@ -58,6 +58,7 @@ class TechDrawGuiExport ViewProviderRichAnno : public ViewProviderDrawingView
virtual bool setEdit(int ModNum);
virtual void unsetEdit(int ModNum);
virtual bool doubleClicked(void);
virtual bool canDelete(App::DocumentObject* obj) const;

virtual TechDraw::DrawRichAnno* getViewObject() const;
TechDraw::DrawRichAnno* getFeature() const;
Expand All @@ -72,7 +73,6 @@ class TechDrawGuiExport ViewProviderRichAnno : public ViewProviderDrawingView
private:
static App::PropertyIntegerConstraint::Constraints LineStyleRange;


};

} // namespace TechDrawGui
Expand Down
10 changes: 10 additions & 0 deletions src/Mod/TechDraw/Gui/ViewProviderTile.cpp
Expand Up @@ -84,6 +84,16 @@ void ViewProviderTile::updateData(const App::Property* prop)
// return dynamic_cast<TechDraw::DrawTile*>(pcObject);
//}

bool ViewProviderTile::canDelete(App::DocumentObject *obj) const
{
// deletions of Tile objects don't destroy anything
// thus we can pass this action
// that the deletion of its parent weld symbol is not possible
// is done in its onDelete() function
Q_UNUSED(obj)
return true;
}

TechDraw::DrawTile* ViewProviderTile::getFeature() const
{
return dynamic_cast<TechDraw::DrawTile*>(pcObject);
Expand Down
1 change: 1 addition & 0 deletions src/Mod/TechDraw/Gui/ViewProviderTile.h
Expand Up @@ -48,6 +48,7 @@ class TechDrawGuiExport ViewProviderTile : public Gui::ViewProviderDocumentObjec
/// returns a list of all possible modes
virtual std::vector<std::string> getDisplayModes(void) const;
virtual void updateData(const App::Property*);
virtual bool canDelete(App::DocumentObject *obj) const;

/* virtual TechDraw::DrawTile* getViewObject() const;*/
virtual TechDraw::DrawTile* getFeature() const;
Expand Down
9 changes: 9 additions & 0 deletions src/Mod/TechDraw/Gui/ViewProviderViewPart.cpp
Expand Up @@ -260,6 +260,7 @@ bool ViewProviderViewPart::onDelete(const std::vector<std::string> &)
// get child views
auto viewSection = getViewObject()->getSectionRefs();
auto viewDetail = getViewObject()->getDetailRefs();
auto viewLeader = getViewObject()->getLeaders();

if (!viewSection.empty()) {
bodyMessageStream << qApp->translate("Std_Delete",
Expand All @@ -277,6 +278,14 @@ bool ViewProviderViewPart::onDelete(const std::vector<std::string> &)
QMessageBox::Ok);
return false;
}
else if (!viewLeader.empty()) {
bodyMessageStream << qApp->translate("Std_Delete",
"You cannot delete this view because it has a leader line that would become broken.");
QMessageBox::warning(Gui::getMainWindow(),
qApp->translate("Std_Delete", "Object dependencies"), bodyMessage,
QMessageBox::Ok);
return false;
}
else {
return true;
}
Expand Down
48 changes: 40 additions & 8 deletions src/Mod/TechDraw/Gui/ViewProviderWeld.cpp
Expand Up @@ -24,6 +24,8 @@
#include "PreCompiled.h"

#ifndef _PreComp_
# include <QMessageBox>
# include <QTextStream>
#endif

/// Here the FreeCAD includes sorted by Base,App,Gui......
Expand Down Expand Up @@ -94,14 +96,14 @@ void ViewProviderWeld::updateData(const App::Property* prop)
ViewProviderDrawingView::updateData(prop);
}

void ViewProviderWeld::onChanged(const App::Property* p)
{
QGIView* qgiv = getQView();
if (qgiv) {
qgiv->updateView(true);
}

ViewProviderDrawingView::onChanged(p);
void ViewProviderWeld::onChanged(const App::Property* p)
{
QGIView* qgiv = getQView();
if (qgiv) {
qgiv->updateView(true);
}

ViewProviderDrawingView::onChanged(p);
}

std::vector<App::DocumentObject*> ViewProviderWeld::claimChildren(void) const
Expand Down Expand Up @@ -186,7 +188,37 @@ double ViewProviderWeld::prefTileTextAdjust(void)
return adjust;
}

bool ViewProviderWeld::onDelete(const std::vector<std::string> &)
{
// a weld cannot be deleted if it has a tile

// get childs
auto childs = claimChildren();

if (!childs.empty()) {
QString bodyMessage;
QTextStream bodyMessageStream(&bodyMessage);
bodyMessageStream << qApp->translate("Std_Delete",
"You cannot delete this weld symbol because\n it has a tile weld that would become broken.");
QMessageBox::warning(Gui::getMainWindow(),
qApp->translate("Std_Delete", "Object dependencies"), bodyMessage,
QMessageBox::Ok);
return false;
}
else {
return true;
}
}

bool ViewProviderWeld::canDelete(App::DocumentObject *obj) const
{
// deletions of Weld objects don't destroy anything
// thus we can pass this action
// that the parent LeaderLine cannot be deleted is handled
// in its onDelete() function
Q_UNUSED(obj)
return true;
}

TechDraw::DrawWeldSymbol* ViewProviderWeld::getViewObject() const
{
Expand Down
3 changes: 2 additions & 1 deletion src/Mod/TechDraw/Gui/ViewProviderWeld.h
Expand Up @@ -67,7 +67,8 @@ class TechDrawGuiExport ViewProviderWeld : public ViewProviderDrawingView
std::string prefFontName(void);
double prefFontSize(void);
double prefTileTextAdjust(void);

virtual bool onDelete(const std::vector<std::string> &);
virtual bool canDelete(App::DocumentObject* obj) const;

};

Expand Down

0 comments on commit f8d90c2

Please sign in to comment.