#include "bufferviewfilter.h"
+#include <QCoreApplication>
+
#include "buffermodel.h"
#include "client.h"
#include "networkmodel.h"
#include "uisettings.h"
+class CheckRemovalEvent : public QEvent {
+public:
+ CheckRemovalEvent(const QModelIndex &source_index) : QEvent(QEvent::User), index(source_index) {};
+ QPersistentModelIndex index;
+};
+
/*****************************************
* The Filter for the Tree View
*****************************************/
setDynamicSortFilter(true);
loadColors();
+
+ connect(this, SIGNAL(_dataChanged(const QModelIndex &, const QModelIndex &)),
+ this, SLOT(_q_sourceDataChanged(QModelIndex,QModelIndex)));
}
void BufferViewFilter::loadColors() {
}
void BufferViewFilter::removeBuffer(const QModelIndex &index) {
- if(!config())
+ if(!config() || !index.isValid() || index.data(NetworkModel::ItemTypeRole) != NetworkModel::BufferItemType)
return;
-
+
BufferId bufferId = data(index, NetworkModel::BufferIdRole).value<BufferId>();
config()->requestRemoveBuffer(bufferId);
}
}
void BufferViewFilter::source_rowsInserted(const QModelIndex &parent, int start, int end) {
- if(parent.data(NetworkModel::ItemTypeRole) != NetworkModel::NetworkItemType)
+ if(parent.data(NetworkModel::ItemTypeRole) != NetworkModel::BufferItemType)
return;
if(!config() || !config()->addNewBuffersAutomatically())
}
}
+void BufferViewFilter::checkPreviousCurrentForRemoval(const QModelIndex ¤t, const QModelIndex &previous) {
+ Q_UNUSED(current);
+ if(previous.isValid())
+ QCoreApplication::postEvent(this, new CheckRemovalEvent(previous));
+}
+
+void BufferViewFilter::customEvent(QEvent *event) {
+ if(event->type() != QEvent::User)
+ return;
+
+ CheckRemovalEvent *removalEvent = static_cast<CheckRemovalEvent *>(event);
+ checkItemForRemoval(removalEvent->index);
+
+ event->accept();
+}
+
+void BufferViewFilter::checkItemsForRemoval(const QModelIndex &topLeft, const QModelIndex &bottomRight) {
+ QModelIndex source_topLeft = mapToSource(topLeft);
+ QModelIndex source_bottomRight = mapToSource(bottomRight);
+ emit _dataChanged(source_topLeft, source_bottomRight);
+}
+
// ******************************
// Helper
// ******************************