PCManFM-Qt
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  explicit ProxyFolderModel(QObject * parent = 0);
47  virtual ~ProxyFolderModel();
48 
49  // only Fm::FolderModel is allowed for being sourceModel
50  virtual void setSourceModel(QAbstractItemModel* model);
51 
52  void setShowHidden(bool show);
53  bool showHidden() const {
54  return showHidden_;
55  }
56 
57  void setFolderFirst(bool folderFirst);
58  bool folderFirst() {
59  return folderFirst_;
60  }
61 
62  void setSortCaseSensitivity(Qt::CaseSensitivity cs) {
63  QSortFilterProxyModel::setSortCaseSensitivity(cs);
64  Q_EMIT sortFilterChanged();
65  }
66 
67  bool showThumbnails() {
68  return showThumbnails_;
69  }
70  void setShowThumbnails(bool show);
71 
72  int thumbnailSize() {
73  return thumbnailSize_;
74  }
75  void setThumbnailSize(int size);
76 
77  FmFileInfo* fileInfoFromIndex(const QModelIndex& index) const;
78 
79  virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
80  virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
81 
82  void addFilter(ProxyFolderModelFilter* filter);
83  void removeFilter(ProxyFolderModelFilter* filter);
84  void updateFilters();
85 
86 Q_SIGNALS:
87  void sortFilterChanged();
88 
89 protected Q_SLOTS:
90  void onThumbnailLoaded(const QModelIndex& srcIndex, int size);
91 
92 protected:
93  bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const;
94  bool lessThan(const QModelIndex & left, const QModelIndex & right) const;
95  // void reloadAllThumbnails();
96 
97 private:
98 
99 private:
100  bool showHidden_;
101  bool folderFirst_;
102  bool showThumbnails_;
103  int thumbnailSize_;
104  QList<ProxyFolderModelFilter*> filters_;
105 };
106 
107 }
108 
109 #endif // FM_PROXYFOLDERMODEL_H
Definition: appchoosercombobox.cpp:26
Definition: proxyfoldermodel.h:36
Definition: proxyfoldermodel.h:43