Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit cb660c8

Browse files
committed
Fix state order
1 parent 7353f34 commit cb660c8

File tree

4 files changed

+39
-21
lines changed

4 files changed

+39
-21
lines changed

src/rameditwidgets/stepeditwidget.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,29 @@ void StepEditWidget::reInit(RamObject *obj)
6767

6868
RamStep::Type stepType = m_step->type();
6969
if (stepType == RamStep::AssetProduction || stepType == RamStep::ShotProduction) {
70-
QHash<RamState*, int> states = m_step->stateCount();
70+
const QVector<RamStep::StateCount> stateCount = m_step->stateCount();
7171
RamState *noState = Ramses::instance()->noState();
72-
DBTableModel *allStates = Ramses::instance()->states();
7372
int total = 0;
74-
for (int i = 0; i < allStates->count(); i++) {
75-
auto s = qobject_cast<RamState*>( allStates->get(i) );
76-
if (s->is(noState))
73+
74+
for(const auto count: stateCount) {
75+
int c = count.count;
76+
if (c == 0)
77+
continue;
78+
79+
RamState *state = count.state;
80+
if (state->is(noState))
7781
continue;
78-
int c = states.value( s, 0 );
79-
if (c > 0) {
80-
QString cStr = "<b>"+QString::number(c)+"</b> ";
81-
if (stepType == RamStep::AssetProduction) cStr += "assets";
82-
else cStr += "shots";
83-
84-
auto l = new QLabel(s->name(), this);
85-
l->setStyleSheet("QLabel { color: "+s->color().name() + "; }");
86-
ui_statesLayout->addRow( l, new QLabel(cStr, this) );
87-
total += c;
88-
}
82+
83+
QString cStr = "<b>"+QString::number(c)+"</b> ";
84+
if (stepType == RamStep::AssetProduction) cStr += "assets";
85+
else cStr += "shots";
86+
87+
auto l = new QLabel(state->name(), this);
88+
l->setStyleSheet("QLabel { color: "+state->color().name() + "; }");
89+
ui_statesLayout->addRow( l, new QLabel(cStr, this) );
90+
total += c;
8991
}
92+
9093
if (total > 0) {
9194
QString cStr = "<b>"+QString::number(total)+"</b> ";
9295
if (stepType == RamStep::AssetProduction) cStr += "assets";

src/rameditwidgets/stepeditwidget.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ private slots:
6868
DuQFColorSelector *ui_colorSelector;
6969

7070
ObjectListWidget *m_applicationList;
71-
7271
};
7372

7473
#endif // STEPEDITWIDGET_H

src/ramobjects/ramstep.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,13 @@ float RamStep::neededDays()
179179
return estimation() - daysSpent();
180180
}
181181

182-
QHash<RamState *, int> RamStep::stateCount()
182+
QVector<RamStep::StateCount> RamStep::stateCount()
183183
{
184184
QHash<RamState *, int> states;
185+
QVector<RamStep::StateCount> count;
185186

186187
RamProject *proj = project();
187-
if (!proj) return states;
188+
if (!proj) return count;
188189

189190
const QSet<RamStatus*> status = proj->stepStatus(this);
190191
for(auto st: status) {
@@ -193,7 +194,16 @@ QHash<RamState *, int> RamStep::stateCount()
193194
states.insert(s, c+1);
194195
}
195196

196-
return states;
197+
QHashIterator<RamState*,int> i(states);
198+
while(i.hasNext()) {
199+
i.next();
200+
count.append({ i.key(), i.value()} );
201+
}
202+
std::sort(count.begin(), count.end(), [] (const StateCount &a, const StateCount &b) {
203+
return a.state->completionRatio() < b.state->completionRatio();
204+
});
205+
206+
return count;
197207
}
198208

199209
QVector<float> RamStep::stats(RamUser *user)

src/ramobjects/ramstep.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ class RamStep : public RamTemplateStep
1818
{
1919
Q_OBJECT
2020
public:
21+
22+
struct StateCount {
23+
RamState *state;
24+
int count;
25+
};
26+
2127
static RamStep *get(QString uuid, bool includeRemoved = false);
2228
static RamStep *c(RamObject *o);
2329
static RamStep *createFromTemplate(RamTemplateStep *tempStep, RamProject *project);
@@ -41,7 +47,7 @@ class RamStep : public RamTemplateStep
4147
float daysSpent() ;
4248
float neededDays() ;
4349

44-
QHash<RamState*, int> stateCount();
50+
QVector<StateCount> stateCount();
4551

4652
/**
4753
* @brief stats

0 commit comments

Comments
 (0)