Add template based Document::countObjectsOfType

Also convert code to use this new method
This commit is contained in:
Benjamin Nauck
2025-01-11 20:00:24 +01:00
parent 74f3aee9a7
commit 08fe94ef25
14 changed files with 40 additions and 40 deletions

View File

@@ -31,7 +31,7 @@
namespace Part
{
class Mirroring : public Part::Feature
class PartExport Mirroring : public Part::Feature
{
PROPERTY_HEADER_WITH_OVERRIDE(Part::Mirroring);

View File

@@ -1153,8 +1153,7 @@ void CmdPartMakeSolid::activated(int iMsg)
bool CmdPartMakeSolid::isActive()
{
return Gui::Selection().countObjectsOfType
(App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink) > 0;
return Gui::Selection().countObjectsOfType<App::DocumentObject>(nullptr, Gui::ResolveMode::FollowLink) > 0;
}
//===========================================================================
@@ -1887,8 +1886,7 @@ void CmdPartThickness::activated(int iMsg)
bool CmdPartThickness::isActive()
{
Base::Type partid = Base::Type::fromName("Part::Feature");
bool objectsSelected = Gui::Selection().countObjectsOfType(partid, nullptr, Gui::ResolveMode::FollowLink) > 0;
bool objectsSelected = Gui::Selection().countObjectsOfType<Part::Feature>(nullptr, Gui::ResolveMode::FollowLink) > 0;
return (objectsSelected && !Gui::Control().activeDialog());
}
@@ -1918,7 +1916,7 @@ void CmdShapeInfo::activated(int iMsg)
bool CmdShapeInfo::isActive()
{
App::Document* doc = App::GetApplication().getActiveDocument();
if (!doc || doc->countObjectsOfType(Part::Feature::getClassTypeId()) == 0)
if (!doc || doc->countObjectsOfType<Part::Feature>() == 0)
return false;
Gui::MDIView* view = Gui::getMainWindow()->activeWindow();
@@ -2102,8 +2100,7 @@ void CmdColorPerFace::activated(int iMsg)
bool CmdColorPerFace::isActive()
{
Base::Type partid = Base::Type::fromName("Part::Feature");
bool objectSelected = Gui::Selection().countObjectsOfType(partid) == 1;
bool objectSelected = Gui::Selection().countObjectsOfType<Part::Feature>() == 1;
return (hasActiveDocument() && !Gui::Control().activeDialog() && objectSelected);
}

View File

@@ -64,6 +64,7 @@
#include <Mod/Part/App/PartFeature.h>
#include <Mod/Part/App/PrimitiveFeature.h>
#include <Mod/Part/App/DatumFeature.h>
#include <Mod/Part/App/FeatureMirroring.h>
#include <App/Datums.h>
#include "Mirroring.h"
@@ -289,7 +290,7 @@ bool Mirroring::accept()
}
Gui::WaitCursor wc;
unsigned int count = activeDoc->countObjectsOfType(Base::Type::fromName("Part::Mirroring"));
unsigned int count = activeDoc->countObjectsOfType<Part::Mirroring>();
activeDoc->openTransaction("Mirroring");
QString shape, label, selectionString;