From a5c0b0735d9a448be2556dfe5dc8e89bb4176cd7 Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Fri, 22 Jun 2007 19:39:41 +0000 Subject: [PATCH 1/1] some minor tweaks --- src/client/buffertreemodel.cpp | 28 ++++++++++------------------ src/client/buffertreemodel.h | 5 +---- src/qtgui/bufferview.cpp | 30 ++++++++++++++++++++++++++---- src/qtgui/bufferview.h | 18 ++++++++++++------ src/qtgui/bufferviewfilter.cpp | 34 +++++++++++++++++++++++++++------- src/qtgui/bufferviewfilter.h | 16 +++++++++------- src/qtgui/bufferviewwidget.cpp | 2 +- src/qtgui/bufferviewwidget.h | 2 +- 8 files changed, 87 insertions(+), 48 deletions(-) diff --git a/src/client/buffertreemodel.cpp b/src/client/buffertreemodel.cpp index 43f624ea..3aac9f31 100644 --- a/src/client/buffertreemodel.cpp +++ b/src/client/buffertreemodel.cpp @@ -86,7 +86,8 @@ QVariant BufferTreeItem::data(int column, int role) const { * 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))); } QListBufferTreeModel::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")); - 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(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); + + 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; @@ -239,7 +232,7 @@ void BufferTreeModel::changeCurrent(const QModelIndex ¤t, const QModelInde 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())); } - } 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); - emit updateSelection(index, QItemSelectionModel::ClearAndSelect); + emit selectionChanged(index); } diff --git a/src/client/buffertreemodel.h b/src/client/buffertreemodel.h index f8490180..9916edd4 100644 --- a/src/client/buffertreemodel.h +++ b/src/client/buffertreemodel.h @@ -22,7 +22,6 @@ #define _BUFFERTREEMODEL_H_ #include -#include // FIXME Dependency on QtGui #include "treemodel.h" #include "buffer.h" @@ -63,7 +62,6 @@ public: BufferIdRole }; - //BufferTreeModel(const QList &, QObject *parent = 0); BufferTreeModel(QObject *parent = 0); static QList defaultHeader(); @@ -82,8 +80,7 @@ signals: 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; diff --git a/src/qtgui/bufferview.cpp b/src/qtgui/bufferview.cpp index 33eab930..0fae80d6 100644 --- a/src/qtgui/bufferview.cpp +++ b/src/qtgui/bufferview.cpp @@ -30,7 +30,7 @@ BufferView::BufferView(QWidget *parent) : QTreeView(parent) { void BufferView::init() { setIndentation(10); - //header()->hide(); + header()->hide(); header()->hideSection(1); expandAll(); @@ -47,7 +47,10 @@ void BufferView::init() { 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))); } @@ -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); - 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) { @@ -64,6 +68,23 @@ void BufferView::setModel(QAbstractItemModel *model) { init(); } +void BufferView::select(const QModelIndex ¤t) { + 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) { @@ -75,6 +96,7 @@ 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) { diff --git a/src/qtgui/bufferview.h b/src/qtgui/bufferview.h index 1cb09869..b7b923e1 100644 --- a/src/qtgui/bufferview.h +++ b/src/qtgui/bufferview.h @@ -38,15 +38,21 @@ public: 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: - 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); }; diff --git a/src/qtgui/bufferviewfilter.cpp b/src/qtgui/bufferviewfilter.cpp index 57155ea0..0e7fcab1 100644 --- a/src/qtgui/bufferviewfilter.cpp +++ b/src/qtgui/bufferviewfilter.cpp @@ -23,7 +23,7 @@ /***************************************** * 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); @@ -32,18 +32,22 @@ BufferViewFilter::BufferViewFilter(QAbstractItemModel *model, Modes 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 &))); + 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::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 ¤t, const QModelIndex &previous) { @@ -54,6 +58,7 @@ void BufferViewFilter::doubleClickReceived(const QModelIndex &clicked) { emit doubleClicked(mapToSource(clicked)); } +/* 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 &))); } +*/ + +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)) { diff --git a/src/qtgui/bufferviewfilter.h b/src/qtgui/bufferviewfilter.h index cd93a220..e5082b4f 100644 --- a/src/qtgui/bufferviewfilter.h +++ b/src/qtgui/bufferviewfilter.h @@ -22,6 +22,7 @@ #define _BUFFERVIEWFILTER_H_ #include +#include #include #include "buffer.h" #include "buffertreemodel.h" @@ -45,28 +46,29 @@ public: }; 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 &); - 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 &); - 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 &); - + void addBuffer(const uint &, const QString &); + Modes mode; QStringList networks; QList customBuffers; diff --git a/src/qtgui/bufferviewwidget.cpp b/src/qtgui/bufferviewwidget.cpp index 10b921e4..23d0df24 100644 --- a/src/qtgui/bufferviewwidget.cpp +++ b/src/qtgui/bufferviewwidget.cpp @@ -35,7 +35,7 @@ QSize BufferViewWidget::sizeHint() const { /***************************************** * 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); diff --git a/src/qtgui/bufferviewwidget.h b/src/qtgui/bufferviewwidget.h index e6e21164..ef56ba76 100644 --- a/src/qtgui/bufferviewwidget.h +++ b/src/qtgui/bufferviewwidget.h @@ -52,7 +52,7 @@ class BufferViewDock : public QDockWidget { 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); }; -- 2.20.1