Преглед на файлове

Book header: show root <description> node

Kandrashin Denis преди 13 години
родител
ревизия
a068924156
променени са 1 файла, в които са добавени 18 реда и са изтрити 2 реда
  1. 18 2
      source/fb2head.cpp

+ 18 - 2
source/fb2head.cpp

@@ -181,7 +181,14 @@ void Fb2HeadModel::expand(QTreeView *view)
     for (int i = 0; i < count; i++) {
     for (int i = 0; i < count; i++) {
         QModelIndex child = index(i, 0, parent);
         QModelIndex child = index(i, 0, parent);
         Fb2HeadItem *node = item(child);
         Fb2HeadItem *node = item(child);
-        if (node) view->expand(child);
+        if (!node) continue;
+        view->expand(child);
+        int count = rowCount(child);
+        for (int j = 0; j < count; j++) {
+            QModelIndex ch = index(j, 0, child);
+            Fb2HeadItem *node = item(ch);
+            if (node) view->expand(ch);
+        }
     }
     }
 }
 }
 
 
@@ -190,7 +197,7 @@ Fb2HeadItem * Fb2HeadModel::item(const QModelIndex &index) const
     if (index.isValid()) {
     if (index.isValid()) {
         return static_cast<Fb2HeadItem*>(index.internalPointer());
         return static_cast<Fb2HeadItem*>(index.internalPointer());
     } else {
     } else {
-        return m_root;
+        return 0;
     }
     }
 }
 }
 
 
@@ -203,11 +210,17 @@ int Fb2HeadModel::columnCount(const QModelIndex &parent) const
 QModelIndex Fb2HeadModel::index(int row, int column, const QModelIndex &parent) const
 QModelIndex Fb2HeadModel::index(int row, int column, const QModelIndex &parent) const
 {
 {
     if (!m_root || row < 0 || column < 0) return QModelIndex();
     if (!m_root || row < 0 || column < 0) return QModelIndex();
+
+    if (!parent.isValid() && m_root) {
+        return createIndex(row, column, (void*)m_root);
+    }
+
     if (Fb2HeadItem *owner = item(parent)) {
     if (Fb2HeadItem *owner = item(parent)) {
         if (Fb2HeadItem *child = owner->item(row)) {
         if (Fb2HeadItem *child = owner->item(row)) {
             return createIndex(row, column, (void*)child);
             return createIndex(row, column, (void*)child);
         }
         }
     }
     }
+
     return QModelIndex();
     return QModelIndex();
 }
 }
 
 
@@ -217,6 +230,8 @@ QModelIndex Fb2HeadModel::parent(const QModelIndex &child) const
         if (Fb2HeadItem * parent = node->parent()) {
         if (Fb2HeadItem * parent = node->parent()) {
             if (Fb2HeadItem * owner = parent->parent()) {
             if (Fb2HeadItem * owner = parent->parent()) {
                 return createIndex(owner->index(parent), 0, (void*)parent);
                 return createIndex(owner->index(parent), 0, (void*)parent);
+            } else {
+                return createIndex(0, 0, (void*)parent);
             }
             }
         }
         }
     }
     }
@@ -226,6 +241,7 @@ QModelIndex Fb2HeadModel::parent(const QModelIndex &child) const
 int Fb2HeadModel::rowCount(const QModelIndex &parent) const
 int Fb2HeadModel::rowCount(const QModelIndex &parent) const
 {
 {
     if (parent.column() > 0) return 0;
     if (parent.column() > 0) return 0;
+    if (!parent.isValid()) return m_root ? 1 : 0;
     Fb2HeadItem *owner = item(parent);
     Fb2HeadItem *owner = item(parent);
     return owner ? owner->count() : 0;
     return owner ? owner->count() : 0;
 }
 }