git-svn-id: svn://db.shs.com.ru/libs@383 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -20,6 +20,7 @@ CDItem::CDItem(CDUtils::Interface * i, int _index, CDItem::CDItemType type, CDIt
|
||||
index_ = _index;
|
||||
parent_ = parent;
|
||||
type_ = type;
|
||||
item_count = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -387,12 +388,13 @@ void CDItemModel::rebuildModel() {
|
||||
}
|
||||
|
||||
|
||||
void CDItemModel::buildItem(CDItem *it, CDSection & r) {
|
||||
void CDItemModel::buildItem(CDItem * it, CDSection & r) {
|
||||
//piCout << "build item" << r.name << r.alias;
|
||||
PIMap<int, CDType>::iterator i;
|
||||
for (i = r.cd.begin(); i != r.cd.end(); ++i) {
|
||||
it->childs << new CDItem(interface, i.key(), CDItem::ItemCDType, it);
|
||||
}
|
||||
it->item_count = it->childs.size();
|
||||
PIMap<int, CDSection>::iterator j;
|
||||
for (j = r.s.begin(); j != r.s.end(); ++j) {
|
||||
it->childs << new CDItem(interface, j.key(), CDItem::ItemCDSection, it);
|
||||
@@ -423,3 +425,32 @@ CDItem * CDItemModel::getItem(const QModelIndex &index) const {
|
||||
}
|
||||
return root;
|
||||
}
|
||||
|
||||
|
||||
QModelIndex CDItemModel::indexByPath(const PIDeque<int> & path, int column) const {
|
||||
if (path.isEmpty()) return QModelIndex();
|
||||
CDItem * item = root;
|
||||
//piCout << path << "...";
|
||||
bool ok = false;
|
||||
for (int i = 0; i < path.size_s() - 1; ++i) {
|
||||
ok = false;
|
||||
foreach (CDItem * j, item->childs)
|
||||
if (j->type_ == CDItem::ItemCDSection && j->index_ == path[i]) {
|
||||
item = j;
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
if (!ok) return QModelIndex();
|
||||
}
|
||||
ok = false;
|
||||
foreach (CDItem * j, item->childs)
|
||||
if (j->type_ == CDItem::ItemCDType && j->index_ == path.back()) {
|
||||
item = j;
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
if (!ok || !item->parent_) return QModelIndex();
|
||||
QModelIndex ret = createIndex(item->parent_->childs.indexOf(item), column, item);
|
||||
//piCout << path << Q2PIString(item->data(cName_Cmd, Qt::DisplayRole).toString()) << getItem(ret)->buildPath();
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user