Add some checks to models
[quassel.git] / src / client / messagemodel.h
index 623efa6..f4a7655 100644 (file)
@@ -56,7 +56,7 @@ public:
 
   MessageModel(QObject *parent);
 
-  inline QModelIndex index(int row, int column, const QModelIndex &/*parent*/ = QModelIndex()) const { return createIndex(row, column); }
+  inline QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
   inline QModelIndex parent(const QModelIndex &) const { return QModelIndex(); }
   inline int rowCount(const QModelIndex &parent = QModelIndex()) const { return parent.isValid() ? 0 : messageCount(); }
   inline int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const { return 3; }
@@ -111,6 +111,14 @@ private:
   QHash<BufferId, int> _messagesWaiting;
 };
 
+// inlines
+QModelIndex MessageModel::index(int row, int column, const QModelIndex &parent) const {
+  if(row < 0 || row >= rowCount(parent) || column < 0 || column >= columnCount(parent))
+    return QModelIndex();
+
+  return createIndex(row, column);
+}
+
 // **************************************************
 //  MessageModelItem
 // **************************************************