Make sure NickView::customEvent() has a valid model
[quassel.git] / src / uisupport / nickview.cpp
index e27640e..11b40c7 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "nickview.h"
 
+#include <QApplication>
 #include <QHeaderView>
 #include <QScrollBar>
 #include <QDebug>
@@ -33,7 +34,6 @@
 #include "nickviewfilter.h"
 #include "networkmodel.h"
 #include "types.h"
-#include "uisettings.h"
 
 class ExpandAllEvent : public QEvent {
 public:
@@ -43,11 +43,6 @@ public:
 NickView::NickView(QWidget *parent)
   : QTreeView(parent)
 {
-  QAbstractItemDelegate *oldDelegate = itemDelegate();
-  NickViewDelegate *newDelegate = new NickViewDelegate(this);
-  setItemDelegate(newDelegate);
-  delete oldDelegate;
-
   setIndentation(10);
   setAnimated(true);
   header()->hide();
@@ -149,6 +144,9 @@ void NickView::customEvent(QEvent *event) {
   if(event->type() != QEvent::User)
     return;
 
+  if(!model())
+    return;
+
   QModelIndex topLevelIdx;
   for(int i = 0; i < model()->rowCount(rootIndex()); i++) {
     topLevelIdx = model()->index(i, 0, rootIndex());
@@ -163,28 +161,3 @@ void NickView::customEvent(QEvent *event) {
   }
   event->accept();
 }
-
-
-// ****************************************
-//  NickViewDelgate
-// ****************************************
-NickViewDelegate::NickViewDelegate(QObject *parent)
-  : QStyledItemDelegate(parent)
-{
-  UiSettings s("QtUiStyle/Colors");
-  _FgOnlineStatus = s.value("onlineStatusFG", QVariant(QColor(Qt::black))).value<QColor>();
-  _FgAwayStatus = s.value("awayStatusFG", QVariant(QColor(Qt::gray))).value<QColor>();
-}
-
-void NickViewDelegate::initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const {
-  QStyledItemDelegate::initStyleOption(option, index);
-
-  if(!index.isValid())
-    return;
-
-  QColor fgColor = _FgOnlineStatus;
-  if(!index.data(NetworkModel::ItemActiveRole).toBool())
-    fgColor = _FgAwayStatus;
-
-  option->palette.setColor(QPalette::Text, fgColor);
-}