1 /***************************************************************************
2 * Copyright (C) 2005-07 by The Quassel Team *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "bufferview.h"
22 #include "bufferviewwidget.h"
24 /*****************************************
25 * The TreeView showing the Buffers
26 *****************************************/
27 BufferViewFilter::BufferViewFilter(QAbstractItemModel *model, Modes filtermode, QStringList nets, QObject *parent) : QSortFilterProxyModel(parent) {
28 setSourceModel(model);
32 connect(model, SIGNAL(invalidateFilter()), this, SLOT(invalidateMe()));
33 connect(model, SIGNAL(updateSelection(const QModelIndex &, QItemSelectionModel::SelectionFlags)), this, SLOT(select(const QModelIndex &, QItemSelectionModel::SelectionFlags)));
35 connect(this, SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), model, SLOT(changeCurrent(const QModelIndex &, const QModelIndex &)));
36 connect(this, SIGNAL(doubleClicked(const QModelIndex &)), model, SLOT(doubleClickReceived(const QModelIndex &)));
39 void BufferViewFilter::invalidateMe() {
43 void BufferViewFilter::select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command) {
44 emit updateSelection(mapFromSource(index), command);
47 void BufferViewFilter::changeCurrent(const QModelIndex ¤t, const QModelIndex &previous) {
48 emit currentChanged(mapToSource(current), mapToSource(previous));
51 void BufferViewFilter::doubleClickReceived(const QModelIndex &clicked) {
52 emit doubleClicked(mapToSource(clicked));
55 bool BufferViewFilter::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const {
56 QModelIndex child = source_parent.child(source_row, 0);
58 return true; // can't imagine this case but true sounds good :)
60 Buffer::Type bufferType = (Buffer::Type) child.data(BufferTreeModel::BufferTypeRole).toInt();
61 if((mode & NoChannels) && bufferType == Buffer::ChannelBuffer) return false;
62 if((mode & NoQueries) && bufferType == Buffer::QueryBuffer) return false;
63 if((mode & NoServers) && bufferType == Buffer::ServerBuffer) return false;
65 bool isActive = child.data(BufferTreeModel::BufferActiveRole).toBool();
66 if((mode & NoActive) && isActive) return false;
67 if((mode & NoInactive) && !isActive) return false;
69 QString net = child.data(Qt::DisplayRole).toString();
70 if((mode & SomeNets) && !networks.contains(net)) return false;
75 /*****************************************
76 * The TreeView showing the Buffers
77 *****************************************/
78 BufferView::BufferView(QWidget *parent) : QTreeView(parent) {
81 void BufferView::init() {
84 header()->hideSection(1);
88 setDropIndicatorShown(true);
90 connect(selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), model(), SLOT(changeCurrent(const QModelIndex &, const QModelIndex &)));
91 connect(this, SIGNAL(doubleClicked(const QModelIndex &)), model(), SLOT(doubleClickReceived(const QModelIndex &)));
92 connect(model(), SIGNAL(updateSelection(const QModelIndex &, QItemSelectionModel::SelectionFlags)), selectionModel(), SLOT(select(const QModelIndex &, QItemSelectionModel::SelectionFlags)));
95 void BufferView::setFilteredModel(QAbstractItemModel *model, BufferViewFilter::Modes mode, QStringList nets) {
96 BufferViewFilter *filter = new BufferViewFilter(model, mode, nets);
100 void BufferView::setModel(QAbstractItemModel *model) {
101 QTreeView::setModel(model);
105 void BufferView::dragEnterEvent(QDragEnterEvent *event) {
106 // not yet needed... this will be usefull to keep track of the active view when customizing them with drag and drop
107 QTreeView::dragEnterEvent(event);
110 void BufferView::rowsInserted(const QModelIndex & parent, int start, int end) {
111 if(parent.parent() == QModelIndex()) setExpanded(parent, true);