30 void C4ConsoleQtDefinitionListModel::DefListNode::SortByName()
 
   33     std::sort(items.begin(), items.end(),
 
   34         [](
const std::unique_ptr<DefListNode> & 
a, 
const std::unique_ptr<DefListNode> & 
b) -> 
bool 
   35         { return a->name.Compare(b->name) < 0; });
 
   38     for (
auto & child : items)
 
   47 C4ConsoleQtDefinitionListModel::C4ConsoleQtDefinitionListModel()
 
   53 C4ConsoleQtDefinitionListModel::~C4ConsoleQtDefinitionListModel() = 
default;
 
   55 void C4ConsoleQtDefinitionListModel::EnsureInit()
 
   58     if (!root.get() || root->items.empty())
 
   63 void C4ConsoleQtDefinitionListModel::ReInit()
 
   67     root = std::make_unique<C4ConsoleQtDefinitionListModel::DefListNode>();
 
   68     int32_t index = 0; 
C4Def *def;
 
   74         DefListNode *node_parent = root.get();
 
   90                 DefListNode *node_child = 
nullptr;
 
   91                 for (
auto &test_node_child : node_parent->items)
 
   92                     if (test_node_child->filename == fn)
 
   94                         node_child = &*test_node_child;
 
  100                     node_parent->items.emplace_back((node_child = 
new DefListNode()));
 
  101                     node_child->idx = node_parent->items.size() - 1;
 
  102                     node_child->parent = node_parent;
 
  104                     node_child->name.Copy(localized_name ? localized_name : fn.getData());
 
  105                     node_child->filename.Copy(fn);
 
  108                 if (!is_parent_folder)
 
  110                     node_child->def = def;
 
  111                     const char *def_name = def->
GetName();
 
  112                     if (def_name && *def_name) node_child->name.Copy(def_name);
 
  118                     node_parent = node_child;
 
  125     DefListNode *new_root = root.get();
 
  126     while (new_root->items.size() == 1 && !new_root->items[0]->def)
 
  128         std::unique_ptr<DefListNode> tmp(new_root->items[0].release());
 
  129         root.reset(tmp.release());
 
  130         new_root = root.get();
 
  132     root->parent = 
nullptr;
 
  134     QStringList group_names;
 
  135     DefListNode *node = root.get();
 
  140             node->def->ConsoleGroupPath.Copy(group_names.join(
'/').toUtf8());
 
  143         if (!node->items.empty())
 
  145             if (node != root.get()) group_names.append(node->name.getData());
 
  146             node = node->items[0].get();
 
  150             int32_t idx = node->idx + 1;
 
  151             while ((node = node->parent))
 
  153                 if (node->items.size() > idx)
 
  155                     node = node->items[idx].get();
 
  158                 if (group_names.size()) group_names.pop_back();
 
  170 void C4ConsoleQtDefinitionListModel::OnItemRemoved(
C4Def *p)
 
  172     for (
auto idx : this->persistentIndexList())
 
  173         if (idx.internalPointer() == p)
 
  174             this->changePersistentIndex(idx, QModelIndex());
 
  178 class C4Def *C4ConsoleQtDefinitionListModel::GetDefByModelIndex(
const QModelIndex &idx)
 
  180     DefListNode *node = 
static_cast<DefListNode *
>(idx.internalPointer());
 
  181     if (node) 
return node->def; 
else return nullptr;
 
  184 const char *C4ConsoleQtDefinitionListModel::GetNameByModelIndex(
const QModelIndex &idx)
 
  186     DefListNode *node = 
static_cast<DefListNode *
>(idx.internalPointer());
 
  187     if (node) 
return node->name.getData(); 
else return nullptr;
 
  190 int C4ConsoleQtDefinitionListModel::rowCount(
const QModelIndex & parent)
 const 
  193     DefListNode *parent_node = parent.isValid() ? 
static_cast<DefListNode *
>(parent.internalPointer()) : 
nullptr;
 
  194     if (!parent_node) parent_node = root.get();
 
  195     if (parent_node) result = parent_node->items.size();
 
  199 int C4ConsoleQtDefinitionListModel::columnCount(
const QModelIndex & parent)
 const 
  204 QVariant C4ConsoleQtDefinitionListModel::data(
const QModelIndex & index, 
int role)
 const 
  207     DefListNode *node = 
static_cast<DefListNode *
>(index.internalPointer());
 
  208     if (!node) 
return QVariant();
 
  209     if (role == Qt::DisplayRole)
 
  211         return QString(node->name.getData());
 
  217 QModelIndex C4ConsoleQtDefinitionListModel::index(
int row, 
int column, 
const QModelIndex &parent)
 const 
  220     if (row < 0 || column != 0) 
return QModelIndex();
 
  221     DefListNode *parent_node = parent.isValid() ? 
static_cast<DefListNode *
>(parent.internalPointer()) : 
nullptr;
 
  222     if (!parent_node) parent_node = root.get();
 
  223     if (parent_node->items.size() <= row) 
return QModelIndex();
 
  225     DefListNode *node = parent_node->items[row].get();
 
  226     return createIndex(row, column, node);
 
  229 QModelIndex C4ConsoleQtDefinitionListModel::parent(
const QModelIndex &index)
 const 
  232     DefListNode *node = 
static_cast<DefListNode *
>(index.internalPointer());
 
  233     if (!node) 
return QModelIndex();
 
  234     DefListNode *parent_node = node->parent;
 
  235     if (!parent_node || parent_node == root.get()) 
return QModelIndex();
 
  236     return createIndex(parent_node->idx, index.column(), parent_node);
 
  239 QModelIndex C4ConsoleQtDefinitionListModel::GetModelIndexByItem(
C4Def *def)
 const 
  242     DefListNode *node = root.get();
 
  245         if (node->def == def) 
break;
 
  246         if (!node->items.empty())
 
  247             node = node->items[0].get();
 
  250             int32_t idx = node->idx + 1;
 
  251             while ((node = node->parent))
 
  253                 if (node->items.size() > idx)
 
  255                     node = node->items[idx].get();
 
  265         return createIndex(node->idx, 0, node);
 
  269         return QModelIndex();
 
bool WildcardMatch(const char *szWildcard, const char *szString)
 
void RemoveExtension(char *szFilename)
 
char Filename[_MAX_FNAME_LEN]
 
const char * GetLocalizedGroupFolderName(const char *folder_path) const
 
C4Def * GetDef(int32_t Index)
 
const char * GetName() const override
 
const char * getData() const
 
void AppendChar(char cChar)
 
void Append(const char *pnData, size_t iChars)
 
int ReplaceChar(char cOld, char cNew)