Gui: fix computing status value and use enum to avoid magic numbers

This commit is contained in:
wmayer
2024-03-30 17:45:23 +01:00
committed by wwmayer
parent e422084e92
commit 7cbb28ca53

View File

@@ -5127,6 +5127,17 @@ void DocumentObjectItem::testStatus(bool resetStatus)
testStatus(resetStatus, icon, icon2);
}
namespace {
enum Status {
Visible = 1 << 0,
Recompute = 1 << 1,
Error = 1 << 2,
Hidden = 1 << 3,
External = 1 << 4,
Freezed = 1 << 5
};
}
void DocumentObjectItem::testStatus(bool resetStatus, QIcon& icon1, QIcon& icon2)
{
App::DocumentObject* pObject = object()->getObject();
@@ -5166,8 +5177,8 @@ void DocumentObjectItem::testStatus(bool resetStatus, QIcon& icon1, QIcon& icon2
bool freezed = pObject->isFreezed();
int currentStatus =
((freezed ? 0 : 1) << 5) |
((external ? 0 : 1) << 4) |
((freezed ? 1 : 0) << 5) |
((external ? 1 : 0) << 4) |
((object()->showInTree() ? 0 : 1) << 3) |
((pObject->isError() ? 1 : 0) << 2) |
((pObject->isTouched() || pObject->mustExecute() == 1 ? 1 : 0) << 1) |
@@ -5183,7 +5194,7 @@ void DocumentObjectItem::testStatus(bool resetStatus, QIcon& icon1, QIcon& icon2
previousStatus = currentStatus;
QIcon::Mode mode = QIcon::Normal;
if (isVisibilityIconEnabled() || (currentStatus & 1)) { // visible
if (isVisibilityIconEnabled() || (currentStatus & Status::Visible)) {
// Note: By default the foreground, i.e. text color is invalid
// to make use of the default color of the tree widget's palette.
// If we temporarily set this color to dark and reset to an invalid
@@ -5210,7 +5221,7 @@ void DocumentObjectItem::testStatus(bool resetStatus, QIcon& icon1, QIcon& icon2
if (icon.isNull()) {
Timing(getIcon);
QPixmap px;
if (currentStatus & 4) {
if (currentStatus & Status::Error) {
static QPixmap pxError;
if (pxError.isNull()) {
// object is in error state
@@ -5218,7 +5229,7 @@ void DocumentObjectItem::testStatus(bool resetStatus, QIcon& icon1, QIcon& icon2
}
px = pxError;
}
else if (currentStatus & 2) {
else if (currentStatus & Status::Recompute) {
static QPixmap pxRecompute;
if (pxRecompute.isNull()) {
// object must be recomputed
@@ -5252,7 +5263,7 @@ void DocumentObjectItem::testStatus(bool resetStatus, QIcon& icon1, QIcon& icon2
pxOn = icon_org.pixmap(w, w, mode, QIcon::On);
}
if (currentStatus & 8) {// hidden item
if (currentStatus & Status::Hidden) {
static QPixmap pxHidden;
if (pxHidden.isNull()) {
pxHidden = Gui::BitmapFactory().pixmapFromSvg("TreeItemVisible", QSize(10, 10));
@@ -5261,7 +5272,7 @@ void DocumentObjectItem::testStatus(bool resetStatus, QIcon& icon1, QIcon& icon2
pxOn = BitmapFactory().merge(pxOn, pxHidden, BitmapFactoryInst::TopLeft);
}
if (external) {// external item
if (currentStatus & Status::External) {
static QPixmap pxExternal;
if (pxExternal.isNull()) {
pxExternal = Gui::BitmapFactory().pixmapFromSvg("LinkOverlay",
@@ -5271,7 +5282,7 @@ void DocumentObjectItem::testStatus(bool resetStatus, QIcon& icon1, QIcon& icon2
pxOn = BitmapFactory().merge(pxOn, pxExternal, BitmapFactoryInst::BottomRight);
}
if (freezed) {
if (currentStatus & Status::Freezed) {
static QPixmap pxFreeze;
if (pxFreeze.isNull()) {
// object is in freezed state
@@ -5306,7 +5317,7 @@ void DocumentObjectItem::testStatus(bool resetStatus, QIcon& icon1, QIcon& icon2
QPainter pt;
pt.begin(&px);
pt.setPen(Qt::NoPen);
pt.drawPixmap(0, 0, px_org.width(), px_org.height(), (currentStatus & 1) ? pxVisible : pxInvisible);
pt.drawPixmap(0, 0, px_org.width(), px_org.height(), (currentStatus & Status::Visible) ? pxVisible : pxInvisible);
pt.drawPixmap(px_org.width(), 0, px_org.width(), px_org.height(), px_org);
pt.end();