* 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() {
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();
-
- 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;
currentBuffer = getBufferByIndex(current);
bufferActivity(Buffer::NoActivity, currentBuffer);
emit bufferSelected(currentBuffer);
- emit updateSelection(current, QItemSelectionModel::ClearAndSelect);
+ emit selectionChanged(current);
}
}
if(!buffer->isStatusBuffer())
emit fakeUserInput(buffer->bufferId(), QString("/join " + buffer->bufferName()));
}
-
}
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);
}
#define _BUFFERTREEMODEL_H_
#include <QtCore>
-#include <QItemSelectionModel> // FIXME Dependency on QtGui
#include "treemodel.h"
#include "buffer.h"
BufferIdRole
};
- //BufferTreeModel(const QList<QVariant> &, QObject *parent = 0);
BufferTreeModel(QObject *parent = 0);
static QList<QVariant> defaultHeader();
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;
void BufferView::init() {
setIndentation(10);
- //header()->hide();
+ header()->hide();
header()->hideSection(1);
expandAll();
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)));
}
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) {
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) {
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) {
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);
};
/*****************************************
* 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);
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) {
emit doubleClicked(mapToSource(clicked));
}
+/*
void BufferViewFilter::enterDrag() {
connect(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)) {
#define _BUFFERVIEWFILTER_H_
#include <QFlags>
+#include <QDropEvent>
#include <QSortFilterProxyModel>
#include "buffer.h"
#include "buffertreemodel.h"
};
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<uint> customBuffers;
/*****************************************
* 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);
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);
};