23 #include <QApplication>
40 QPersistentModelIndex
index;
47 BufferViewFilter::BufferViewFilter(QAbstractItemModel *model,
BufferViewConfig *config)
48 : QSortFilterProxyModel(model),
50 _sortOrder(Qt::AscendingOrder),
51 _showServerQueries(false),
53 _enableEditMode(tr(
"Show / Hide Chats"), this)
56 setSourceModel(model);
58 setDynamicSortFilter(
true);
60 connect(
this, SIGNAL(_dataChanged(
const QModelIndex &,
const QModelIndex &)),
61 this, SLOT(_q_sourceDataChanged(QModelIndex, QModelIndex)));
63 _enableEditMode.setCheckable(
true);
64 _enableEditMode.setChecked(_editMode);
65 connect(&_enableEditMode, SIGNAL(toggled(
bool)),
this, SLOT(enableEditMode(
bool)));
68 defaultSettings.
notify(
"ServerNoticesTarget",
this, SLOT(showServerQueriesChanged()));
69 showServerQueriesChanged();
79 disconnect(
_config, 0,
this, 0);
96 connect(config, SIGNAL(initDone()),
this, SLOT(
configInitialized()), Qt::QueuedConnection);
123 setObjectName(
config()->bufferViewName());
145 QList<QAction *> actionList;
161 if (enable ==
false) {
163 QSet<BufferId>::const_iterator iter;
185 QModelIndex source_index = mapToSource(index);
186 Qt::ItemFlags
flags = sourceModel()->flags(source_index);
191 flags |= Qt::ItemIsDropEnabled;
194 flags |= Qt::ItemIsUserCheckable | Qt::ItemIsTristate;
201 if (clientConf && clientConf->
isLocked()) {
202 flags &= ~(Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled);
216 QModelIndex source_parent = mapToSource(parent);
224 for (
int i = 0; i < bufferList.count(); i++) {
225 networkId = bufferList[i].first;
226 bufferId = bufferList[i].second;
227 if (droppedNetworkId == networkId) {
231 if (row < rowCount(parent)) {
232 QModelIndex source_child = mapToSource(index(row, 0, parent));
245 if (
config()->bufferList().contains(bufferId) && !
config()->sortAlphabetically()) {
246 if (
config()->bufferList().indexOf(bufferId) < pos)
249 if (!clientConf || !clientConf->
isLocked())
273 if (!
config() ||
config()->bufferList().contains(bufferId))
299 foreach(
BufferId bufferId, bufferIds) {
300 if (bufferList.contains(bufferId))
303 int pos = bufferList.count();
305 for (
int i = 0; i < bufferList.count(); i++) {
313 bufferList.insert(pos, bufferId);
335 if (
config()->isInitialized()
336 && !
config()->removedBuffers().contains(bufferId)
337 && ((
config()->addNewBuffersAutomatically() && !
config()->temporarilyRemovedBuffers().contains(bufferId))
349 if (!
config()->networkId().isValid())
350 allowedBufferTypes &= ~
BufferInfo::StatusBuffer;
352 if (!(allowedBufferTypes & bufferType))
367 if (
config()->minimumActivity() > activityLevel)
383 if (!
config()->networkId().isValid()) {
394 QModelIndex child = sourceModel()->index(source_row, 0, source_parent);
396 if (!child.isValid()) {
397 qWarning() <<
"filterAcceptsRow has been called with an invalid Child";
417 int itemType = leftItemType & rightItemType;
436 if (leftPos == -1 && rightPos == -1)
438 if (leftPos == -1 || rightPos == -1)
439 return !(leftPos < rightPos);
440 return leftPos < rightPos;
460 case Qt::ForegroundRole:
461 case Qt::BackgroundRole:
462 case Qt::DecorationRole:
466 case Qt::CheckStateRole:
479 QModelIndex source_index = mapToSource(index);
484 if (
_toAdd.contains(bufferId))
488 return Qt::PartiallyChecked;
491 return Qt::Unchecked;
497 return Qt::PartiallyChecked;
499 return Qt::Unchecked;
506 case Qt::CheckStateRole:
516 QModelIndex source_index = mapToSource(index);
527 case Qt::PartiallyChecked:
540 emit dataChanged(index, index);
548 if (previous.isValid())
555 if (event->type() != QEvent::User)
567 QModelIndex source_topLeft = mapToSource(topLeft);
568 QModelIndex source_bottomRight = mapToSource(bottomRight);
585 if (leftType != rightType)
586 return leftType < rightType;