Merge pull request #17528 from kadet1090/get-object-T-helpers

Gui: Add getObject<T>() helpers to various classes
This commit is contained in:
Chris Hennes
2024-12-06 19:51:11 -05:00
committed by GitHub
137 changed files with 557 additions and 633 deletions

View File

@@ -57,8 +57,7 @@ TaskWidgetPathCompound::TaskWidgetPathCompound(ViewProviderPathCompound* Compoun
this->groupLayout()->addWidget(proxy);
Path::FeatureCompound* pcCompound =
static_cast<Path::FeatureCompound*>(CompoundView->getObject());
Path::FeatureCompound* pcCompound = CompoundView->getObject<Path::FeatureCompound>();
const std::vector<App::DocumentObject*>& Paths = pcCompound->Group.getValues();
for (std::vector<App::DocumentObject*>::const_iterator it = Paths.begin(); it != Paths.end();
++it) {
@@ -128,8 +127,7 @@ void TaskDlgPathCompound::clicked(int button)
bool TaskDlgPathCompound::accept()
{
std::vector<App::DocumentObject*> paths;
Path::FeatureCompound* pcCompound =
static_cast<Path::FeatureCompound*>(CompoundView->getObject());
Path::FeatureCompound* pcCompound = CompoundView->getObject<Path::FeatureCompound>();
App::Document* pcDoc = static_cast<App::Document*>(pcCompound->getDocument());
std::vector<std::string> names = parameter->getList();
for (std::size_t i = 0; i < names.size(); i++) {

View File

@@ -42,8 +42,7 @@ ViewProviderArea::~ViewProviderArea()
std::vector<App::DocumentObject*> ViewProviderArea::claimChildren() const
{
return std::vector<App::DocumentObject*>(
static_cast<Path::FeatureArea*>(getObject())->Sources.getValues());
return std::vector<App::DocumentObject*>(getObject<Path::FeatureArea>()->Sources.getValues());
}
bool ViewProviderArea::canDragObjects() const
@@ -58,7 +57,7 @@ bool ViewProviderArea::canDragObject(App::DocumentObject* obj) const
void ViewProviderArea::dragObject(App::DocumentObject* obj)
{
Path::FeatureArea* area = static_cast<Path::FeatureArea*>(getObject());
Path::FeatureArea* area = getObject<Path::FeatureArea>();
std::vector<App::DocumentObject*> sources = area->Sources.getValues();
for (std::vector<App::DocumentObject*>::iterator it = sources.begin(); it != sources.end();
++it) {
@@ -82,7 +81,7 @@ bool ViewProviderArea::canDropObject(App::DocumentObject* obj) const
void ViewProviderArea::dropObject(App::DocumentObject* obj)
{
Path::FeatureArea* area = static_cast<Path::FeatureArea*>(getObject());
Path::FeatureArea* area = getObject<Path::FeatureArea>();
std::vector<App::DocumentObject*> sources = area->Sources.getValues();
sources.push_back(obj);
area->Sources.setValues(sources);
@@ -106,7 +105,7 @@ void ViewProviderArea::updateData(const App::Property* prop)
bool ViewProviderArea::onDelete(const std::vector<std::string>&)
{
// get the input shapes
Path::FeatureArea* area = static_cast<Path::FeatureArea*>(getObject());
Path::FeatureArea* area = getObject<Path::FeatureArea>();
std::vector<App::DocumentObject*> pShapes = area->Sources.getValues();
for (std::vector<App::DocumentObject*>::iterator it = pShapes.begin(); it != pShapes.end();
++it) {
@@ -132,7 +131,7 @@ ViewProviderAreaView::~ViewProviderAreaView()
std::vector<App::DocumentObject*> ViewProviderAreaView::claimChildren() const
{
std::vector<App::DocumentObject*> ret;
Path::FeatureAreaView* feature = static_cast<Path::FeatureAreaView*>(getObject());
Path::FeatureAreaView* feature = getObject<Path::FeatureAreaView>();
if (feature->Source.getValue()) {
ret.push_back(feature->Source.getValue());
}
@@ -151,7 +150,7 @@ bool ViewProviderAreaView::canDragObject(App::DocumentObject* obj) const
void ViewProviderAreaView::dragObject(App::DocumentObject*)
{
Path::FeatureAreaView* feature = static_cast<Path::FeatureAreaView*>(getObject());
Path::FeatureAreaView* feature = getObject<Path::FeatureAreaView>();
feature->Source.setValue(nullptr);
}
@@ -167,7 +166,7 @@ bool ViewProviderAreaView::canDropObject(App::DocumentObject* obj) const
void ViewProviderAreaView::dropObject(App::DocumentObject* obj)
{
Path::FeatureAreaView* feature = static_cast<Path::FeatureAreaView*>(getObject());
Path::FeatureAreaView* feature = getObject<Path::FeatureAreaView>();
feature->Source.setValue(obj);
}
@@ -182,7 +181,7 @@ void ViewProviderAreaView::updateData(const App::Property* prop)
bool ViewProviderAreaView::onDelete(const std::vector<std::string>&)
{
Path::FeatureAreaView* feature = static_cast<Path::FeatureAreaView*>(getObject());
Path::FeatureAreaView* feature = getObject<Path::FeatureAreaView>();
Gui::Application::Instance->showViewProvider(feature->Source.getValue());
return true;
}

View File

@@ -51,8 +51,7 @@ void ViewProviderPathCompound::unsetEdit(int ModNum)
std::vector<App::DocumentObject*> ViewProviderPathCompound::claimChildren() const
{
return std::vector<App::DocumentObject*>(
static_cast<Path::FeatureCompound*>(getObject())->Group.getValues());
return std::vector<App::DocumentObject*>(getObject<Path::FeatureCompound>()->Group.getValues());
}
bool ViewProviderPathCompound::canDragObjects() const
@@ -62,7 +61,7 @@ bool ViewProviderPathCompound::canDragObjects() const
void ViewProviderPathCompound::dragObject(App::DocumentObject* obj)
{
static_cast<Path::FeatureCompound*>(getObject())->removeObject(obj);
getObject<Path::FeatureCompound>()->removeObject(obj);
}
bool ViewProviderPathCompound::canDropObjects() const
@@ -72,7 +71,7 @@ bool ViewProviderPathCompound::canDropObjects() const
void ViewProviderPathCompound::dropObject(App::DocumentObject* obj)
{
static_cast<Path::FeatureCompound*>(getObject())->addObject(obj);
getObject<Path::FeatureCompound>()->addObject(obj);
}
QIcon ViewProviderPathCompound::getIcon() const

View File

@@ -41,8 +41,7 @@ QIcon ViewProviderPathShape::getIcon() const
std::vector<App::DocumentObject*> ViewProviderPathShape::claimChildren() const
{
return std::vector<App::DocumentObject*>(
static_cast<Path::FeatureShape*>(getObject())->Sources.getValues());
return std::vector<App::DocumentObject*>(getObject<Path::FeatureShape>()->Sources.getValues());
}
bool ViewProviderPathShape::canDragObjects() const
@@ -57,7 +56,7 @@ bool ViewProviderPathShape::canDragObject(App::DocumentObject* obj) const
void ViewProviderPathShape::dragObject(App::DocumentObject* obj)
{
Path::FeatureShape* feature = static_cast<Path::FeatureShape*>(getObject());
Path::FeatureShape* feature = getObject<Path::FeatureShape>();
std::vector<App::DocumentObject*> sources = feature->Sources.getValues();
for (std::vector<App::DocumentObject*>::iterator it = sources.begin(); it != sources.end();
++it) {
@@ -81,7 +80,7 @@ bool ViewProviderPathShape::canDropObject(App::DocumentObject* obj) const
void ViewProviderPathShape::dropObject(App::DocumentObject* obj)
{
Path::FeatureShape* feature = static_cast<Path::FeatureShape*>(getObject());
Path::FeatureShape* feature = getObject<Path::FeatureShape>();
std::vector<App::DocumentObject*> sources = feature->Sources.getValues();
sources.push_back(obj);
feature->Sources.setValues(sources);
@@ -105,7 +104,7 @@ void ViewProviderPathShape::updateData(const App::Property* prop)
bool ViewProviderPathShape::onDelete(const std::vector<std::string>&)
{
// get the input shapes
Path::FeatureShape* feature = static_cast<Path::FeatureShape*>(getObject());
Path::FeatureShape* feature = getObject<Path::FeatureShape>();
std::vector<App::DocumentObject*> pShapes = feature->Sources.getValues();
for (std::vector<App::DocumentObject*>::iterator it = pShapes.begin(); it != pShapes.end();
++it) {