X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fuisupport%2Fbufferviewfilter.cpp;h=3e0a59f00e8ab326d79fa00f799dc282e0fa34ff;hb=5916720e01ef3473e06e9134507a6099c2466198;hp=dfad3c21affe14b628b5cc64a5abb4fb704b6181;hpb=7401b1e634438ea9cafd195a79a804b42cc9f135;p=quassel.git diff --git a/src/uisupport/bufferviewfilter.cpp b/src/uisupport/bufferviewfilter.cpp index dfad3c21..3e0a59f0 100644 --- a/src/uisupport/bufferviewfilter.cpp +++ b/src/uisupport/bufferviewfilter.cpp @@ -28,6 +28,7 @@ #include "buffermodel.h" #include "buffersettings.h" #include "client.h" +#include "clientbufferviewconfig.h" #include "iconloader.h" #include "networkmodel.h" @@ -167,12 +168,23 @@ void BufferViewFilter::enableEditMode(bool enable) { Qt::ItemFlags BufferViewFilter::flags(const QModelIndex &index) const { QModelIndex source_index = mapToSource(index); Qt::ItemFlags flags = sourceModel()->flags(source_index); - if(_config) { - if(source_index == QModelIndex() || sourceModel()->data(source_index, NetworkModel::ItemTypeRole) == NetworkModel::NetworkItemType) { + if(config()) { + NetworkModel::ItemType itemType = (NetworkModel::ItemType)sourceModel()->data(source_index, NetworkModel::ItemTypeRole).toInt(); + BufferInfo::Type bufferType = (BufferInfo::Type)sourceModel()->data(source_index, NetworkModel::BufferTypeRole).toInt(); + if(source_index == QModelIndex() || itemType == NetworkModel::NetworkItemType) { flags |= Qt::ItemIsDropEnabled; } else if(_editMode) { flags |= Qt::ItemIsUserCheckable | Qt::ItemIsTristate; } + + // prohibit dragging of most items. and most drop places + // only query to query is allowed for merging + if(bufferType != BufferInfo::QueryBuffer) { + ClientBufferViewConfig *clientConf = qobject_cast(config()); + if(clientConf && clientConf->isLocked()) { + flags &= ~(Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled); + } + } } return flags; } @@ -198,7 +210,7 @@ bool BufferViewFilter::dropMimeData(const QMimeData *data, Qt::DropAction action row = 0; if(row < rowCount(parent)) { - QModelIndex source_child = sourceModel()->index(row, 0, parent); + QModelIndex source_child = mapToSource(index(row, 0, parent)); BufferId beforeBufferId = sourceModel()->data(source_child, NetworkModel::BufferIdRole).value(); pos = config()->bufferList().indexOf(beforeBufferId); if(_sortOrder == Qt::DescendingOrder) @@ -262,7 +274,8 @@ bool BufferViewFilter::filterAcceptBuffer(const QModelIndex &source_bufferIndex) if(!config()->bufferList().contains(bufferId) && !_editMode) { // add the buffer if... - if(config()->isInitialized() && !config()->removedBuffers().contains(bufferId) // it hasn't been manually removed and either + if(config()->isInitialized() + && !config()->removedBuffers().contains(bufferId) // it hasn't been manually removed and either && ((config()->addNewBuffersAutomatically() && !config()->temporarilyRemovedBuffers().contains(bufferId)) // is totally unknown to us (a new buffer)... || (config()->temporarilyRemovedBuffers().contains(bufferId) && activityLevel > BufferInfo::OtherActivity))) { // or was just temporarily hidden and has a new message waiting for us. addBuffer(bufferId); @@ -313,10 +326,15 @@ bool BufferViewFilter::filterAcceptsRow(int source_row, const QModelIndex &sourc return false; } - if(!source_parent.isValid()) + NetworkModel::ItemType childType = (NetworkModel::ItemType)sourceModel()->data(child, NetworkModel::ItemTypeRole).toInt(); + switch(childType) { + case NetworkModel::NetworkItemType: return filterAcceptNetwork(child); - else + case NetworkModel::BufferItemType: return filterAcceptBuffer(child); + default: + return false; + } } bool BufferViewFilter::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const { @@ -352,10 +370,7 @@ bool BufferViewFilter::networkLessThan(const QModelIndex &source_left, const QMo NetworkId leftNetworkId = sourceModel()->data(source_left, NetworkModel::NetworkIdRole).value(); NetworkId rightNetworkId = sourceModel()->data(source_right, NetworkModel::NetworkIdRole).value(); - if(config() && config()->sortAlphabetically()) - return QSortFilterProxyModel::lessThan(source_left, source_right); - else - return leftNetworkId < rightNetworkId; + return QSortFilterProxyModel::lessThan(source_left, source_right); } QVariant BufferViewFilter::data(const QModelIndex &index, int role) const { @@ -377,6 +392,9 @@ QVariant BufferViewFilter::icon(const QModelIndex &index) const { return QVariant(); QModelIndex source_index = mapToSource(index); + if(sourceModel()->data(source_index, NetworkModel::ItemTypeRole).toInt() != NetworkModel::BufferItemType) + return QVariant(); + if(sourceModel()->data(source_index, NetworkModel::BufferTypeRole).toInt() != BufferInfo::QueryBuffer) return QVariant();