some minor tweaks
authorMarcus Eggenberger <egs@quassel-irc.org>
Fri, 22 Jun 2007 19:39:41 +0000 (19:39 +0000)
committerMarcus Eggenberger <egs@quassel-irc.org>
Fri, 22 Jun 2007 19:39:41 +0000 (19:39 +0000)
src/client/buffertreemodel.cpp
src/client/buffertreemodel.h
src/qtgui/bufferview.cpp
src/qtgui/bufferview.h
src/qtgui/bufferviewfilter.cpp
src/qtgui/bufferviewfilter.h
src/qtgui/bufferviewwidget.cpp
src/qtgui/bufferviewwidget.h

index 43f624e..3aac9f3 100644 (file)
@@ -86,7 +86,8 @@ QVariant BufferTreeItem::data(int column, int role) const {
  * BufferTreeModel
  *****************************************/
 BufferTreeModel::BufferTreeModel(QObject *parent) : TreeModel(BufferTreeModel::defaultHeader(), parent) {
  * BufferTreeModel
  *****************************************/
 BufferTreeModel::BufferTreeModel(QObject *parent) : TreeModel(BufferTreeModel::defaultHeader(), parent) {
-  connect(this, SIGNAL(fakeUserInput(BufferId, QString)), ClientProxy::instance(), SLOT(gsUserInput(BufferId, QString)));
+  connect(this, SIGNAL(fakeUserInput(BufferId, QString)),
+          ClientProxy::instance(), SLOT(gsUserInput(BufferId, QString)));
 }
 
 QList<QVariant >BufferTreeModel::defaultHeader() {
 }
 
 QList<QVariant >BufferTreeModel::defaultHeader() {
@@ -190,24 +191,16 @@ bool BufferTreeModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
   int sourcerow = data->data("application/Quassel/BufferItem/row").toInt();
   QString network = QString::fromUtf8(data->data("application/Quassel/BufferItem/network"));
   
   int sourcerow = data->data("application/Quassel/BufferItem/row").toInt();
   QString network = QString::fromUtf8(data->data("application/Quassel/BufferItem/network"));
   
-  if(!networkItem.contains(network))
-    return false;
+  Q_ASSERT(networkItem.contains(network));
 
 
+  if(parent == QModelIndex()) // can't be a query...
+    return false;
   
   Buffer *sourceBuffer = static_cast<BufferTreeItem *>(networkItem[network]->child(sourcerow))->buffer();
   
   Buffer *sourceBuffer = static_cast<BufferTreeItem *>(networkItem[network]->child(sourcerow))->buffer();
-
-  if(parent == QModelIndex()) { // droping into empty space
-    emit addBuffer(sourceBuffer->bufferId().uid(), network);
-    return true;
-  }
-    
-  if(!isBufferIndex(parent)) { // dropping at a network
-    emit addBuffer(sourceBuffer->bufferId().uid(), network);
-    return true;
-  }
-
-
   Buffer *targetBuffer = getBufferByIndex(parent);
   Buffer *targetBuffer = getBufferByIndex(parent);
+
+  if(!(sourceBuffer->bufferType() & targetBuffer->bufferType() & Buffer::QueryBuffer)) // only queries can be merged
+    return false;
   
   if(sourceBuffer == targetBuffer) // we won't merge with ourself :)
     return false;
   
   if(sourceBuffer == targetBuffer) // we won't merge with ourself :)
     return false;
@@ -239,7 +232,7 @@ void BufferTreeModel::changeCurrent(const QModelIndex &current, const QModelInde
     currentBuffer = getBufferByIndex(current);
     bufferActivity(Buffer::NoActivity, currentBuffer);
     emit bufferSelected(currentBuffer);
     currentBuffer = getBufferByIndex(current);
     bufferActivity(Buffer::NoActivity, currentBuffer);
     emit bufferSelected(currentBuffer);
-    emit updateSelection(current, QItemSelectionModel::ClearAndSelect);
+    emit selectionChanged(current);
   }
 }
 
   }
 }
 
@@ -250,7 +243,6 @@ void BufferTreeModel::doubleClickReceived(const QModelIndex &clicked) {
     if(!buffer->isStatusBuffer()) 
       emit fakeUserInput(buffer->bufferId(), QString("/join " + buffer->bufferName()));
   }
     if(!buffer->isStatusBuffer()) 
       emit fakeUserInput(buffer->bufferId(), QString("/join " + buffer->bufferName()));
   }
-    
 }
 
 void BufferTreeModel::bufferActivity(Buffer::ActivityLevel level, Buffer *buffer) {
 }
 
 void BufferTreeModel::bufferActivity(Buffer::ActivityLevel level, Buffer *buffer) {
@@ -263,5 +255,5 @@ void BufferTreeModel::bufferActivity(Buffer::ActivityLevel level, Buffer *buffer
 
 void BufferTreeModel::selectBuffer(Buffer *buffer) {
   QModelIndex index = getOrCreateBufferItemIndex(buffer);
 
 void BufferTreeModel::selectBuffer(Buffer *buffer) {
   QModelIndex index = getOrCreateBufferItemIndex(buffer);
-  emit updateSelection(index, QItemSelectionModel::ClearAndSelect);
+  emit selectionChanged(index);
 }
 }
index f849018..9916edd 100644 (file)
@@ -22,7 +22,6 @@
 #define _BUFFERTREEMODEL_H_
 
 #include <QtCore>
 #define _BUFFERTREEMODEL_H_
 
 #include <QtCore>
-#include <QItemSelectionModel> // FIXME Dependency on QtGui
 
 #include "treemodel.h"
 #include "buffer.h"
 
 #include "treemodel.h"
 #include "buffer.h"
@@ -63,7 +62,6 @@ public:
     BufferIdRole
   };
   
     BufferIdRole
   };
   
-  //BufferTreeModel(const QList<QVariant> &, QObject *parent = 0);
   BufferTreeModel(QObject *parent = 0);
   static QList<QVariant> defaultHeader();
 
   BufferTreeModel(QObject *parent = 0);
   static QList<QVariant> defaultHeader();
 
@@ -82,8 +80,7 @@ signals:
   void bufferSelected(Buffer *);
   void invalidateFilter();
   void fakeUserInput(BufferId, QString);
   void bufferSelected(Buffer *);
   void invalidateFilter();
   void fakeUserInput(BufferId, QString);
-  void updateSelection(const QModelIndex &, QItemSelectionModel::SelectionFlags);
-  void addBuffer(const uint &, const QString &);
+  void selectionChanged(const QModelIndex &);
     
 private:
   bool isBufferIndex(const QModelIndex &) const;
     
 private:
   bool isBufferIndex(const QModelIndex &) const;
index 33eab93..0fae80d 100644 (file)
@@ -30,7 +30,7 @@ BufferView::BufferView(QWidget *parent) : QTreeView(parent) {
 
 void BufferView::init() {
   setIndentation(10);
 
 void BufferView::init() {
   setIndentation(10);
-  //header()->hide();
+  header()->hide();
   header()->hideSection(1);
   expandAll();
   
   header()->hideSection(1);
   expandAll();
   
@@ -47,7 +47,10 @@ void BufferView::init() {
   connect(this, SIGNAL(doubleClicked(const QModelIndex &)),
           model(), SLOT(doubleClickReceived(const QModelIndex &)));
   
   connect(this, SIGNAL(doubleClicked(const QModelIndex &)),
           model(), SLOT(doubleClickReceived(const QModelIndex &)));
   
-  connect(model(), SIGNAL(updateSelection(const QModelIndex &, QItemSelectionModel::SelectionFlags)),
+  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)));
 
 }
           selectionModel(), SLOT(select(const QModelIndex &, QItemSelectionModel::SelectionFlags)));
 
 }
@@ -55,8 +58,9 @@ void BufferView::init() {
 void BufferView::setFilteredModel(QAbstractItemModel *model, BufferViewFilter::Modes mode, QStringList nets) {
   BufferViewFilter *filter = new BufferViewFilter(model, mode, nets);
   setModel(filter);
 void BufferView::setFilteredModel(QAbstractItemModel *model, BufferViewFilter::Modes mode, QStringList nets) {
   BufferViewFilter *filter = new BufferViewFilter(model, mode, nets);
   setModel(filter);
-  connect(this, SIGNAL(dragEnter()), filter, SLOT(enterDrag()));
-  connect(this, SIGNAL(dragLeave()), filter, SLOT(leaveDrag()));
+  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) {
 }
 
 void BufferView::setModel(QAbstractItemModel *model) {
@@ -64,6 +68,23 @@ void BufferView::setModel(QAbstractItemModel *model) {
   init();
 }
 
   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) {
 // dragEnterEvent and dragLeaveEvent are needed to keep track of the active
 // view when customizing them via drag and drop
 void BufferView::dragEnterEvent(QDragEnterEvent *event) {
@@ -75,6 +96,7 @@ void BufferView::dragLeaveEvent(QDragLeaveEvent *event) {
   emit dragLeave();
   QTreeView::dragLeaveEvent(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) {
 
 // ensure that newly inserted network nodes are expanded per default
 void BufferView::rowsInserted(const QModelIndex & parent, int start, int end) {
index 1cb0986..b7b923e 100644 (file)
@@ -38,15 +38,21 @@ public:
   void setModel(QAbstractItemModel *model);
   void setFilteredModel(QAbstractItemModel *model, BufferViewFilter::Modes mode, QStringList nets);
   
   void setModel(QAbstractItemModel *model);
   void setFilteredModel(QAbstractItemModel *model, BufferViewFilter::Modes mode, QStringList nets);
   
-  void dragEnterEvent(QDragEnterEvent *);
-  void dragLeaveEvent(QDragLeaveEvent *);
+  //void dragEnterEvent(QDragEnterEvent *);
+  //void dragLeaveEvent(QDragLeaveEvent *);
   
   
+public slots:
+  void select(const QModelIndex &);
+    
 signals:
 signals:
-  void dragEnter();
-  void dragLeave();
+  void eventDropped(QDropEvent *);
+  void selectionChanged(const QModelIndex &, QItemSelectionModel::SelectionFlags);
+  //void dragEnter();
+  //void dragLeave();
   
   
-  protected:
-    void rowsInserted (const QModelIndex & parent, int start, int end);
+protected:
+  void dropEvent(QDropEvent *);
+  void rowsInserted (const QModelIndex & parent, int start, int end);
 };
 
 
 };
 
 
index 57155ea..0e7fcab 100644 (file)
@@ -23,7 +23,7 @@
 /*****************************************
 * The Filter for the Tree View
 *****************************************/
 /*****************************************
 * The Filter for the Tree View
 *****************************************/
-BufferViewFilter::BufferViewFilter(QAbstractItemModel *model, Modes filtermode, QStringList nets, QObject *parent) : QSortFilterProxyModel(parent) {
+BufferViewFilter::BufferViewFilter(QAbstractItemModel *model, const Modes &filtermode, const QStringList &nets) : QSortFilterProxyModel(model) {
   setSourceModel(model);
   setSortRole(BufferTreeModel::BufferNameRole);
   setSortCaseSensitivity(Qt::CaseInsensitive);
   setSourceModel(model);
   setSortRole(BufferTreeModel::BufferNameRole);
   setSortCaseSensitivity(Qt::CaseInsensitive);
@@ -32,18 +32,22 @@ BufferViewFilter::BufferViewFilter(QAbstractItemModel *model, Modes filtermode,
   networks = nets;
   
   connect(model, SIGNAL(invalidateFilter()), this, SLOT(invalidateMe()));
   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 &)));
+  connect(model, SIGNAL(selectionChanged(const QModelIndex &)),
+          this, SLOT(select(const QModelIndex &)));
+  
+  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::invalidateMe() {
   invalidateFilter();
 }
 
-void BufferViewFilter::select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) {
-  emit updateSelection(mapFromSource(index), command);
+void BufferViewFilter::select(const QModelIndex &index) {
+  emit selectionChanged(mapFromSource(index));
 }
 
 void BufferViewFilter::changeCurrent(const QModelIndex &current, const QModelIndex &previous) {
 }
 
 void BufferViewFilter::changeCurrent(const QModelIndex &current, const QModelIndex &previous) {
@@ -54,6 +58,7 @@ void BufferViewFilter::doubleClickReceived(const QModelIndex &clicked) {
   emit doubleClicked(mapToSource(clicked));
 }
 
   emit doubleClicked(mapToSource(clicked));
 }
 
+/*
 void BufferViewFilter::enterDrag() {
   connect(sourceModel(), SIGNAL(addBuffer(const uint &, const QString &)),
           this, SLOT(addBuffer(const uint &, const QString &)));
 void BufferViewFilter::enterDrag() {
   connect(sourceModel(), SIGNAL(addBuffer(const uint &, const QString &)),
           this, SLOT(addBuffer(const uint &, const QString &)));
@@ -63,6 +68,21 @@ void BufferViewFilter::leaveDrag() {
   disconnect(sourceModel(), SIGNAL(addBuffer(const uint &, const QString &)),
              this, SLOT(addBuffer(const uint &, const QString &)));
 }
   disconnect(sourceModel(), SIGNAL(addBuffer(const uint &, const QString &)),
              this, SLOT(addBuffer(const uint &, const QString &)));
 }
+*/
+
+void BufferViewFilter::dropEvent(QDropEvent *event) {
+  const QMimeData *data = event->mimeData();
+  if(!(data->hasFormat("application/Quassel/BufferItem/row")
+       && data->hasFormat("application/Quassel/BufferItem/network")
+       && data->hasFormat("application/Quassel/BufferItem/bufferId")))
+    return; // whatever the drop is... it's not a buffer...
+  
+  event->accept();
+  uint bufferid = data->data("application/Quassel/BufferItem/bufferId").toUInt();
+  QString network = QString::fromUtf8(data->data("application/Quassel/BufferItem/network"));
+  addBuffer(bufferid, network);
+}
+
 
 void BufferViewFilter::addBuffer(const uint &bufferuid, const QString &network) {
   if(!networks.contains(network)) {
 
 void BufferViewFilter::addBuffer(const uint &bufferuid, const QString &network) {
   if(!networks.contains(network)) {
index cd93a22..e5082b4 100644 (file)
@@ -22,6 +22,7 @@
 #define _BUFFERVIEWFILTER_H_
 
 #include <QFlags>
 #define _BUFFERVIEWFILTER_H_
 
 #include <QFlags>
+#include <QDropEvent>
 #include <QSortFilterProxyModel>
 #include "buffer.h"
 #include "buffertreemodel.h"
 #include <QSortFilterProxyModel>
 #include "buffer.h"
 #include "buffertreemodel.h"
@@ -45,28 +46,29 @@ public:
   };
   Q_DECLARE_FLAGS(Modes, Mode)
 
   };
   Q_DECLARE_FLAGS(Modes, Mode)
 
-  BufferViewFilter(QAbstractItemModel *model, Modes mode, QStringList nets, QObject *parent = 0);
+  BufferViewFilter(QAbstractItemModel *model, const Modes &mode, const QStringList &nets);
   
 public slots:
   void invalidateMe();
   void changeCurrent(const QModelIndex &, const QModelIndex &);
   void doubleClickReceived(const QModelIndex &);
   
 public slots:
   void invalidateMe();
   void changeCurrent(const QModelIndex &, const QModelIndex &);
   void doubleClickReceived(const QModelIndex &);
-  void select(const QModelIndex &, QItemSelectionModel::SelectionFlags);
-  void enterDrag();
-  void leaveDrag();
-  void addBuffer(const uint &, const QString &);
+  void select(const QModelIndex &);
+  //void enterDrag();
+  //void leaveDrag();
+  void dropEvent(QDropEvent *);
   
 signals:
   void currentChanged(const QModelIndex &, const QModelIndex &);
   void doubleClicked(const QModelIndex &);
   
 signals:
   void currentChanged(const QModelIndex &, const QModelIndex &);
   void doubleClicked(const QModelIndex &);
-  void updateSelection(const QModelIndex &, QItemSelectionModel::SelectionFlags);
+  void selectionChanged(const QModelIndex &);
   
 private:
   bool filterAcceptBuffer(const QModelIndex &) const;
   bool filterAcceptNetwork(const QModelIndex &) const;
   bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
   bool lessThan(const QModelIndex &, const QModelIndex &);
   
 private:
   bool filterAcceptBuffer(const QModelIndex &) const;
   bool filterAcceptNetwork(const QModelIndex &) const;
   bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
   bool lessThan(const QModelIndex &, const QModelIndex &);
-
+  void addBuffer(const uint &, const QString &);
+  
   Modes mode;
   QStringList networks;
   QList<uint> customBuffers;
   Modes mode;
   QStringList networks;
   QList<uint> customBuffers;
index 10b921e..23d0df2 100644 (file)
@@ -35,7 +35,7 @@ QSize BufferViewWidget::sizeHint() const {
 /*****************************************
  * Dock and API for the BufferViews
  *****************************************/
 /*****************************************
  * Dock and API for the BufferViews
  *****************************************/
-BufferViewDock::BufferViewDock(QAbstractItemModel *model, QString viewname, BufferViewFilter::Modes mode, QStringList nets, QWidget *parent) : QDockWidget(parent) {
+BufferViewDock::BufferViewDock(QAbstractItemModel *model, const QString &viewname, const BufferViewFilter::Modes &mode, const QStringList &nets, QWidget *parent) : QDockWidget(parent) {
   setObjectName(QString("View-" + viewname)); // should be unique for mainwindow state!
   setWindowTitle(viewname);
 
   setObjectName(QString("View-" + viewname)); // should be unique for mainwindow state!
   setWindowTitle(viewname);
 
index e6e2116..ef56ba7 100644 (file)
@@ -52,7 +52,7 @@ class BufferViewDock : public QDockWidget {
   Q_OBJECT
 
 public:
   Q_OBJECT
 
 public:
-  BufferViewDock(QAbstractItemModel *model, QString name, BufferViewFilter::Modes mode, QStringList nets = QStringList(), QWidget *parent = 0);
+  BufferViewDock(QAbstractItemModel *model, const QString &name, const BufferViewFilter::Modes &mode, const QStringList &nets = QStringList(), QWidget *parent = 0);
 };
 
 
 };