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"
23 /*****************************************
24 * The TreeView showing the Buffers
25 *****************************************/
26 // Please be carefull when reimplementing methods which are used to inform the view about changes to the data
27 // to be on the safe side: call QTreeView's method aswell
28 BufferView::BufferView(QWidget *parent) : QTreeView(parent) {
31 void BufferView::init() {
34 header()->hideSection(1);
39 setDropIndicatorShown(true);
41 setSortingEnabled(true);
42 sortByColumn(0, Qt::AscendingOrder);
44 connect(selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
45 model(), SLOT(changeCurrent(const QModelIndex &, const QModelIndex &)));
47 connect(this, SIGNAL(doubleClicked(const QModelIndex &)),
48 model(), SLOT(doubleClickReceived(const QModelIndex &)));
50 connect(model(), SIGNAL(selectionChanged(const QModelIndex &)),
51 this, SLOT(select(const QModelIndex &)));
53 connect(this, SIGNAL(selectionChanged(const QModelIndex &, QItemSelectionModel::SelectionFlags)),
54 selectionModel(), SLOT(select(const QModelIndex &, QItemSelectionModel::SelectionFlags)));
58 void BufferView::setFilteredModel(QAbstractItemModel *model, BufferViewFilter::Modes mode, QStringList nets) {
59 BufferViewFilter *filter = new BufferViewFilter(model, mode, nets);
61 connect(this, SIGNAL(eventDropped(QDropEvent *)), filter, SLOT(dropEvent(QDropEvent *)));
62 //connect(this, SIGNAL(dragEnter()), filter, SLOT(enterDrag()));
63 //connect(this, SIGNAL(dragLeave()), filter, SLOT(leaveDrag()));
66 void BufferView::setModel(QAbstractItemModel *model) {
67 QTreeView::setModel(model);
71 void BufferView::select(const QModelIndex ¤t) {
72 emit selectionChanged(current, QItemSelectionModel::ClearAndSelect);
75 void BufferView::dropEvent(QDropEvent *event) {
76 if(event->source() == this) {
77 // this is either a merge or a sort operation...
78 // currently only merges are supported
80 emit eventDropped(event);
82 QTreeView::dropEvent(event);
88 // dragEnterEvent and dragLeaveEvent are needed to keep track of the active
89 // view when customizing them via drag and drop
90 void BufferView::dragEnterEvent(QDragEnterEvent *event) {
92 QTreeView::dragEnterEvent(event);
95 void BufferView::dragLeaveEvent(QDragLeaveEvent *event) {
97 QTreeView::dragLeaveEvent(event);
101 // ensure that newly inserted network nodes are expanded per default
102 void BufferView::rowsInserted(const QModelIndex & parent, int start, int end) {
103 if(parent.parent() == QModelIndex()) setExpanded(parent, true);
104 QTreeView::rowsInserted(parent, start, end);