Fixed Bug in ModelPropertyMapper where currentChanges where unnoticed cause the rowIn...
[quassel.git] / src / client / buffertreemodel.h
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by The Quassel Team                             *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                   *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #ifndef _BUFFERTREEMODEL_H_
22 #define _BUFFERTREEMODEL_H_
23
24 #include <QtCore>
25
26 #include "treemodel.h"
27 #include "buffer.h"
28
29 #include <QPointer>
30
31 #include <QItemSelectionModel>
32
33 class BufferInfo;
34
35 #include "selectionmodelsynchronizer.h"
36 #include "modelpropertymapper.h"
37 class MappedSelectionModel;
38 class QAbstractItemView;
39
40 /*****************************************
41  *  Fancy Buffer Items
42  *****************************************/
43 class BufferTreeItem : public TreeItem {
44   Q_OBJECT
45   
46 public:
47   BufferTreeItem(Buffer *, TreeItem *parent = 0);
48
49   virtual uint id() const;
50   QVariant data(int column, int role) const;
51   virtual Qt::ItemFlags flags() const;
52   
53   Buffer *buffer() const { return buf; }
54   void setActivity(const Buffer::ActivityLevel &);
55   
56 private:
57   QString text(int column) const;
58   QColor foreground(int column) const;
59   
60   Buffer *buf;
61   Buffer::ActivityLevel activity;
62 };
63
64 /*****************************************
65  *  Network Items
66  *****************************************/
67 class NetworkTreeItem : public TreeItem {
68   Q_OBJECT
69   
70 public:
71   NetworkTreeItem(const QString &, TreeItem *parent = 0);
72
73   virtual uint id() const;
74   virtual Qt::ItemFlags flags() const;
75   
76 private:
77   QString net;
78   
79 };
80
81 /*****************************************
82  * BufferTreeModel
83  *****************************************/
84 class BufferTreeModel : public TreeModel {
85   Q_OBJECT
86   
87 public:
88   enum myRoles {
89     BufferTypeRole = Qt::UserRole,
90     BufferActiveRole,
91     BufferNameRole,
92     BufferUidRole
93   };
94   
95   BufferTreeModel(QObject *parent = 0);
96   static QList<QVariant> defaultHeader();
97
98   inline SelectionModelSynchronizer *selectionModelSynchronizer() { return _selectionModelSynchronizer; }
99   inline ModelPropertyMapper *propertyMapper() { return _propertyMapper; }
100
101   void synchronizeSelectionModel(MappedSelectionModel *selectionModel);
102   void synchronizeView(QAbstractItemView *view);
103   void mapProperty(int column, int role, QObject *target, const QByteArray &property);
104
105 public slots:
106   void bufferUpdated(Buffer *);
107   void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command);
108   void selectBuffer(Buffer *buffer);
109   void bufferActivity(Buffer::ActivityLevel, Buffer *buffer);
110   
111 signals:
112   void bufferSelected(Buffer *);
113   void invalidateFilter();
114   void selectionChanged(const QModelIndex &);
115     
116 private:
117   bool isBufferIndex(const QModelIndex &) const;
118   Buffer *getBufferByIndex(const QModelIndex &) const;
119   QModelIndex getOrCreateNetworkItemIndex(Buffer *buffer);
120   QModelIndex getOrCreateBufferItemIndex(Buffer *buffer);
121
122   QStringList mimeTypes() const;
123   QMimeData *mimeData(const QModelIndexList &) const;
124   bool dropMimeData(const QMimeData *, Qt::DropAction, int, int, const QModelIndex &);
125
126   QPointer<SelectionModelSynchronizer> _selectionModelSynchronizer;
127   QPointer<ModelPropertyMapper> _propertyMapper;
128   Buffer *currentBuffer;
129 };
130
131 #endif