📄 appmgrmodel.cpp
字号:
#include "AppMgrModel.h"#include <QPoint>#include <QImage>#include <QStringList>#include <QSettings> #include <QApplication>#include <QFont>const int AppMgrModel::COL_NUM = 3;const QString AppMgrModel::iniFileName = "./data/app_data.ini";struct AppNode{ AppNode() : type(-1), name(NULL), value(NULL) {}; int type; QString name; QString value;};AppMgrModel::AppMgrModel(const QString& children, QObject* parent) : QAbstractTableModel(parent), mChildren(children){ loadChildNodes(); nodesCount = mNodeList.size(); qDebug("nodes count: %d", nodesCount);}AppMgrModel::~AppMgrModel(){ clearNodes();}QVariant AppMgrModel::data(const QModelIndex &index, int role) const{ int nodeIndex = index.row() * columnCount() + index.column(); if (nodeIndex >= nodesCount) return QVariant(); switch(role) { default: case Qt::DisplayRole: return mNodeList.at(nodeIndex)->name; case Qt::BackgroundColorRole: return Qt::yellow; case Qt::FontRole: if (qApp) { QFont f = qApp->font(); f.setPixelSize(12); f.setBold(true); return f; } break; case Qt::UserRole: return mNodeList.at(nodeIndex)->type; case Qt::UserRole + 1: return mNodeList.at(nodeIndex)->value; } return QVariant();}void AppMgrModel::loadChildNodes(){ QSettings cfg(iniFileName, QSettings::IniFormat); if (mChildren == TOP_FOLDER_FLAG) { mChildren = cfg.value("0/Value").toString(); } qDebug("chilren nodes: %s", mChildren.toLatin1().constData()); QStringList childrenIds = mChildren.split('*'); clearNodes(); int size = childrenIds.size(); for (int i=0; i < size; i++) { cfg.beginGroup(childrenIds.at(i)); qDebug("chilren node group: %s", childrenIds.at(i).toLatin1().constData()); AppNode* node = new AppNode(); node->type = cfg.value("Type").toInt(); node->name = cfg.value("Name").toString(); node->value = cfg.value("Value").toString(); mNodeList.append(node); qDebug("chilren node appended. Type=%d, Name=%s, Value=%s", node->type, node->name.toLatin1().constData(), node->value.toLatin1().constData()); cfg.endGroup(); } }void AppMgrModel::clearNodes(){ if (!mNodeList.isEmpty()) { int size = mNodeList.size(); for (int i=0; i < size; i++) { if (mNodeList.at(i) != NULL) delete mNodeList.at(i); } mNodeList.clear(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -