Assembly: Improve const correctness

This commit is contained in:
wmayer
2025-04-27 15:39:07 +02:00
committed by Max Wilfinger
parent 0302b3de5f
commit 377614aeef
4 changed files with 26 additions and 16 deletions

View File

@@ -24,7 +24,6 @@
#include <cmath>
#include <vector>
#include <App/Application.h>
#include <App/Document.h>
#include <App/DocumentObjectGroup.h>
@@ -43,7 +42,6 @@
#include <Mod/PartDesign/App/Body.h>
#include <Mod/Spreadsheet/App/Cell.h>
#include "AssemblyObject.h"
#include "AssemblyLink.h"
#include "BomObject.h"
@@ -291,19 +289,19 @@ std::string BomObject::getBomPropertyValue(App::DocumentObject* obj, const std::
if (auto propStr = freecad_cast<App::PropertyString*>(prop)) {
return propStr->getValue();
}
else if (auto propQuantity = freecad_cast<App::PropertyQuantity*>(prop)) {
if (auto propQuantity = freecad_cast<App::PropertyQuantity*>(prop)) {
return propQuantity->getQuantityValue().getUserString();
}
else if (auto propEnum = freecad_cast<App::PropertyEnumeration*>(prop)) {
if (auto propEnum = freecad_cast<App::PropertyEnumeration*>(prop)) {
return propEnum->getValueAsString();
}
else if (auto propFloat = freecad_cast<App::PropertyFloat*>(prop)) {
if (auto propFloat = freecad_cast<App::PropertyFloat*>(prop)) {
return std::to_string(propFloat->getValue());
}
else if (auto propInt = freecad_cast<App::PropertyInteger*>(prop)) {
if (auto propInt = freecad_cast<App::PropertyInteger*>(prop)) {
return std::to_string(propInt->getValue());
}
else if (auto propBool = freecad_cast<App::PropertyBool*>(prop)) {
if (auto propBool = freecad_cast<App::PropertyBool*>(prop)) {
return propBool->getValue() ? "True" : "False";
}
@@ -311,7 +309,7 @@ std::string BomObject::getBomPropertyValue(App::DocumentObject* obj, const std::
return QObject::tr("Not supported").toStdString();
}
AssemblyObject* BomObject::getAssembly()
AssemblyObject* BomObject::getAssembly() const
{
for (auto& obj : getInList()) {
if (obj->isDerivedFrom<AssemblyObject>()) {
@@ -321,7 +319,7 @@ AssemblyObject* BomObject::getAssembly()
return nullptr;
}
bool BomObject::hasQuantityColumn()
bool BomObject::hasQuantityColumn() const
{
for (auto& columnName : columnsNames.getValues()) {
if (columnName == "Quantity") {
@@ -331,9 +329,9 @@ bool BomObject::hasQuantityColumn()
return false;
}
std::string Assembly::BomObject::getText(size_t row, size_t col)
std::string Assembly::BomObject::getText(size_t row, size_t col) const
{
Spreadsheet::Cell* cell = getCell(App::CellAddress(row, col));
const Spreadsheet::Cell* cell = getCell(App::CellAddress(row, col));
std::string cellName;
if (cell) {
cell->getStringContent(cellName);
@@ -347,7 +345,7 @@ std::string Assembly::BomObject::getText(size_t row, size_t col)
return cellName;
}
int BomObject::getColumnIndex(std::string name)
int BomObject::getColumnIndex(std::string name) const
{
int col = 0;
for (auto& columnName : columnsNames.getValues()) {

View File

@@ -80,11 +80,11 @@ public:
void addObjectChildrenToBom(std::vector<App::DocumentObject*> objs, size_t& row, std::string index);
void saveCustomColumnData();
AssemblyObject* getAssembly();
AssemblyObject* getAssembly() const;
bool hasQuantityColumn();
int getColumnIndex(std::string name);
std::string getText(size_t row, size_t col);
bool hasQuantityColumn() const;
int getColumnIndex(std::string name) const;
std::string getText(size_t row, size_t col) const;
App::PropertyStringList columnsNames;
App::PropertyBool detailSubAssemblies;

View File

@@ -411,6 +411,17 @@ Cell* Sheet::getCell(CellAddress address)
return cells.getValue(address);
}
/**
* Get contents of the cell specified by \a address, or 0 if it is not defined
*
* @returns A CellContent object or 0.
*/
const Cell* Sheet::getCell(CellAddress address) const
{
return cells.getValue(address);
}
/**
* Get cell contents specified by \a address.
*

View File

@@ -110,6 +110,7 @@ public:
void splitCell(App::CellAddress address);
Cell* getCell(App::CellAddress address);
const Cell* getCell(App::CellAddress address) const;
Cell* getNewCell(App::CellAddress address);