Jelajahi Sumber

Small optimization FbTreeModel

Kandrashin Denis 13 tahun lalu
induk
melakukan
a9ba04211f
5 mengubah file dengan 12 tambahan dan 11 penghapusan
  1. 2 2
      source/fb2edit.pro
  2. 1 1
      source/fb2main.cpp
  3. 3 3
      source/fb2text.h
  4. 5 4
      source/fb2tree.cpp
  5. 1 1
      source/fb2tree.h

+ 2 - 2
source/fb2edit.pro

@@ -3,8 +3,8 @@ HEADERS = \
     fb2doc.h \
     fb2main.h \
     fb2read.h \
-    fb2tree.h \
-    fb2edit.h
+    fb2text.h \
+    fb2tree.h
 
 SOURCES = \
     fb2app.cpp \

+ 1 - 1
source/fb2main.cpp

@@ -4,8 +4,8 @@
 
 #include "fb2main.h"
 #include "fb2doc.h"
-#include "fb2edit.h"
 #include "fb2read.h"
+#include "fb2text.h"
 #include "fb2tree.h"
 
 #include <Qsci/qsciscintilla.h>

+ 3 - 3
source/fb2edit.h → source/fb2text.h

@@ -1,5 +1,5 @@
-#ifndef FB2EDIT_H
-#define FB2EDIT_H
+#ifndef FB2TEXT_H
+#define FB2TEXT_H
 
 #include <QResizeEvent>
 #include <QTextEdit>
@@ -35,4 +35,4 @@ private:
     QSize m_size;
 };
 
-#endif // FB2EDIT_H
+#endif // FB2TEXT_H

+ 5 - 4
source/fb2tree.cpp

@@ -27,10 +27,11 @@ Fb2TreeItem::~Fb2TreeItem()
     }
 }
 
-Fb2TreeItem * Fb2TreeItem::item(int index) const
+Fb2TreeItem * Fb2TreeItem::item(const QModelIndex &index) const
 {
-    if (index < 0 || index >= m_list.size()) return NULL;
-    return m_list[index];
+    int row = index.row();
+    if (row < 0 || row >= m_list.size()) return NULL;
+    return m_list[row];
 }
 
 QString Fb2TreeItem::text() const
@@ -62,7 +63,7 @@ Fb2TreeItem * Fb2TreeModel::item(const QModelIndex &index) const
     if (!m_root) return NULL;
     if (!index.isValid()) return m_root;
     Fb2TreeItem * parent = item(index.parent());
-    return parent ? parent->item(index.row()) : NULL;
+    return parent ? parent->item(index) : NULL;
 }
 
 int Fb2TreeModel::columnCount(const QModelIndex &parent) const

+ 1 - 1
source/fb2tree.h

@@ -13,7 +13,7 @@ public:
 
     virtual ~Fb2TreeItem();
 
-    Fb2TreeItem * item(int index) const;
+    Fb2TreeItem * item(const QModelIndex &index) const;
 
     int index(Fb2TreeItem * child) const {
         return m_list.indexOf(child);