}
int cat = index.internalId();
if(!cat) { // top-level item (category)
- if(role == Qt::DisplayRole) {
- QString title;
- switch(index.row()) {
- case 0: title = tr("%n Owner(s)", "", users[index.row()].count()); break;
- case 1: title = tr("%n Admin(s)", "", users[index.row()].count()); break;
- case 2: title = tr("%n Operator(s)", "", users[index.row()].count()); break;
- case 3: title = tr("%n Half-Op(s)", "", users[index.row()].count()); break;
- case 4: title = tr("%n Voiced", "", users[index.row()].count()); break;
- case 5: title = tr("%n User(s)", "", users[index.row()].count()); break;
- default:
- qDebug() << "invalid model index"; return QVariant();
+ switch(role) {
+ case Qt::DisplayRole: {
+ QString title;
+ switch(index.row()) {
+ case 0: title = tr("%n Owner(s)", "", users[index.row()].count()); break;
+ case 1: title = tr("%n Admin(s)", "", users[index.row()].count()); break;
+ case 2: title = tr("%n Operator(s)", "", users[index.row()].count()); break;
+ case 3: title = tr("%n Half-Op(s)", "", users[index.row()].count()); break;
+ case 4: title = tr("%n Voiced", "", users[index.row()].count()); break;
+ case 5: title = tr("%n User(s)", "", users[index.row()].count()); break;
+ default: qDebug() << "invalid model index"; return QVariant();
+ }
+ return title;
}
- return title;
- } else return QVariant();
+ case SortKeyRole: return index.row();
+ default: return QVariant();
+ }
} else {
IrcUser *user = users[cat-1][index.row()];
switch(role) {
case Qt::DisplayRole:
return user->nick();
+ case Qt::ToolTipRole:
+ return user->hostmask();
+ case SortKeyRole:
+ return user->nick();
default:
return QVariant();
}
}
}
+/******************************************************************************************
+ * FilteredNickModel
+ ******************************************************************************************/
+
+FilteredNickModel::FilteredNickModel(QObject *parent) : QSortFilterProxyModel(parent) {
+ setDynamicSortFilter(true);
+ setSortCaseSensitivity(Qt::CaseInsensitive);
+ setSortRole(NickModel::SortKeyRole);
+
+}
+
+// Hide empty categories
+bool FilteredNickModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const {
+ if(!source_parent.isValid()) {
+ QModelIndex index = sourceModel()->index(source_row, 0);
+ return sourceModel()->rowCount(index);
+ }
+ return true;
+}
#define _NICKMODEL_H_
#include <QAbstractItemModel>
+#include <QSortFilterProxyModel>
#include <QVector>
class IrcChannel;
* levels, where the top-level items are the categories (such as Ops, Voiced etc), and the second-level items
* the actual nicks/users. Several roles are provided to access information about a nick.
*
- * Note that the nicks are not sorted in any way. Use a QSortFilterProxyModel to do that instead.
+ * Note that the nicks are not sorted in any way. Use a FilteredNickModel instead.
*/
class NickModel : public QAbstractItemModel {
Q_OBJECT
public:
+ enum NickModelRole { SortKeyRole = Qt::UserRole };
+
NickModel(IrcChannel *channel = 0, QObject *parent = 0);
virtual ~NickModel();
};
+//! This ProxyModel can be used on top of a NickModel in order to provide a sorted nicklist and to hide unused categories.
+class FilteredNickModel : public QSortFilterProxyModel {
+ Q_OBJECT
+
+ public:
+ FilteredNickModel(QObject *parent = 0);
+
+ protected:
+ virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
+
+};
+
#endif
ui.actionDisconnectCore->setEnabled(true);
ui.actionNetworkList->setEnabled(true);
ui.bufferWidget->show();
+ statusBar()->showMessage(tr("Connected to core."));
}
void MainWin::disconnectedFromCore() {
ui.actionNetworkList->setEnabled(false);
ui.bufferWidget->hide();
ui.actionConnectCore->setEnabled(true);
- //qDebug() << "mainwin disconnected";
+ statusBar()->showMessage(tr("Not connected to core."));
}
AbstractUiMsg *MainWin::layoutMsg(const Message &msg) {
#include "nickview.h"
#include "nickmodel.h"
+#include <QHeaderView>
+#include <QSortFilterProxyModel>
NickView::NickView(QWidget *parent) : QTreeView(parent) {
setGeometry(0, 0, 30, 30);
//setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
+ setIndentation(10);
+ header()->hide();
+ header()->hideSection(1);
+ setAnimated(true);
+ setSortingEnabled(true);
+ sortByColumn(0, Qt::AscendingOrder);
+ filteredModel = new FilteredNickModel(this);
+ QTreeView::setModel(filteredModel);
}
NickView::~NickView() {
}
void NickView::setModel(NickModel *model) {
- QTreeView::setModel(model);
+ filteredModel->setSourceModel(model);
+ expandAll();
+
}