}
void TreeModel::debug_rowsAboutToBeInserted(const QModelIndex &parent, int start, int end) {
- // qDebug() << "debug_rowsAboutToBeInserted" << parent << parent.internalPointer() << parent.data().toString() << rowCount(parent) << start << end;
+ qDebug() << "debug_rowsAboutToBeInserted" << parent << parent.internalPointer() << parent.data().toString() << rowCount(parent) << start << end;
}
void TreeModel::debug_rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) {
}
void TreeModel::debug_rowsRemoved(const QModelIndex &parent, int start, int end) {
- // qDebug() << "debug_rowsRemoved" << parent << parent.internalPointer() << parent.data().toString() << rowCount(parent) << start << end;
+ qDebug() << "debug_rowsRemoved" << parent << parent.internalPointer() << parent.data().toString() << rowCount(parent) << start << end;
}
disconnect(_bufferModel, 0, this, 0);
}
_bufferModel = bufferModel;
- connect(bufferModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)),
- this, SLOT(rowsAboutToBeRemoved(QModelIndex, int, int)));
+
+ if(bufferModel) {
+ connect(bufferModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)),
+ this, SLOT(rowsAboutToBeRemoved(QModelIndex, int, int)));
+ }
}
void BufferWidget::setSelectionModel(QItemSelectionModel *selectionModel) {
disconnect(_selectionModel, 0, this, 0);
}
_selectionModel = selectionModel;
- connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
- this, SLOT(currentChanged(QModelIndex, QModelIndex)));
+
+ if(selectionModel) {
+ connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
+ this, SLOT(currentChanged(QModelIndex, QModelIndex)));
+ }
}
void BufferWidget::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) {
disconnectedFromCore(); // Disable menus and stuff
showCoreConnectionDlg(true); // autoconnect if appropriate
- // attach the BufferWidget to the PropertyMapper
+ // attach the BufferWidget to the BufferModel and the default selection
ui.bufferWidget->setModel(Client::bufferModel());
ui.bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
ui.menuViews->addAction(nickDock->toggleViewAction());
+ // attach the NickListWidget to the BufferModel and the default selection
+ nickListWidget->setModel(Client::bufferModel());
+ nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
+
Client::bufferModel()->mapProperty(0, NetworkModel::BufferIdRole, nickListWidget, "currentBuffer");
}
NickListWidget::NickListWidget(QWidget *parent)
: QWidget(parent),
- _currentBuffer(0)
+ _bufferModel(0),
+ _selectionModel(0)
{
ui.setupUi(this);
}
+void NickListWidget::setModel(BufferModel *bufferModel) {
+ if(_bufferModel) {
+ disconnect(_bufferModel, 0, this, 0);
+ }
+
+ _bufferModel = bufferModel;
+
+ if(bufferModel) {
+ connect(bufferModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)),
+ this, SLOT(rowsAboutToBeRemoved(QModelIndex, int, int)));
+ }
+}
+
+void NickListWidget::setSelectionModel(QItemSelectionModel *selectionModel) {
+ if(_selectionModel) {
+ disconnect(_selectionModel, 0, this, 0);
+ }
+
+ _selectionModel = selectionModel;
+
+ if(selectionModel) {
+ connect(selectionModel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
+ this, SLOT(currentChanged(QModelIndex, QModelIndex)));
+ }
+}
+
-BufferId NickListWidget::currentBuffer() const {
- return _currentBuffer;
+void NickListWidget::reset() {
+ NickView *nickView;
+ QHash<BufferId, NickView *>::iterator iter = nickViews.begin();
+ while(iter != nickViews.end()) {
+ nickView = *iter;
+ iter = nickViews.erase(iter);
+ ui.stackedWidget->removeWidget(nickView);
+ nickView->deleteLater();
+ }
+}
+
+
+void NickListWidget::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) {
+ Q_UNUSED(previous);
+ QVariant variant;
+
+ variant = current.data(NetworkModel::BufferIdRole);
+ if(!variant.isValid())
+ return;
+ setCurrentBuffer(variant.value<BufferId>());
}
+
void NickListWidget::setCurrentBuffer(BufferId bufferId) {
QModelIndex bufferIdx = Client::networkModel()->bufferIndex(bufferId);
ui.stackedWidget->setCurrentWidget(nickViews.value(bufferId));
} else {
NickView *view = new NickView(this);
- NickViewFilter *filter = new NickViewFilter(Client::networkModel());
+ NickViewFilter *filter = new NickViewFilter(bufferId, Client::networkModel());
+ filter->setObjectName("Buffer " + QString::number(bufferId.toInt()));
view->setModel(filter);
view->setRootIndex(filter->mapFromSource(bufferIdx));
+ view->expandAll();
nickViews[bufferId] = view;
ui.stackedWidget->addWidget(view);
ui.stackedWidget->setCurrentWidget(view);
}
}
-void NickListWidget::reset() {
- foreach(NickView *view, nickViews.values()) {
- ui.stackedWidget->removeWidget(view);
- view->deleteLater();
+
+void NickListWidget::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) {
+ Q_ASSERT(model());
+ if(!parent.isValid()) {
+ // ok this means that whole networks are about to be removed
+ // we can't determine which buffers are affect, so we hope that all nets are removed
+ // this is the most common case (for example disconnecting from the core or terminating the clint)
+ reset();
+ } else {
+ // check if there are explicitly buffers removed
+ for(int i = start; i <= end; i++) {
+ QVariant variant = parent.child(i,0).data(NetworkModel::BufferIdRole);
+ if(!variant.isValid())
+ continue;
+
+ BufferId bufferId = qVariantValue<BufferId>(variant);
+ removeBuffer(bufferId);
+ }
}
- nickViews.clear();
}
void NickListWidget::removeBuffer(BufferId bufferId) {
#include <QHash>
+#include <QPointer>
+#include <QItemSelectionModel>
+
+#include "buffermodel.h"
+
class Buffer;
class NickView;
class NickListWidget : public QWidget {
Q_OBJECT
- Q_PROPERTY(BufferId currentBuffer READ currentBuffer WRITE setCurrentBuffer); // FIXME BufferId
-
public:
NickListWidget(QWidget *parent = 0);
+ inline BufferModel *model() { return _bufferModel; }
+ void setModel(BufferModel *bufferModel);
+
+ inline QItemSelectionModel *selectionModel() const { return _selectionModel; }
+ void setSelectionModel(QItemSelectionModel *selectionModel);
+
public slots:
- BufferId currentBuffer() const;
- void setCurrentBuffer(BufferId bufferId);
void reset();
protected:
virtual QSize sizeHint() const;
+protected slots:
+// virtual void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint);
+// virtual void commitData(QWidget *editor);
+ virtual void currentChanged(const QModelIndex ¤t, const QModelIndex &previous);
+// virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
+// virtual void editorDestroyed(QObject *editor);
+ virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
+// virtual void rowsInserted(const QModelIndex &parent, int start, int end);
+// virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
+
private slots:
void removeBuffer(BufferId bufferId);
+ void setCurrentBuffer(BufferId bufferId);
private:
Ui::NickListWidget ui;
QHash<BufferId, NickView *> nickViews;
- BufferId _currentBuffer;
-
+
+ QPointer<BufferModel> _bufferModel;
+ QPointer<QItemSelectionModel> _selectionModel;
};
#endif
QSize BufferView::sizeHint() const {
+ return QSize(120, 50);
+
if(!model())
return QTreeView::sizeHint();
NickView::NickView(QWidget *parent)
- : QTreeView(parent)
+ : QTreeView(parent),
+ _sizeHint(QTreeView::sizeHint())
{
setIndentation(10);
setAnimated(true);
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)),
- this, SLOT(showContextMenu(const QPoint&)));
+ this, SLOT(showContextMenu(const QPoint&)));
connect(this, SIGNAL(activated( const QModelIndex& )),
this, SLOT(startQuery( const QModelIndex& )));
}
setColumnHidden(i, true);
expandAll();
+ updateSizeHint();
}
void NickView::setModel(QAbstractItemModel *model) {
init();
}
-void NickView::rowsInserted(const QModelIndex &index, int start, int end) {
- QTreeView::rowsInserted(index, start, end);
- expandAll(); // FIXME We need to do this more intelligently. Maybe a pimped TreeView?
+void NickView::rowsInserted(const QModelIndex &parent, int start, int end) {
+ QTreeView::rowsInserted(parent, start, end);
+ if(model()->data(parent, NetworkModel::ItemTypeRole) == NetworkModel::UserCategoryItemType && !isExpanded(parent))
+ expand(parent);
+ updateSizeHint();
+}
+
+void NickView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) {
+ QTreeView::rowsAboutToBeRemoved(parent, start, end);
+ updateSizeHint();
+}
+
+void NickView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) {
+ QTreeView::dataChanged(topLeft, bottomRight);
+ updateSizeHint();
}
QString NickView::nickFromModelIndex(const QModelIndex & index) {
Client::instance()->userInput(bufferInfo, command);
}
-QSize NickView::sizeHint() const {
+void NickView::updateSizeHint() {
if(!model())
- return QTreeView::sizeHint();
+ return;
int columnSize = 0;
for(int i = 0; i < model()->columnCount(); i++) {
columnSize += sizeHintForColumn(i);
}
- return QSize(columnSize, 50);
+ _sizeHint = QSize(columnSize, 50);
+}
+
+QSize NickView::sizeHint() const {
+ return _sizeHint;
}
class NickView : public QTreeView {
Q_OBJECT
- public:
- NickView(QWidget *parent = 0);
- virtual ~NickView();
+public:
+ NickView(QWidget *parent = 0);
+ virtual ~NickView();
- protected:
- virtual void rowsInserted(const QModelIndex &, int, int);
- virtual QSize sizeHint() const;
-
- public slots:
- void setModel(QAbstractItemModel *model);
- void init();
- void showContextMenu(const QPoint & pos);
- void startQuery(const QModelIndex & modelIndex);
-
- private:
- BufferInfo bufferInfoFromModelIndex(const QModelIndex & index);
- QString nickFromModelIndex(const QModelIndex & index);
- void executeCommand(const BufferInfo & bufferInfo, const QString & command);
+protected:
+ virtual void rowsInserted(const QModelIndex &parent, int start, int end);
+ virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
+ virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
+ virtual QSize sizeHint() const;
+public slots:
+ void setModel(QAbstractItemModel *model);
+ void init();
+ void showContextMenu(const QPoint & pos);
+ void startQuery(const QModelIndex & modelIndex);
+
+private:
+ QSize _sizeHint;
+
+ void updateSizeHint();
+ BufferInfo bufferInfoFromModelIndex(const QModelIndex & index);
+ QString nickFromModelIndex(const QModelIndex & index);
+ void executeCommand(const BufferInfo & bufferInfo, const QString & command);
+
};
/******************************************************************************************
* NickViewFilter
******************************************************************************************/
-NickViewFilter::NickViewFilter(NetworkModel *parent)
- : QSortFilterProxyModel(parent)
+NickViewFilter::NickViewFilter(const BufferId &bufferId, NetworkModel *parent)
+ : QSortFilterProxyModel(parent),
+ _bufferId(bufferId)
{
setSourceModel(parent);
setDynamicSortFilter(true);
return foreground(index);
else
return QSortFilterProxyModel::data(index, role);
+// else {
+// QVariant d =
+// if(role == 0)
+// qDebug() << index << role << d;
+// return d;
+// }
}
QVariant NickViewFilter::foreground(const QModelIndex &index) const {
// FIXME:: make colors configurable;
// FIXME: use the style interface instead of qsettings
}
+
+
+bool NickViewFilter::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const {
+ QModelIndex source_child = source_parent.child(source_row, 0);
+ return (sourceModel()->data(source_child, NetworkModel::BufferIdRole).value<BufferId>() == _bufferId);
+}
#define NICKVIEWFILTER_H
#include <QSortFilterProxyModel>
+#include "types.h"
class NetworkModel;
Q_OBJECT
public:
- NickViewFilter(NetworkModel *parent = 0);
+ NickViewFilter(const BufferId &bufferId, NetworkModel *parent = 0);
QVariant data(const QModelIndex &index, int role) const;
QVariant foreground(const QModelIndex &index) const;
+
+protected:
+ virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
+
+private:
+ BufferId _bufferId;
};
#endif
{ using namespace Global;
quasselVersion = "0.2.0-alpha3-pre";
- quasselDate = "2008-03-03";
- quasselBuild = 615;
+ quasselDate = "2008-03-06";
+ quasselBuild = 616;
//! Minimum client build number the core needs
clientBuildNeeded = 613;