PCManFM-Qt
 All Classes
proxyfoldermodel.h
1 /*
2  <one line to give the library's name and an idea of what it does.>
3  Copyright (C) 2012 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library 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 GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
20 
21 #ifndef FM_PROXYFOLDERMODEL_H
22 #define FM_PROXYFOLDERMODEL_H
23 
24 #include "libfmqtglobals.h"
25 #include <QSortFilterProxyModel>
26 #include <libfm/fm.h>
27 #include <QList>
28 
29 namespace Fm {
30 
31 // a proxy model used to sort and filter FolderModel
32 
33 class FolderModelItem;
34 class ProxyFolderModel;
35 
36 class LIBFM_QT_API ProxyFolderModelFilter {
37 public:
38  virtual bool filterAcceptsRow(const ProxyFolderModel* model, FmFileInfo* info) const = 0;
39  virtual ~ProxyFolderModelFilter() {}
40 };
41 
42 
43 class LIBFM_QT_API ProxyFolderModel : public QSortFilterProxyModel {
44  Q_OBJECT
45 public:
46 
47 public:
48  explicit ProxyFolderModel(QObject * parent = 0);
49  virtual ~ProxyFolderModel();
50 
51  // only Fm::FolderModel is allowed for being sourceModel
52  virtual void setSourceModel(QAbstractItemModel* model);
53 
54  void setShowHidden(bool show);
55  bool showHidden() {
56  return showHidden_;
57  }
58 
59  void setFolderFirst(bool folderFirst);
60  bool folderFirst() {
61  return folderFirst_;
62  }
63 
64  void setSortCaseSensitivity(Qt::CaseSensitivity cs) {
65  QSortFilterProxyModel::setSortCaseSensitivity(cs);
66  Q_EMIT sortFilterChanged();
67  }
68 
69  bool showThumbnails() {
70  return showThumbnails_;
71  }
72  void setShowThumbnails(bool show);
73 
74  int thumbnailSize() {
75  return thumbnailSize_;
76  }
77  void setThumbnailSize(int size);
78 
79  FmFileInfo* fileInfoFromIndex(const QModelIndex& index) const;
80 
81  virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
82  virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
83 
84  void addFilter(ProxyFolderModelFilter* filter);
85  void removeFilter(ProxyFolderModelFilter* filter);
86 
87 Q_SIGNALS:
88  void sortFilterChanged();
89 
90 protected Q_SLOTS:
91  void onThumbnailLoaded(const QModelIndex& srcIndex, int size);
92 
93 protected:
94  bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const;
95  bool lessThan(const QModelIndex & left, const QModelIndex & right) const;
96  // void reloadAllThumbnails();
97 
98 private:
99 
100 private:
101  bool showHidden_;
102  bool folderFirst_;
103  bool showThumbnails_;
104  int thumbnailSize_;
105  QList<ProxyFolderModelFilter*> filters_;
106 };
107 
108 }
109 
110 #endif // FM_PROXYFOLDERMODEL_H
Definition: appchoosercombobox.cpp:26
Definition: proxyfoldermodel.h:36
Definition: proxyfoldermodel.h:43