Merge pull request #19019 from hyarion/refactor/countObjectsOfType

Refactor countObjectsOfType in selection and document
This commit is contained in:
Chris Hennes
2025-01-14 16:05:12 -06:00
committed by GitHub
31 changed files with 194 additions and 222 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

@@ -344,8 +344,7 @@ void CmdPartCut::activated(int iMsg)
bool CmdPartCut::isActive()
{
return getSelection().countObjectsOfType(
App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink)==2;
return getSelection().countObjectsOfType<App::DocumentObject>(nullptr, Gui::ResolveMode::FollowLink) == 2;
}
//===========================================================================
@@ -404,8 +403,7 @@ void CmdPartCommon::activated(int iMsg)
bool CmdPartCommon::isActive()
{
return getSelection().countObjectsOfType(
App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink) >= 1;
return getSelection().countObjectsOfType<App::DocumentObject>(nullptr, Gui::ResolveMode::FollowLink) >= 1;
}
//===========================================================================
@@ -483,8 +481,7 @@ void CmdPartFuse::activated(int iMsg)
bool CmdPartFuse::isActive()
{
return getSelection().countObjectsOfType(
App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink) >= 1;
return getSelection().countObjectsOfType<App::DocumentObject>(nullptr, Gui::ResolveMode::FollowLink) >= 1;
}
//===========================================================================
@@ -839,8 +836,7 @@ CmdPartCompound::CmdPartCompound()
void CmdPartCompound::activated(int iMsg)
{
Q_UNUSED(iMsg);
unsigned int n = getSelection().countObjectsOfType(
App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink);
unsigned int n = getSelection().countObjectsOfType<App::DocumentObject>(nullptr, Gui::ResolveMode::FollowLink);
if (n < 1) {
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
QObject::tr("Select one shape or more, please."));
@@ -872,8 +868,7 @@ void CmdPartCompound::activated(int iMsg)
bool CmdPartCompound::isActive()
{
return getSelection().countObjectsOfType(
App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink) >= 1;
return getSelection().countObjectsOfType<App::DocumentObject>(nullptr, Gui::ResolveMode::FollowLink) >= 1;
}
//===========================================================================
@@ -921,7 +916,7 @@ void CmdPartSection::activated(int iMsg)
bool CmdPartSection::isActive()
{
return getSelection().countObjectsOfType(App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink) == 2;
return getSelection().countObjectsOfType<App::DocumentObject>(nullptr, Gui::ResolveMode::FollowLink) == 2;
}
//===========================================================================
@@ -1032,7 +1027,7 @@ void CmdPartExport::activated(int iMsg)
bool CmdPartExport::isActive()
{
return Gui::Selection().countObjectsOfType(App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink) > 0;
return Gui::Selection().countObjectsOfType<App::DocumentObject>(nullptr, Gui::ResolveMode::FollowLink) > 0;
}
//===========================================================================
@@ -1158,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;
}
//===========================================================================
@@ -1360,7 +1354,7 @@ void CmdPartMakeFace::activated(int iMsg)
bool CmdPartMakeFace::isActive()
{
return (Gui::Selection().countObjectsOfType(App::DocumentObject::getClassTypeId(), nullptr, Gui::ResolveMode::FollowLink) > 0 &&
return (Gui::Selection().countObjectsOfType<App::DocumentObject>(nullptr, Gui::ResolveMode::FollowLink) > 0 &&
!Gui::Control().activeDialog());
}
@@ -1892,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());
}
@@ -1923,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();
@@ -2107,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

@@ -119,8 +119,7 @@ void CmdPartShapeFromMesh::activated(int iMsg)
bool CmdPartShapeFromMesh::isActive()
{
Base::Type meshid = Base::Type::fromName("Mesh::Feature");
return Gui::Selection().countObjectsOfType(meshid) > 0;
return Gui::Selection().countObjectsOfType("Mesh::Feature") > 0;
}
//===========================================================================
// Part_PointsFromMesh
@@ -205,8 +204,7 @@ void CmdPartPointsFromMesh::activated(int iMsg)
bool CmdPartPointsFromMesh::isActive()
{
Base::Type meshid = Base::Type::fromName("App::GeoFeature");
return Gui::Selection().countObjectsOfType(meshid) > 0;
return Gui::Selection().countObjectsOfType<App::GeoFeature>() > 0;
}
//===========================================================================

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;