accidentaly deactivated custom sorting... ooops
[quassel.git] / src / uisupport / bufferviewfilter.cpp
index 3e4886c..9ddb6f0 100644 (file)
@@ -39,7 +39,6 @@ BufferViewFilter::BufferViewFilter(QAbstractItemModel *model, BufferViewConfig *
   setSourceModel(model);
   connect(model, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(source_rowsInserted(const QModelIndex &, int, int)));
                        
-  // setSortCaseSensitivity(Qt::CaseInsensitive);
   setDynamicSortFilter(true);
 }
 
@@ -116,7 +115,7 @@ bool BufferViewFilter::dropMimeData(const QMimeData *data, Qt::DropAction action
 }
 
 void BufferViewFilter::addBuffer(const BufferId &bufferId) {
-  if(config()->bufferList().contains(bufferId))
+  if(!config() || config()->bufferList().contains(bufferId))
     return;
   
   int pos = config()->bufferList().count();
@@ -145,9 +144,11 @@ void BufferViewFilter::removeBuffer(const QModelIndex &index) {
 
 
 bool BufferViewFilter::filterAcceptBuffer(const QModelIndex &source_bufferIndex) const {
+  BufferId bufferId = sourceModel()->data(source_bufferIndex, NetworkModel::BufferIdRole).value<BufferId>();
+  Q_ASSERT(bufferId.isValid());
   if(!_config)
     return true;
-
+  
   if(config()->networkId().isValid() && config()->networkId() != sourceModel()->data(source_bufferIndex, NetworkModel::NetworkIdRole).value<NetworkId>())
     return false;
 
@@ -158,11 +159,10 @@ bool BufferViewFilter::filterAcceptBuffer(const QModelIndex &source_bufferIndex)
     return false;
 
   if(_config->minimumActivity() > source_bufferIndex.data(NetworkModel::BufferActivityRole).toInt()) {
-    if(!Client::bufferModel()->standardSelectionModel()->isSelected(source_bufferIndex))
+    if(bufferId != Client::bufferModel()->standardSelectionModel()->currentIndex().data(NetworkModel::BufferIdRole).value<BufferId>())
       return false;
   }
 
-  BufferId bufferId = sourceModel()->data(source_bufferIndex, NetworkModel::BufferIdRole).value<BufferId>();
   return _config->bufferList().contains(bufferId);
 }
 
@@ -185,7 +185,7 @@ bool BufferViewFilter::filterAcceptsRow(int source_row, const QModelIndex &sourc
     return false;
   }
 
-  if(source_parent == QModelIndex())
+  if(!source_parent.isValid())
     return filterAcceptNetwork(child);
   else
     return filterAcceptBuffer(child);
@@ -260,8 +260,10 @@ void BufferViewFilter::source_rowsInserted(const QModelIndex &parent, int start,
   if(!config() || !config()->addNewBuffersAutomatically())
     return;
 
+  QModelIndex child;
   for(int row = start; row <= end; row++) {
-    addBuffer(parent.child(row, 0).data(NetworkModel::BufferIdRole).value<BufferId>());
+    child = sourceModel()->index(row, 0, parent);
+    addBuffer(sourceModel()->data(child, NetworkModel::BufferIdRole).value<BufferId>());
   }
 }
 
@@ -282,6 +284,6 @@ bool bufferIdLessThan(const BufferId &left, const BufferId &right) {
   if(leftType != rightType)
     return leftType < rightType;
   else
-    return Client::networkModel()->data(leftIndex, Qt::DisplayRole).toString() < Client::networkModel()->data(rightIndex, Qt::DisplayRole).toString();
+    return QString::compare(Client::networkModel()->data(leftIndex, Qt::DisplayRole).toString(), Client::networkModel()->data(rightIndex, Qt::DisplayRole).toString(), Qt::CaseInsensitive) < 0;
 }