git-svn-id: svn://db.shs.com.ru/libs@116 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
#include "cdutils_k.h"
|
||||
#include "piqt.h"
|
||||
#include <QDebug>
|
||||
#include <QBrush>
|
||||
#include <QColor>
|
||||
|
||||
using namespace CDUtils;
|
||||
|
||||
@@ -19,9 +21,8 @@ CDKItemModel::~CDKItemModel() {
|
||||
|
||||
QVariant CDKItemModel::data(const QModelIndex &index, int role) const {
|
||||
if (!index.isValid()) return QVariant();
|
||||
if (role != Qt::DisplayRole && role != Qt::EditRole) return QVariant();
|
||||
CDKItem *item = getItem(index);
|
||||
return item->data(index.column());
|
||||
return item->data(index.column(), role);
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +95,7 @@ void CDKItemModel::rebuildModel() {
|
||||
}
|
||||
|
||||
|
||||
void CDKItemModel::buildItem(CDKItem *it, CDSection r) {
|
||||
void CDKItemModel::buildItem(CDKItem *it, CDSection & r) {
|
||||
//piCout << "build item" << r.name << r.alias;
|
||||
PIMap<int, CDType>::iterator i;
|
||||
for (i = r.k.begin(); i != r.k.end(); ++i) {
|
||||
@@ -112,7 +113,7 @@ void CDKItemModel::internalRebuild() {
|
||||
qDebug() << "[CDKItemModel]" << "internalRebuild()";
|
||||
if (root) delete root;
|
||||
root = new CDKItem(0, CDKItem::ItemCDSection, 0);
|
||||
CDSection r = K.root();
|
||||
CDSection & r = K.root();
|
||||
buildItem(root, r);
|
||||
}
|
||||
|
||||
@@ -138,15 +139,23 @@ CDKItem::~CDKItem() {
|
||||
}
|
||||
|
||||
|
||||
QVariant CDKItem::data(int column) const {
|
||||
CDSection rs = K.section(buildPath());
|
||||
//piCout << rs.name << rs.alias << rs.count(false) << rs.sectionsCount() << K.root().name << K.root().alias <<K.root().count(false) << K.root().sectionsCount();
|
||||
QVariant CDKItem::data(int column, int role) const {
|
||||
if (role == Qt::BackgroundRole) {
|
||||
switch (type_) {
|
||||
case ItemCDType: return QBrush(QColor(255, 250, 230));
|
||||
case ItemCDSection: return QBrush(QColor(220, 220, 250));
|
||||
}
|
||||
}
|
||||
if (role != Qt::DisplayRole && role != Qt::EditRole) return QVariant();
|
||||
PIDeque<int> path = buildPath();
|
||||
CDSection & rs = K.section(path);
|
||||
CDSection s;
|
||||
switch (type_) {
|
||||
case ItemCDType:
|
||||
switch (column) {
|
||||
case 0: return QString::number(index_);
|
||||
case 1: return PI2QString(rs[index_].name());
|
||||
case 2: return PI2QString(rs[index_].type());
|
||||
case 2: return stringType(rs[index_].type());
|
||||
case 3: return PI2QString(rs[index_].formula());
|
||||
case 4: return PI2QString(rs[index_].value());
|
||||
case 5: return PI2QString(rs[index_].comment());
|
||||
@@ -155,11 +164,12 @@ QVariant CDKItem::data(int column) const {
|
||||
}
|
||||
break;
|
||||
case ItemCDSection:
|
||||
rs = rs.section(index_);
|
||||
s = rs.section(index_);
|
||||
// piCout << rs.name << rs.alias << s.name << s.alias;
|
||||
switch (column) {
|
||||
case 0: return QString("[") + QString::number(index_) + QString("]");
|
||||
case 1: return PI2QString(rs.alias);
|
||||
case 2: return PI2QString(rs.name);
|
||||
case 1: return PI2QString(s.alias);
|
||||
case 2: return PI2QString(s.name);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -171,7 +181,7 @@ QVariant CDKItem::data(int column) const {
|
||||
|
||||
bool CDKItem::setData(int column, const QVariant &value) {
|
||||
if (column == 3 && type_ == ItemCDType) {
|
||||
//K.section(buildPath())[index_].formula_ = Q2PIString(value.toString());
|
||||
K.section(buildPath())[index_].setFormula(Q2PIString(value.toString()));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -186,7 +196,28 @@ PIDeque<int> CDKItem::buildPath() const {
|
||||
p = p->parent_;
|
||||
}
|
||||
path.take_front();
|
||||
//piCout << path;
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
QString CDKItem::stringType(const PIString & t) const {
|
||||
QString n = PI2QString(t);
|
||||
if (n.isEmpty()) return QString("");
|
||||
switch (n[0].toLatin1()) {
|
||||
case 'l': return QString("list"); break;
|
||||
case 'b': return QString("bool"); break;
|
||||
case 'n': return QString("int"); break;
|
||||
case 'f': return QString("double"); break;
|
||||
case 'c': return QString("color"); break;
|
||||
case 'r': return QString("rect"); break;
|
||||
case 'a': return QString("rect"); break;
|
||||
case 'p': return QString("point"); break;
|
||||
case 'v': return QString("vector"); break;
|
||||
case 'i': return QString("IP"); break;
|
||||
case 'e': return QString("enum"); break;
|
||||
case 'F': return QString("file"); break;
|
||||
case 'D': return QString("dir"); break;
|
||||
}
|
||||
return QString("double");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user