CFileTreeViewGuiComp.h
Go to the documentation of this file.
1 #ifndef ifilegui_CFileTreeViewGuiComp_included
2 #define ifilegui_CFileTreeViewGuiComp_included
3 
4 
5 // Qt includes
6 #include <QtCore/QDir>
7 #include <QtCore/QTimer>
8 #include <QtCore/QElapsedTimer>
9 #include <QtCore/QThread>
10 #include <QtCore/QMutexLocker>
11 #include <QtGui/QStandardItemModel>
12 #if QT_VERSION >= 0x050000
13 #include <QtWidgets/QFileIconProvider>
14 #else
15 #include <QtGui/QFileIconProvider>
16 #endif
17 
18 
19 // ACF includes
20 #include <ifile/IFileNameParam.h>
21 #include <ifile/IFileTypeInfo.h>
25 
26 #include <GeneratedFiles/ifilegui/ui_CFileTreeViewGuiComp.h>
27 
28 
29 namespace ifilegui
30 {
31 
32 
40  Ui::CFileTreeViewGuiComp, ifile::IFileNameParam>,
42 {
43  Q_OBJECT
44 public:
46  Ui::CFileTreeViewGuiComp, ifile::IFileNameParam> BaseClass;
47 
48  I_BEGIN_COMPONENT(CFileTreeViewGuiComp);
49  I_REGISTER_SUBELEMENT(CurrentFile);
50  I_REGISTER_SUBELEMENT_INTERFACE(CurrentFile, ifile::IFileNameParam, ExtractCurrentFile);
51  I_REGISTER_SUBELEMENT_INTERFACE(CurrentFile, imod::IModel, ExtractCurrentFile);
52  I_REGISTER_SUBELEMENT_INTERFACE(CurrentFile, istd::IChangeable, ExtractCurrentFile);
53  I_REGISTER_SUBELEMENT_INTERFACE(CurrentFile, iser::ISerializable, ExtractCurrentFile);
54  I_ASSIGN(m_fileTypeInfoCompPtr, "FileTypeInfo", "File type info used to create file filters", false, "FileTypeInfo");
55  I_ASSIGN_MULTI_0(m_filtersAttrPtr, "Filters", "List of filters if no FileTypeInfo is specified", false);
56  I_ASSIGN(m_noEmptyDirsAttrPtr, "NoEmptyFolders", "Recursively skip folder which containing no files", true, true);
57  I_END_COMPONENT;
58 
59  enum DataRoles
60  {
61  DR_PATH = Qt::UserRole + 1,
63  };
64 
66 
67 protected:
68  // reimplemented (icomp::CComponentBase)
69  virtual void OnComponentCreated();
70  virtual void OnComponentDestroyed();
71 
72  // reimplemented (iqtgui::CGuiComponentBase)
73  virtual void OnGuiCreated();
74 
75  // reimplemented (iqtgui::TGuiObserverWrap)
76  virtual void UpdateGui(const istd::IChangeable::ChangeSet& changeSet);
77 
78  // reimplemented (imod::CMultiModelDispatcherBase)
79  virtual void OnModelChanged(int modelId, const istd::IChangeable::ChangeSet& changeSet);
80 
81 private Q_SLOTS:
82  void OnSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected);
83  void on_Refresh_clicked();
84  void OnTreeModelUpdated();
85  void on_FilterText_textChanged(QString filterText);
86 
87 private:
88  void RebuildTreeModel();
89  void DoTreeModelUpdate();
90  void UpdateCurrentSelection();
91  void UpdateChildItems(QStandardItem* itemPtr);
92 
98  bool CreateFileList(const QDir& root,
99  const QStringList& nameFilters,
100  QDir::SortFlags sortSpec,
101  QStandardItem* parentItemPtr);
102 
106  bool CreateDirectoryList(
107  const QDir& root,
108  const QStringList& nameFilters,
109  QDir::SortFlags sortSpec,
110  QStandardItem* parentItemPtr);
111 
112  void EnumerateDirectory(
113  const QDir& root,
114  const QStringList& nameFilters,
115  QDir::SortFlags sortSpec,
116  QStandardItem* parentItemPtr);
117 
118 private:
119  class CurrentFile: public ifile::CFileNameParamComp
120  {
121  public:
122  // reimplemented (ifile::IFileNameParam)
123  virtual int GetPathType() const
124  {
125  return PT_FILE;
126  }
127  };
128 
129  imod::TModelWrap<CurrentFile> m_currentFile;
130 
131  // static template methods for subelement access
132  template <class InterfaceType>
133  static InterfaceType* ExtractCurrentFile(CFileTreeViewGuiComp& component)
134  {
135  return &component.m_currentFile;
136  }
137 
138  class InternalThread: public QThread
139  {
140  public:
141  explicit InternalThread(CFileTreeViewGuiComp* parentPtr): QThread(parentPtr),
142  m_parentPtr(parentPtr)
143  {
144  }
145 
146  // reimplemented (QThread)
147  virtual void run()
148  {
149  m_parentPtr->DoTreeModelUpdate();
150  }
151 
152  private:
153  CFileTreeViewGuiComp* m_parentPtr;
154  };
155 
156  friend class InternalThread;
157  InternalThread* m_internalThreadPtr;
158 
159  QMutex m_lock;
160 
161  bool m_fileModelUpdateAllowed;
162  int m_filesCount;
163  int m_dirsCount;
164 
165  mutable QStandardItemModel m_itemModel;
166  QFileIconProvider m_iconProvider;
167 
168  mutable QMap<QString, QIcon> m_extToIconMap;
169 
170  QRegExp m_filterMatcher;
171  QString m_userFilter;
172  QTimer m_filterTimer;
173  QElapsedTimer m_performanceTimer;
174 
175  I_REF(ifile::IFileTypeInfo, m_fileTypeInfoCompPtr);
176  I_MULTIATTR(QString, m_filtersAttrPtr);
177  I_ATTR(bool, m_noEmptyDirsAttrPtr);
178 };
179 
180 
181 } // namespace ifilegui
182 
183 
184 #endif // !ifilegui_CFileTreeProviderGuiComp_included
185 
186 
virtual void OnComponentDestroyed()
virtual void OnGuiCreated()
Called just after GUI is initialized.
virtual void OnModelChanged(int modelId, const istd::IChangeable::ChangeSet &changeSet)
Provide loading and saving of objects.
Definition: IFileTypeInfo.h:22
Generic implementation of a data model changes notifier.
Common class for all classes which objects can be archived or restored from archive.
Definition: ISerializable.h:23
iqtgui::TDesignerGuiObserverCompBase< Ui::CFileTreeViewGuiComp, ifile::IFileNameParam > BaseClass
Common interface for any file system item name (e.g directory, file or URL path)
Common interface for data model objects, which can be changed.
Definition: IChangeable.h:24
File system explorer-like component.
Base class for all Qt GUI components.
virtual void UpdateGui(const istd::IChangeable::ChangeSet &changeSet)
Do update of the GUI to reflect the state of model.
Basic implementation of interface ifile::IFileNameParam as component.
Common interface for model objects, that supports Model/Observer design pattern.
Definition: IModel.h:23
Set of change flags (its IDs).
Definition: IChangeable.h:30

© 2007-2017 Witold Gantzke and Kirill Lepskiy