#include "buffertreemodel.h"
+#include "mappedselectionmodel.h"
+#include <QAbstractItemView>
+
#include "bufferinfo.h"
#include "client.h"
#include "signalproxy.h"
case BufferTreeModel::BufferNameRole:
return buf->bufferName();
case BufferTreeModel::BufferTypeRole:
- return buf->bufferType();
+ return int(buf->bufferType());
case BufferTreeModel::BufferActiveRole:
return buf->isActive();
- case BufferTreeModel::BufferInfoRole:
+ case BufferTreeModel::BufferUidRole:
return buf->bufferInfo().uid();
default:
return QVariant();
Qt::ItemFlags BufferTreeItem::flags() const {
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
- if(buf->bufferType() == Buffer::QueryBuffer)
+ if(buf->bufferType() == Buffer::QueryType)
flags |= Qt::ItemIsDropEnabled;
return flags;
* BufferTreeModel
*****************************************/
BufferTreeModel::BufferTreeModel(QObject *parent)
- : TreeModel(BufferTreeModel::defaultHeader(), parent)
+ : TreeModel(BufferTreeModel::defaultHeader(), parent),
+ _selectionModelSynchronizer(new SelectionModelSynchronizer(this)),
+ _propertyMapper(new ModelPropertyMapper(this))
{
- Client::signalProxy()->attachSignal(this, SIGNAL(fakeUserInput(BufferInfo, QString)), SIGNAL(sendInput(BufferInfo, QString)));
+ _propertyMapper->setModel(this);
+ delete _propertyMapper->selectionModel();
+ MappedSelectionModel *mappedSelectionModel = new MappedSelectionModel(this);
+ _propertyMapper->setSelectionModel(mappedSelectionModel);
+ synchronizeSelectionModel(mappedSelectionModel);
+
+ connect(_selectionModelSynchronizer, SIGNAL(setCurrentIndex(QModelIndex, QItemSelectionModel::SelectionFlags)),
+ this, SLOT(setCurrentIndex(QModelIndex, QItemSelectionModel::SelectionFlags)));
}
QList<QVariant >BufferTreeModel::defaultHeader() {
return data;
}
+void BufferTreeModel::synchronizeSelectionModel(MappedSelectionModel *selectionModel) {
+ selectionModelSynchronizer()->addSelectionModel(selectionModel);
+}
+
+void BufferTreeModel::synchronizeView(QAbstractItemView *view) {
+ MappedSelectionModel *mappedSelectionModel = new MappedSelectionModel(view->model());
+ selectionModelSynchronizer()->addSelectionModel(mappedSelectionModel);
+ Q_ASSERT(mappedSelectionModel);
+ delete view->selectionModel();
+ view->setSelectionModel(mappedSelectionModel);
+}
+
+void BufferTreeModel::mapProperty(int column, int role, QObject *target, const QByteArray &property) {
+ propertyMapper()->addMapping(column, role, target, property);
+}
+
bool BufferTreeModel::isBufferIndex(const QModelIndex &index) const {
// not so purdy...
return parent(index) != QModelIndex();
Buffer *sourceBuffer = static_cast<BufferTreeItem *>(rootItem->childById(qHash(network))->child(sourcerow))->buffer();
Buffer *targetBuffer = getBufferByIndex(parent);
- if(!(sourceBuffer->bufferType() & targetBuffer->bufferType() & Buffer::QueryBuffer)) // only queries can be merged
+ if(!(sourceBuffer->bufferType() & targetBuffer->bufferType() & Buffer::QueryType)) // only queries can be merged
return false;
if(sourceBuffer == targetBuffer) // we won't merge with ourself :)
}
// This Slot indicates that the user has selected a different buffer in the gui
-void BufferTreeModel::changeCurrent(const QModelIndex ¤t, const QModelIndex &/*previous*/) {
- if(isBufferIndex(current)) {
- currentBuffer = getBufferByIndex(current);
+void BufferTreeModel::setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) {
+ Q_UNUSED(command)
+ if(isBufferIndex(index)) {
+ currentBuffer = getBufferByIndex(index);
bufferActivity(Buffer::NoActivity, currentBuffer);
emit bufferSelected(currentBuffer);
- emit selectionChanged(current);
- }
-}
-
-// we received a double click on a buffer, so we're going to join it
-void BufferTreeModel::doubleClickReceived(const QModelIndex &clicked) {
- if(isBufferIndex(clicked)) {
- Buffer *buffer = getBufferByIndex(clicked);
- if(!buffer->isStatusBuffer())
- emit fakeUserInput(buffer->bufferInfo(), QString("/join " + buffer->bufferName()));
+ emit selectionChanged(index);
}
}
void BufferTreeModel::selectBuffer(Buffer *buffer) {
QModelIndex index = getOrCreateBufferItemIndex(buffer);
- //emit selectionChanged(index);
- changeCurrent(index, QModelIndex());
+ // SUPER UGLY!
+ setCurrentIndex(index, 0);
}