QGIS API Documentation  2.6.0-Brighton
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsbrowsermodel.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsbrowsermodel.h
3  ---------------------
4  begin : July 2011
5  copyright : (C) 2011 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #ifndef QGSBROWSERMODEL_H
16 #define QGSBROWSERMODEL_H
17 
18 #include <QAbstractItemModel>
19 #include <QIcon>
20 #include <QMimeData>
21 
22 #include "qgsdataitem.h"
23 
24 class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
25 {
26  Q_OBJECT
27 
28  public:
29  explicit QgsBrowserModel( QObject *parent = 0 );
30  ~QgsBrowserModel();
31 
32  // implemented methods from QAbstractItemModel for read-only access
33 
36  virtual Qt::ItemFlags flags( const QModelIndex &index ) const;
37 
42  virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
43 
46  virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
47 
49  virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const;
50 
53  virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const;
54 
56  virtual QModelIndex index( int row, int column, const QModelIndex & parent = QModelIndex() ) const;
57 
58  QModelIndex findItem( QgsDataItem *item, QgsDataItem *parent = 0 ) const;
59 
63  virtual QModelIndex parent( const QModelIndex &index ) const;
64 
66  virtual QStringList mimeTypes() const;
67 
69  virtual QMimeData * mimeData( const QModelIndexList &indexes ) const;
70 
72  virtual bool dropMimeData( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent );
73 
74  QgsDataItem *dataItem( const QModelIndex &idx ) const;
75 
76  bool hasChildren( const QModelIndex &parent = QModelIndex() ) const;
77 
78  // Refresh item specified by path
79  void refresh( QString path );
80 
81  // Refresh item childs
82  void refresh( const QModelIndex &index = QModelIndex() );
83 
85  QModelIndex findPath( QString path );
86 
87  void connectItem( QgsDataItem *item );
88 
89  bool canFetchMore( const QModelIndex & parent ) const;
90  void fetchMore( const QModelIndex & parent );
91 
92  public slots:
93  // Reload the whole model
94  void reload();
95  void beginInsertItems( QgsDataItem *parent, int first, int last );
96  void endInsertItems();
97  void beginRemoveItems( QgsDataItem *parent, int first, int last );
98  void endRemoveItems();
99 
100  void addFavouriteDirectory( QString favDir );
101  void removeFavourite( const QModelIndex &index );
102 
103  void updateProjectHome();
104 
105  protected:
106  // populates the model
107  void addRootItems();
108  void removeRootItems();
109 
110  QVector<QgsDataItem*> mRootItems;
113 };
114 
115 #endif // QGSBROWSERMODEL_H