some minor tweaks
[quassel.git] / src / qtgui / bufferview.cpp
index d30e4da..0fae80d 100644 (file)
  ***************************************************************************/
 
 #include "bufferview.h"
-#include "bufferviewwidget.h"
-
-/*****************************************
-* The TreeView showing the Buffers
-*****************************************/
-BufferViewFilter::BufferViewFilter(QAbstractItemModel *model, Modes filtermode, QStringList nets, QObject *parent) : QSortFilterProxyModel(parent) {
-  setSourceModel(model);
-  mode = filtermode;
-  networks = nets;
-  
-  connect(model, SIGNAL(invalidateFilter()), this, SLOT(invalidateMe()));
-  connect(model, SIGNAL(updateSelection(const QModelIndex &, QItemSelectionModel::SelectionFlags)), this, SLOT(select(const QModelIndex &, QItemSelectionModel::SelectionFlags)));
-    
-  connect(this, SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), model, SLOT(changeCurrent(const QModelIndex &, const QModelIndex &)));
-  connect(this, SIGNAL(doubleClicked(const QModelIndex &)), model, SLOT(doubleClickReceived(const QModelIndex &)));
-}
-
-void BufferViewFilter::invalidateMe() {
-  invalidateFilter();
-}
-
-void BufferViewFilter::select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) {
-  emit updateSelection(mapFromSource(index), command);
-}
-
-void BufferViewFilter::changeCurrent(const QModelIndex &current, const QModelIndex &previous) {
-  emit currentChanged(mapToSource(current), mapToSource(previous));
-}
-
-void BufferViewFilter::doubleClickReceived(const QModelIndex &clicked) {
-  emit doubleClicked(mapToSource(clicked));
-}
-
-bool BufferViewFilter::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const {
-  QModelIndex child = source_parent.child(source_row, 0);
-  if(!child.isValid())
-    return true; // can't imagine this case but true sounds good :)
-  
-  Buffer::Type bufferType = (Buffer::Type) child.data(BufferTreeModel::BufferTypeRole).toInt();
-  if((mode & NoChannels) && bufferType == Buffer::ChannelBuffer) return false;
-  if((mode & NoQueries) && bufferType == Buffer::QueryBuffer) return false;
-  if((mode & NoServers) && bufferType == Buffer::ServerBuffer) return false;
-
-  bool isActive = child.data(BufferTreeModel::BufferActiveRole).toBool();
-  if((mode & NoActive) && isActive) return false;
-  if((mode & NoInactive) && !isActive) return false;
-
-  QString net = child.data(Qt::DisplayRole).toString();
-  if((mode & SomeNets) && !networks.contains(net)) return false;
-    
-  return true;
-}
 
 /*****************************************
 * The TreeView showing the Buffers
@@ -84,21 +32,35 @@ void BufferView::init() {
   setIndentation(10);
   header()->hide();
   header()->hideSection(1);
+  expandAll();
   
   setDragEnabled(true);
   setAcceptDrops(true);
   setDropIndicatorShown(true);
   
-  connect(selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), model(), SLOT(changeCurrent(const QModelIndex &, const QModelIndex &)));
-  connect(this, SIGNAL(doubleClicked(const QModelIndex &)), model(), SLOT(doubleClickReceived(const QModelIndex &)));
-  connect(model(), SIGNAL(updateSelection(const QModelIndex &, QItemSelectionModel::SelectionFlags)), selectionModel(), SLOT(select(const QModelIndex &, QItemSelectionModel::SelectionFlags)));
+  setSortingEnabled(true);
+  sortByColumn(0, Qt::AscendingOrder);
+  
+  connect(selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
+          model(), SLOT(changeCurrent(const QModelIndex &, const QModelIndex &)));
+  
+  connect(this, SIGNAL(doubleClicked(const QModelIndex &)),
+          model(), SLOT(doubleClickReceived(const QModelIndex &)));
+  
+  connect(model(), SIGNAL(selectionChanged(const QModelIndex &)),
+          this, SLOT(select(const QModelIndex &)));
+  
+  connect(this, SIGNAL(selectionChanged(const QModelIndex &, QItemSelectionModel::SelectionFlags)),
+          selectionModel(), SLOT(select(const QModelIndex &, QItemSelectionModel::SelectionFlags)));
 
-  expandAll();
 }
 
 void BufferView::setFilteredModel(QAbstractItemModel *model, BufferViewFilter::Modes mode, QStringList nets) {
   BufferViewFilter *filter = new BufferViewFilter(model, mode, nets);
   setModel(filter);
+  connect(this, SIGNAL(eventDropped(QDropEvent *)), filter, SLOT(dropEvent(QDropEvent *)));
+  //connect(this, SIGNAL(dragEnter()), filter, SLOT(enterDrag()));
+  //connect(this, SIGNAL(dragLeave()), filter, SLOT(leaveDrag()));
 }
 
 void BufferView::setModel(QAbstractItemModel *model) {
@@ -106,11 +68,37 @@ void BufferView::setModel(QAbstractItemModel *model) {
   init();
 }
 
+void BufferView::select(const QModelIndex &current) {
+  emit selectionChanged(current, QItemSelectionModel::ClearAndSelect);
+}
+
+void BufferView::dropEvent(QDropEvent *event) {
+  if(event->source() == this) {
+    // this is either a merge or a sort operation... 
+    // currently only merges are supported
+  } else {
+    emit eventDropped(event);
+  }
+  QTreeView::dropEvent(event);    
+  
+}
+
+/*
+ done prettier now..
+// dragEnterEvent and dragLeaveEvent are needed to keep track of the active
+// view when customizing them via drag and drop
 void BufferView::dragEnterEvent(QDragEnterEvent *event) {
-  // not yet needed... this will be usefull to keep track of the active view when customizing them with drag and drop
+  emit dragEnter();
   QTreeView::dragEnterEvent(event);
 }
 
+void BufferView::dragLeaveEvent(QDragLeaveEvent *event) {
+  emit dragLeave();
+  QTreeView::dragLeaveEvent(event);
+}
+*/
+
+// ensure that newly inserted network nodes are expanded per default
 void BufferView::rowsInserted(const QModelIndex & parent, int start, int end) {
   if(parent.parent() == QModelIndex()) setExpanded(parent, true);
   QTreeView::rowsInserted(parent, start, end);