X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fbufferviewfilter.cpp;h=49f1673a2ea538937e36aabd7a0a6870ffdf6aa3;hp=896bd116a021975566ce266ec86dec117b753ec0;hb=567fa5b9eb57110231bb1f485819dde6d2b56c92;hpb=997a62b68d7469a93f373476dd955c44eb051be0 diff --git a/src/uisupport/bufferviewfilter.cpp b/src/uisupport/bufferviewfilter.cpp index 896bd116..49f1673a 100644 --- a/src/uisupport/bufferviewfilter.cpp +++ b/src/uisupport/bufferviewfilter.cpp @@ -22,6 +22,7 @@ #include +#include "buffermodel.h" #include "client.h" #include "networkmodel.h" @@ -36,7 +37,8 @@ BufferViewFilter::BufferViewFilter(QAbstractItemModel *model, BufferViewConfig * { setConfig(config); setSourceModel(model); - // setSortCaseSensitivity(Qt::CaseInsensitive); + connect(model, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(source_rowsInserted(const QModelIndex &, int, int))); + setDynamicSortFilter(true); } @@ -88,6 +90,8 @@ bool BufferViewFilter::dropMimeData(const QMimeData *data, Qt::DropAction action networkId = bufferList[i].first; bufferId = bufferList[i].second; if(droppedNetworkId == networkId) { + if(row < 0) + row = 0; if(row < rowCount(parent)) { BufferId beforeBufferId = parent.child(row, 0).data(NetworkModel::BufferIdRole).value(); pos = config()->bufferList().indexOf(beforeBufferId); @@ -111,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(); @@ -140,20 +144,26 @@ void BufferViewFilter::removeBuffer(const QModelIndex &index) { bool BufferViewFilter::filterAcceptBuffer(const QModelIndex &source_bufferIndex) const { + BufferId bufferId = sourceModel()->data(source_bufferIndex, NetworkModel::BufferIdRole).value(); + Q_ASSERT(bufferId.isValid()); if(!_config) return true; + if(config()->networkId().isValid() && config()->networkId() != sourceModel()->data(source_bufferIndex, NetworkModel::NetworkIdRole).value()) + return false; + if(!(_config->allowedBufferTypes() & (BufferInfo::Type)source_bufferIndex.data(NetworkModel::BufferTypeRole).toInt())) return false; if(_config->hideInactiveBuffers() && !source_bufferIndex.data(NetworkModel::ItemActiveRole).toBool()) return false; - if(_config->minimumActivity() > source_bufferIndex.data(NetworkModel::BufferActivityRole).toInt()) - return false; + if(_config->minimumActivity() > source_bufferIndex.data(NetworkModel::BufferActivityRole).toInt()) { + if(bufferId != Client::bufferModel()->standardSelectionModel()->currentIndex().data(NetworkModel::BufferIdRole).value()) + return false; + } - BufferId bufferId = sourceModel()->data(source_bufferIndex, NetworkModel::BufferIdRole).value(); - return _config->bufferList().contains(bufferId); + return _config->bufferList().contains(bufferId); } bool BufferViewFilter::filterAcceptNetwork(const QModelIndex &source_index) const { @@ -175,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); @@ -194,12 +204,13 @@ bool BufferViewFilter::lessThan(const QModelIndex &source_left, const QModelInde } bool BufferViewFilter::bufferLessThan(const QModelIndex &source_left, const QModelIndex &source_right) const { + return QSortFilterProxyModel::lessThan(source_left, source_right); BufferId leftBufferId = sourceModel()->data(source_left, NetworkModel::BufferIdRole).value(); BufferId rightBufferId = sourceModel()->data(source_right, NetworkModel::BufferIdRole).value(); if(config()) { return config()->bufferList().indexOf(leftBufferId) < config()->bufferList().indexOf(rightBufferId); } else - return leftBufferId < rightBufferId; + return bufferIdLessThan(leftBufferId, rightBufferId); } bool BufferViewFilter::networkLessThan(const QModelIndex &source_left, const QModelIndex &source_right) const { @@ -243,6 +254,19 @@ QVariant BufferViewFilter::foreground(const QModelIndex &index) const { } +void BufferViewFilter::source_rowsInserted(const QModelIndex &parent, int start, int end) { + if(parent.data(NetworkModel::ItemTypeRole) != NetworkModel::BufferItemType) + return; + + if(!config() || !config()->addNewBuffersAutomatically()) + return; + + QModelIndex child; + for(int row = start; row <= end; row++) { + child = sourceModel()->index(row, 0, parent); + addBuffer(sourceModel()->data(child, NetworkModel::BufferIdRole).value()); + } +} // ****************************** // Helper @@ -261,6 +285,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; }