PCManFM-Qt
dirtreemodel.h
1 /*
2  * <one line to give the program's name and a brief idea of what it does.>
3  * Copyright (C) 2014 <copyright holder> <email>
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 along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  */
20 
21 #ifndef FM_DIRTREEMODEL_H
22 #define FM_DIRTREEMODEL_H
23 
24 #include "libfmqtglobals.h"
25 #include <QModelIndex>
26 #include <QAbstractItemModel>
27 #include <QIcon>
28 #include <QList>
29 #include <QSharedPointer>
30 #include <libfm/fm.h>
31 
32 namespace Fm {
33 
34 class DirTreeModelItem;
35 class DirTreeView;
36 
37 class LIBFM_QT_API DirTreeModel : public QAbstractItemModel {
38  Q_OBJECT
39 
40 public:
41  friend class DirTreeModelItem; // allow direct access of private members in DirTreeModelItem
42  friend class DirTreeView; // allow direct access of private members in DirTreeView
43 
44  enum Role {
45  FileInfoRole = Qt::UserRole
46  };
47 
48  explicit DirTreeModel(QObject* parent);
49  ~DirTreeModel();
50 
51  QModelIndex addRoot(FmFileInfo* root);
52  void loadRow(const QModelIndex& index);
53  void unloadRow(const QModelIndex& index);
54 
55  bool isLoaded(const QModelIndex& index);
56  QIcon icon(const QModelIndex& index);
57  FmFileInfo* fileInfo(const QModelIndex& index);
58  FmPath* filePath(const QModelIndex& index);
59  QString dispName(const QModelIndex& index);
60 
61  void setShowHidden(bool show_hidden);
62  bool showHidden() const {
63  return showHidden_;
64  }
65 
66  QModelIndex indexFromPath(FmPath* path) const;
67 
68  virtual Qt::ItemFlags flags(const QModelIndex& index) const;
69  virtual QVariant data(const QModelIndex& index, int role) const;
70  virtual int columnCount(const QModelIndex& parent) const;
71  virtual int rowCount(const QModelIndex& parent) const;
72  virtual QModelIndex parent(const QModelIndex& child) const;
73  virtual QModelIndex index(int row, int column, const QModelIndex& parent) const;
74  virtual bool hasChildren(const QModelIndex& parent = QModelIndex()) const;
75 
76 private:
77  DirTreeModelItem* itemFromPath(FmPath* path) const;
78  DirTreeModelItem* itemFromIndex(const QModelIndex& index) const;
79  QModelIndex indexFromItem(DirTreeModelItem* item) const;
80 
81 Q_SIGNALS:
82  void rowLoaded(const QModelIndex& index);
83 
84 private:
85  bool showHidden_;
86  QList<DirTreeModelItem*> rootItems_;
87 };
88 }
89 
90 #endif // FM_DIRTREEMODEL_H
Definition: appchoosercombobox.cpp:26
Definition: dirtreeview.h:36
Definition: dirtreemodel.h:37
Definition: dirtreemodelitem.h:35