From: Marcus Eggenberger Date: Tue, 8 Jan 2008 19:29:30 +0000 (+0000) Subject: We now have back a real BufferModel. It's basically a ProxyModel to X-Git-Tag: 0.2.0-alpha1~240 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=2f05c5d7e94d5e96d2b4bae59140fd3b60a7a62f We now have back a real BufferModel. It's basically a ProxyModel to the recently introduced NetworkModel. Activity displays in the BufferViews are now a bit crippled (new Activity levels will be shown even when the buffer is selected). Now We can Use The Nickviews with the NetworkModel and get Rid of the QtGui Dependency in the Client. --- diff --git a/dev-notes/ROADMAP b/dev-notes/ROADMAP index f7e40972..10a2471d 100644 --- a/dev-notes/ROADMAP +++ b/dev-notes/ROADMAP @@ -6,22 +6,22 @@ Already Done: make signalproxy threadsafe utf-8 / encodings externalize SQL-queries, provide migration path... + Buffermodel Showstoppers: ============= WiP: settings dialog -> Sput serverlist, identities... -> Sput mode changes in serverhandler -> EgS - BUFFERMODEL -> EgS make wizard more intuitive (account data, two-step auth) -> Sput Open: network settings in DB -> ? - switch to network-IDs -> ? + switch to network-IDs (depends on network settings into db) -> ? remove buffergroups (DB) -> ? insert buffertype field rein (DB) -> ? core-user admin, rights management (ACL) -> Sput? -BUG: multi-user join -> ? +BUG: multi-user join (should be done while switching to network-IDs) -> ? Important: ========== @@ -29,3 +29,5 @@ WiP: shortcuts -> Sput Open: save activity-state in core (client reconnect) -- save per-buffer timestamp locally in client -> ? backlog administration -> ? + fix Activity and get rid of QtGui dep in client + diff --git a/src/client/buffermodel.cpp b/src/client/buffermodel.cpp new file mode 100644 index 00000000..df5d99ff --- /dev/null +++ b/src/client/buffermodel.cpp @@ -0,0 +1,95 @@ +/*************************************************************************** + * Copyright (C) 2005-08 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "buffermodel.h" + +#include "networkmodel.h" +#include "mappedselectionmodel.h" +#include "buffer.h" +#include + +BufferModel::BufferModel(NetworkModel *parent) + : QSortFilterProxyModel(parent), + _selectionModelSynchronizer(new SelectionModelSynchronizer(this)), + _propertyMapper(new ModelPropertyMapper(this)) +{ + setSourceModel(parent); + + // initialize the Property Mapper + _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))); +} + +BufferModel::~BufferModel() { +} + +bool BufferModel::filterAcceptsRow(int sourceRow, const QModelIndex &parent) const { + Q_UNUSED(sourceRow) + + if(parent.data(NetworkModel::ItemTypeRole) == NetworkModel::BufferItemType) + return false; + else + return true; +} + +void BufferModel::synchronizeSelectionModel(MappedSelectionModel *selectionModel) { + selectionModelSynchronizer()->addSelectionModel(selectionModel); +} + +void BufferModel::synchronizeView(QAbstractItemView *view) { + MappedSelectionModel *mappedSelectionModel = new MappedSelectionModel(view->model()); + selectionModelSynchronizer()->addSelectionModel(mappedSelectionModel); + Q_ASSERT(mappedSelectionModel); + delete view->selectionModel(); + view->setSelectionModel(mappedSelectionModel); +} + +void BufferModel::mapProperty(int column, int role, QObject *target, const QByteArray &property) { + propertyMapper()->addMapping(column, role, target, property); +} + +// This Slot indicates that the user has selected a different buffer in the gui +void BufferModel::setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) { + Q_UNUSED(command) + Buffer *newCurrentBuffer; + NetworkModel *networkModel = qobject_cast(parent()); + if(networkModel->isBufferIndex(mapToSource(index)) && currentBuffer != (newCurrentBuffer = networkModel->getBufferByIndex(mapToSource(index)))) { + currentBuffer = newCurrentBuffer; + networkModel->bufferActivity(Buffer::NoActivity, currentBuffer); + emit bufferSelected(currentBuffer); + emit selectionChanged(index); + } +} + +void BufferModel::selectBuffer(Buffer *buffer) { + QModelIndex index = (qobject_cast(parent()))->bufferIndex(buffer->bufferInfo()); + if(!index.isValid()) { + qWarning() << "BufferModel::selectBuffer(): unknown Buffer has been selected."; + return; + } + // SUPER UGLY! + setCurrentIndex(mapFromSource(index), 0); +} diff --git a/src/client/buffermodel.h b/src/client/buffermodel.h new file mode 100644 index 00000000..4fb610db --- /dev/null +++ b/src/client/buffermodel.h @@ -0,0 +1,67 @@ +/*************************************************************************** + * Copyright (C) 2005-08 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef BUFFERMODEL_H +#define BUFFERMODEL_H + +#include +#include +#include + +class NetworkModel; +//class SelectionModelSynchronizer; +#include "selectionmodelsynchronizer.h" +//class ModelPropertyMapper; +#include "modelpropertymapper.h" +class MappedSelectionModel; +class QAbstractItemView; +class Buffer; + +class BufferModel : public QSortFilterProxyModel { + Q_OBJECT + +public: + BufferModel(NetworkModel *parent = 0); + virtual ~BufferModel(); + + bool filterAcceptsRow(int sourceRow, const QModelIndex &parent) const; + + inline SelectionModelSynchronizer *selectionModelSynchronizer() { return _selectionModelSynchronizer; } + inline ModelPropertyMapper *propertyMapper() { return _propertyMapper; } + + void synchronizeSelectionModel(MappedSelectionModel *selectionModel); + void synchronizeView(QAbstractItemView *view); + void mapProperty(int column, int role, QObject *target, const QByteArray &property); + +public slots: + void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command); + void selectBuffer(Buffer *buffer); + +signals: + void bufferSelected(Buffer *); + void selectionChanged(const QModelIndex &); + +private: + QPointer _selectionModelSynchronizer; + QPointer _propertyMapper; + Buffer *currentBuffer; +}; + +#endif // BUFFERMODEL_H diff --git a/src/client/client.cpp b/src/client/client.cpp index 1b6e0bba..55fccf23 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -28,6 +28,7 @@ #include "message.h" #include "networkinfo.h" #include "networkmodel.h" +#include "buffermodel.h" #include "quasselui.h" #include "signalproxy.h" #include "util.h" @@ -52,27 +53,28 @@ void Client::init(AbstractUi *ui) { } Client::Client(QObject *parent) - : QObject(parent), + : QObject(parent), socket(0), _signalProxy(new SignalProxy(SignalProxy::Client, this)), mainUi(0), _networkModel(0), + _bufferModel(0), connectedToCore(false) { - } Client::~Client() { - } void Client::init() { blockSize = 0; _networkModel = new NetworkModel(this); + _bufferModel = new BufferModel(_networkModel); connect(this, SIGNAL(bufferSelected(Buffer *)), - _networkModel, SLOT(selectBuffer(Buffer *))); + _bufferModel, SLOT(selectBuffer(Buffer *))); + connect(this, SIGNAL(bufferUpdated(Buffer *)), _networkModel, SLOT(bufferUpdated(Buffer *))); connect(this, SIGNAL(bufferActivity(Buffer::ActivityLevel, Buffer *)), @@ -192,6 +194,11 @@ NetworkModel *Client::networkModel() { return instance()->_networkModel; } +BufferModel *Client::bufferModel() { + return instance()->_bufferModel; +} + + SignalProxy *Client::signalProxy() { return instance()->_signalProxy; } diff --git a/src/client/client.h b/src/client/client.h index 9a64526e..342f8d0f 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -37,6 +37,7 @@ class NetworkInfo; class AbstractUi; class AbstractUiMsg; class NetworkModel; +class BufferModel; class SignalProxy; class QTimer; @@ -82,6 +83,7 @@ public: static void removeIdentity(IdentityId id); static NetworkModel *networkModel(); + static BufferModel *bufferModel(); static SignalProxy *signalProxy(); static AbstractUiMsg *layoutMsg(const Message &); @@ -191,6 +193,7 @@ private: QPointer _signalProxy; QPointer mainUi; QPointer _networkModel; + QPointer _bufferModel; ClientMode clientMode; diff --git a/src/client/client.pri b/src/client/client.pri index 740f74e7..89088da1 100644 --- a/src/client/client.pri +++ b/src/client/client.pri @@ -1,6 +1,6 @@ DEPMOD = common QT_MOD = core network gui # gui is needed just for QColor... FIXME! -SRCS += buffer.cpp networkmodel.cpp client.cpp clientsettings.cpp mappedselectionmodel.cpp modelpropertymapper.cpp \ - nickmodel.cpp selectionmodelsynchronizer.cpp treemodel.cpp -HDRS += buffer.h networkmodel.h client.h clientsettings.h quasselui.h mappedselectionmodel.h modelpropertymapper.h \ - nickmodel.h selectionmodelsynchronizer.h treemodel.h +SRCS += buffer.cpp treemodel.cpp networkmodel.cpp buffermodel.cpp client.cpp clientsettings.cpp mappedselectionmodel.cpp modelpropertymapper.cpp \ + nickmodel.cpp selectionmodelsynchronizer.cpp +HDRS += buffer.h treemodel.h networkmodel.h buffermodel.h client.h clientsettings.h quasselui.h mappedselectionmodel.h modelpropertymapper.h \ + nickmodel.h selectionmodelsynchronizer.h diff --git a/src/client/mappedselectionmodel.cpp b/src/client/mappedselectionmodel.cpp index 2c73186f..f5b74709 100644 --- a/src/client/mappedselectionmodel.cpp +++ b/src/client/mappedselectionmodel.cpp @@ -56,21 +56,11 @@ QModelIndex MappedSelectionModel::mapFromSource(const QModelIndex &sourceIndex) return sourceIndex; } -QItemSelection MappedSelectionModel::mapFromSource(const QItemSelection &sourceSelection) { - if(isProxyModel()) { - QItemSelection mappedSelection; - foreach(QItemSelectionRange range, sourceSelection) { - QModelIndex topleft = mapFromSource(range.topLeft()); - QModelIndex bottomright = mapFromSource(range.bottomRight()); - if(topleft.isValid() && bottomright.isValid()) - mappedSelection << QItemSelectionRange(topleft, bottomright); - else - Q_ASSERT(!topleft.isValid() && !bottomright.isValid()); - } - return mappedSelection; - } else { +QItemSelection MappedSelectionModel::mapSelectionFromSource(const QItemSelection &sourceSelection) { + if(isProxyModel()) + return proxyModel()->mapSelectionFromSource(sourceSelection); + else return sourceSelection; - } } QModelIndex MappedSelectionModel::mapToSource(const QModelIndex &proxyIndex) { @@ -80,16 +70,11 @@ QModelIndex MappedSelectionModel::mapToSource(const QModelIndex &proxyIndex) { return proxyIndex; } -QItemSelection MappedSelectionModel::mapToSource(const QItemSelection &proxySelection) { - if(isProxyModel()) { - QItemSelection mappedSelection; - foreach(QItemSelectionRange range, proxySelection) { - mappedSelection << QItemSelectionRange(mapToSource(range.topLeft()), mapToSource(range.bottomRight())); - } - return mappedSelection; - } else { +QItemSelection MappedSelectionModel::mapSelectionToSource(const QItemSelection &proxySelection) { + if(isProxyModel()) + return proxyModel()->mapSelectionToSource(proxySelection); + else return proxySelection; - } } void MappedSelectionModel::mappedSelect(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) { @@ -99,7 +84,7 @@ void MappedSelectionModel::mappedSelect(const QModelIndex &index, QItemSelection } void MappedSelectionModel::mappedSelect(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command) { - QItemSelection mappedSelection = mapFromSource(selection); + QItemSelection mappedSelection = mapSelectionFromSource(selection); if(mappedSelection != QItemSelectionModel::selection()) select(mappedSelection, command); } @@ -124,6 +109,6 @@ void MappedSelectionModel::_currentChanged(const QModelIndex ¤t, const QMo void MappedSelectionModel::_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) { Q_UNUSED(selected) Q_UNUSED(deselected) - emit mappedSelectionChanged(mapToSource(QItemSelectionModel::selection())); + emit mappedSelectionChanged(mapSelectionToSource(QItemSelectionModel::selection())); } diff --git a/src/client/mappedselectionmodel.h b/src/client/mappedselectionmodel.h index 01ccb4b2..a59ea253 100644 --- a/src/client/mappedselectionmodel.h +++ b/src/client/mappedselectionmodel.h @@ -41,10 +41,10 @@ public: const QAbstractProxyModel *proxyModel() const; QModelIndex mapFromSource(const QModelIndex &sourceIndex); - QItemSelection mapFromSource(const QItemSelection &sourceSelection); + QItemSelection mapSelectionFromSource(const QItemSelection &sourceSelection); QModelIndex mapToSource(const QModelIndex &proxyIndex); - QItemSelection mapToSource(const QItemSelection &proxySelection); + QItemSelection mapSelectionToSource(const QItemSelection &proxySelection); public slots: void mappedSelect(const QModelIndex &index, QItemSelectionModel::SelectionFlags command); diff --git a/src/client/networkmodel.cpp b/src/client/networkmodel.cpp index 85cc23d6..4bad7a0e 100644 --- a/src/client/networkmodel.cpp +++ b/src/client/networkmodel.cpp @@ -22,7 +22,6 @@ #include "networkmodel.h" -#include "mappedselectionmodel.h" #include #include "bufferinfo.h" @@ -128,8 +127,8 @@ void BufferItem::setTopic(const QString &topic) { } void BufferItem::join(IrcUser *ircUser) { -// emit newChild(new IrcUserItem(ircUser, this)); -// emit dataChanged(2); + emit newChild(new IrcUserItem(ircUser, this)); + emit dataChanged(2); } void BufferItem::part(IrcUser *ircUser) { @@ -262,19 +261,8 @@ void IrcUserItem::ircUserDestroyed() { * NetworkModel *****************************************/ NetworkModel::NetworkModel(QObject *parent) - : TreeModel(NetworkModel::defaultHeader(), parent), - _selectionModelSynchronizer(new SelectionModelSynchronizer(this)), - _propertyMapper(new ModelPropertyMapper(this)) + : TreeModel(NetworkModel::defaultHeader(), parent) { - // initialize the Property Mapper - _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))); } QListNetworkModel::defaultHeader() { @@ -283,22 +271,6 @@ QListNetworkModel::defaultHeader() { return data; } -void NetworkModel::synchronizeSelectionModel(MappedSelectionModel *selectionModel) { - selectionModelSynchronizer()->addSelectionModel(selectionModel); -} - -void NetworkModel::synchronizeView(QAbstractItemView *view) { - MappedSelectionModel *mappedSelectionModel = new MappedSelectionModel(view->model()); - selectionModelSynchronizer()->addSelectionModel(mappedSelectionModel); - Q_ASSERT(mappedSelectionModel); - delete view->selectionModel(); - view->setSelectionModel(mappedSelectionModel); -} - -void NetworkModel::mapProperty(int column, int role, QObject *target, const QByteArray &property) { - propertyMapper()->addMapping(column, role, target, property); -} - bool NetworkModel::isBufferIndex(const QModelIndex &index) const { return index.data(NetworkModel::ItemTypeRole) == NetworkModel::BufferItemType; } @@ -469,38 +441,13 @@ void NetworkModel::bufferUpdated(Buffer *buffer) { emit dataChanged(itemindex, itemindex); } -// This Slot indicates that the user has selected a different buffer in the gui -void NetworkModel::setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) { - Q_UNUSED(command) - Buffer *newCurrentBuffer; - if(isBufferIndex(index) && currentBuffer != (newCurrentBuffer = getBufferByIndex(index))) { - currentBuffer = newCurrentBuffer; - bufferActivity(Buffer::NoActivity, currentBuffer); - emit bufferSelected(currentBuffer); - emit selectionChanged(index); - } -} - void NetworkModel::bufferActivity(Buffer::ActivityLevel level, Buffer *buf) { BufferItem *bufferItem = buffer(buf->bufferInfo()); if(!bufferItem) { qWarning() << "NetworkModel::bufferActivity(): received Activity Info for uknown Buffer"; return; } - - if(buf != currentBuffer) - bufferItem->setActivity(level); - else - bufferItem->setActivity(Buffer::NoActivity); + bufferItem->setActivity(level); bufferUpdated(buf); } -void NetworkModel::selectBuffer(Buffer *buffer) { - QModelIndex index = bufferIndex(buffer->bufferInfo()); - if(!index.isValid()) { - qWarning() << "NetworkModel::selectBuffer(): unknown Buffer has been selected."; - return; - } - // SUPER UGLY! - setCurrentIndex(index, 0); -} diff --git a/src/client/networkmodel.h b/src/client/networkmodel.h index 0ed74877..3b6b3312 100644 --- a/src/client/networkmodel.h +++ b/src/client/networkmodel.h @@ -28,8 +28,6 @@ #include -#include - class BufferInfo; #include "selectionmodelsynchronizer.h" @@ -159,13 +157,6 @@ public: NetworkModel(QObject *parent = 0); static QList defaultHeader(); - inline SelectionModelSynchronizer *selectionModelSynchronizer() { return _selectionModelSynchronizer; } - inline ModelPropertyMapper *propertyMapper() { return _propertyMapper; } - - void synchronizeSelectionModel(MappedSelectionModel *selectionModel); - void synchronizeView(QAbstractItemView *view); - void mapProperty(int column, int role, QObject *target, const QByteArray &property); - static bool mimeContainsBufferList(const QMimeData *mimeData); static QList< QPair > mimeDataToBufferList(const QMimeData *mimeData); @@ -174,32 +165,23 @@ public: virtual bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &); void attachNetworkInfo(NetworkInfo *networkInfo); - + + bool isBufferIndex(const QModelIndex &) const; + Buffer *getBufferByIndex(const QModelIndex &) const; + QModelIndex bufferIndex(BufferInfo bufferInfo); + public slots: void bufferUpdated(Buffer *); - void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command); - void selectBuffer(Buffer *buffer); void bufferActivity(Buffer::ActivityLevel, Buffer *buffer); -signals: - void bufferSelected(Buffer *); - void selectionChanged(const QModelIndex &); - private: - bool isBufferIndex(const QModelIndex &) const; - Buffer *getBufferByIndex(const QModelIndex &) const; - QModelIndex networkIndex(uint networkId); NetworkItem *network(uint networkId); NetworkItem *newNetwork(uint networkId, const QString &networkName); - QModelIndex bufferIndex(BufferInfo bufferInfo); BufferItem *buffer(BufferInfo bufferInfo); BufferItem *newBuffer(BufferInfo bufferInfo); - QPointer _selectionModelSynchronizer; - QPointer _propertyMapper; - Buffer *currentBuffer; }; #endif // NETWORKMODEL_H diff --git a/src/client/selectionmodelsynchronizer.cpp b/src/client/selectionmodelsynchronizer.cpp index bdb2ccf0..ef0b9478 100644 --- a/src/client/selectionmodelsynchronizer.cpp +++ b/src/client/selectionmodelsynchronizer.cpp @@ -36,6 +36,11 @@ SelectionModelSynchronizer::~SelectionModelSynchronizer() { } void SelectionModelSynchronizer::addSelectionModel(MappedSelectionModel *selectionmodel) { + if(selectionmodel->model() == model()) { + addRegularSelectionModel(selectionmodel); + return; + } + if(selectionmodel->baseModel() != model()) { qWarning() << "cannot Syncronize SelectionModel" << selectionmodel << "which has a different baseModel()"; return; @@ -50,6 +55,22 @@ void SelectionModelSynchronizer::addSelectionModel(MappedSelectionModel *selecti selectionmodel, SLOT(mappedSetCurrentIndex(QModelIndex, QItemSelectionModel::SelectionFlags))); connect(this, SIGNAL(select(QItemSelection, QItemSelectionModel::SelectionFlags)), selectionmodel, SLOT(mappedSelect(QItemSelection, QItemSelectionModel::SelectionFlags))); +} + +void SelectionModelSynchronizer::addRegularSelectionModel(QItemSelectionModel *selectionmodel) { + if(selectionmodel->model() != model()) { + qWarning() << "cannot Syncronize QItemSelectionModel" << selectionmodel << "which has a different model()"; + return; + } + connect(selectionmodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)), + this, SLOT(_regularCurrentChanged(QModelIndex, QModelIndex))); + connect(selectionmodel, SIGNAL(selectionChanged(QItemSelection, QItemSelection)), + this, SLOT(_regularSelectionChanged(QItemSelection, QItemSelection))); + + connect(this, SIGNAL(setCurrentIndex(QModelIndex, QItemSelectionModel::SelectionFlags)), + selectionmodel, SLOT(setCurrentIndex(QModelIndex, QItemSelectionModel::SelectionFlags))); + connect(this, SIGNAL(select(QItemSelection, QItemSelectionModel::SelectionFlags)), + selectionmodel, SLOT(select(QItemSelection, QItemSelectionModel::SelectionFlags))); } @@ -65,3 +86,15 @@ void SelectionModelSynchronizer::_mappedCurrentChanged(const QModelIndex ¤ void SelectionModelSynchronizer::_mappedSelectionChanged(const QItemSelection &selected) { emit select(selected, QItemSelectionModel::ClearAndSelect); } + +void SelectionModelSynchronizer::_regularCurrentChanged(const QModelIndex &newCurrent, const QModelIndex &oldCurrent) { + Q_UNUSED(oldCurrent) + emit setCurrentIndex(newCurrent, QItemSelectionModel::ClearAndSelect); +} + +void SelectionModelSynchronizer::_regularSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected) { + Q_UNUSED(selected) + Q_UNUSED(deselected) + QItemSelectionModel *selectionModel = qobject_cast(sender()); + emit select(selectionModel->selection(), QItemSelectionModel::ClearAndSelect); +} diff --git a/src/client/selectionmodelsynchronizer.h b/src/client/selectionmodelsynchronizer.h index a6551473..5cda9cce 100644 --- a/src/client/selectionmodelsynchronizer.h +++ b/src/client/selectionmodelsynchronizer.h @@ -35,6 +35,7 @@ public: virtual ~SelectionModelSynchronizer(); void addSelectionModel(MappedSelectionModel *model); + void addRegularSelectionModel(QItemSelectionModel *model); void removeSelectionModel(MappedSelectionModel *model); inline QAbstractItemModel *model() { return _model; } @@ -43,6 +44,9 @@ private slots: void _mappedCurrentChanged(const QModelIndex ¤t); void _mappedSelectionChanged(const QItemSelection &selected); + void _regularCurrentChanged(const QModelIndex &newCurrent, const QModelIndex &oldCurrent); + void _regularSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected); + signals: void select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command); void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command); diff --git a/src/core/abstractsqlstorage.cpp b/src/core/abstractsqlstorage.cpp index b29c88cf..47442705 100644 --- a/src/core/abstractsqlstorage.cpp +++ b/src/core/abstractsqlstorage.cpp @@ -30,6 +30,12 @@ AbstractSqlStorage::AbstractSqlStorage(QObject *parent) } AbstractSqlStorage::~AbstractSqlStorage() { + QHash, QSqlQuery *>::iterator iter = _queryCache.begin(); + while(iter != _queryCache.end()) { + delete *iter; + iter = _queryCache.erase(iter); + } + { QSqlDatabase db = QSqlDatabase::database("quassel_connection"); db.commit(); @@ -126,7 +132,6 @@ QSqlQuery *AbstractSqlStorage::cachedQuery(const QString &queryName, int version query->prepare(queryString(queryName, version)); _queryCache[queryId] = query; } - return _queryCache[queryId]; } diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index d7c3bbac..0feeb63e 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -25,6 +25,7 @@ #include "client.h" #include "coreconnectdlg.h" #include "networkmodel.h" +#include "buffermodel.h" #include "nicklistwidget.h" #include "serverlist.h" #include "settingsdlg.h" @@ -117,7 +118,7 @@ void MainWin::init() { TopicWidget *topicwidget = new TopicWidget(dock); dock->setWidget(topicwidget); - Client::networkModel()->mapProperty(1, Qt::DisplayRole, topicwidget, "topic"); + Client::bufferModel()->mapProperty(1, Qt::DisplayRole, topicwidget, "topic"); addDockWidget(Qt::TopDockWidgetArea, dock); @@ -159,7 +160,7 @@ void MainWin::setupMenus() { void MainWin::setupViews() { - NetworkModel *model = Client::networkModel(); + BufferModel *model = Client::bufferModel(); connect(model, SIGNAL(bufferSelected(Buffer *)), this, SLOT(showBuffer(Buffer *))); addBufferView(tr("All Buffers"), model, BufferViewFilter::AllNets, QList()); @@ -167,6 +168,18 @@ void MainWin::setupViews() { addBufferView(tr("All Queries"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoServers, QList()); addBufferView(tr("All Networks"), model, BufferViewFilter::AllNets|BufferViewFilter::NoChannels|BufferViewFilter::NoQueries, QList()); addBufferView(tr("Full Custom"), model, BufferViewFilter::FullCustom, QList()); + +// QDockWidget *dock = new QDockWidget("FILTERTEST", this); +// dock->setAllowedAreas(Qt::RightDockWidgetArea|Qt::LeftDockWidgetArea); +// BufferView *view = new BufferView(dock); +// view->setModel(Client::bufferModel()); +// dock->setWidget(view); + +// addDockWidget(Qt::LeftDockWidgetArea, dock); +// ui.menuViews->addAction(dock->toggleViewAction()); + +// netViews.append(dock); + ui.menuViews->addSeparator(); } @@ -180,7 +193,7 @@ void MainWin::addBufferView(const QString &viewname, QAbstractItemModel *model, //create the view and initialize it's filter BufferView *view = new BufferView(dock); view->setFilteredModel(model, mode, nets); - Client::networkModel()->synchronizeView(view); + Client::bufferModel()->synchronizeView(view); dock->setWidget(view); addDockWidget(Qt::LeftDockWidgetArea, dock);