Qt Editor: Sort objects in object creator by name

qteditor
Sven Eberhardt 2016-03-19 14:39:58 -04:00
parent ed0647866e
commit 3f7d68ff2c
2 changed files with 12 additions and 0 deletions

View File

@ -27,6 +27,15 @@
/* Defintion tree */
void C4ConsoleQtDefinitionListModel::DefListNode::SortByName()
{
// sort self
std::sort(items.begin(), items.end(),
[](const std::unique_ptr<DefListNode> & a, const std::unique_ptr<DefListNode> & b) -> bool
{ return a->name.Compare(b->name) < 0; });
// sort children recursively
for (auto & child : items) child->SortByName();
}
/* Defintion view model */
@ -100,6 +109,8 @@ void C4ConsoleQtDefinitionListModel::ReInit()
std::unique_ptr<DefListNode> tmp(new_root->items[0].release());
root.reset(tmp.release());
}
// Sort everything by display name (recursively)
root->SortByName();
// Model reset to invalidate all indexes
beginResetModel();
endResetModel();

View File

@ -44,6 +44,7 @@ class C4ConsoleQtDefinitionListModel : public QAbstractItemModel
DefListNode *parent;
DefListNode() : def(NULL), idx(0), parent(NULL) {}
void SortByName(); // sort self and children
};
std::unique_ptr<DefListNode> root;