CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkPathListWidget.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Library: CTK
4 
5  Copyright (c) Kitware Inc.
6 
7  Licensed under the Apache License, Version 2.0 (the "License");
8  you may not use this file except in compliance with the License.
9  You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0.txt
12 
13  Unless required by applicable law or agreed to in writing, software
14  distributed under the License is distributed on an "AS IS" BASIS,
15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  See the License for the specific language governing permissions and
17  limitations under the License.
18 
19  This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc.
20  and was partially funded by NIH grant 3P41RR013218-12S1
21 
22 =========================================================================*/
23 
24 #ifndef __ctkPathListWidget_h
25 #define __ctkPathListWidget_h
26 
27 // Qt includes
28 #include <QListView>
29 
30 // QtGUI includes
31 #include "ctkWidgetsExport.h"
32 
33 class ctkPathListWidgetPrivate;
34 
35 class QStandardItem;
36 
47 class CTK_WIDGETS_EXPORT ctkPathListWidget : public QListView
48 {
49  Q_OBJECT
50 
52  Q_PROPERTY(QStringList paths READ paths WRITE setPaths NOTIFY pathsChanged)
53 
54 
55  Q_PROPERTY(Mode mode READ mode WRITE setMode)
56 
57 
58  Q_PROPERTY(PathOptions fileOptions READ fileOptions WRITE setFileOptions)
59 
60 
61  Q_PROPERTY(PathOptions directoryOptions READ directoryOptions WRITE setDirectoryOptions)
62 
63 
64  Q_PROPERTY(QIcon fileIcon READ fileIcon WRITE setFileIcon RESET unsetFileIcon)
65 
66 
67  Q_PROPERTY(QIcon directoryIcon READ directoryIcon WRITE setDirectoryIcon RESET unsetDirectoryIcon)
68 
69  Q_FLAGS(PathOption PathOptions)
70  Q_ENUMS(Mode)
71 
72 public:
73 
74  enum
75  {
77  AbsolutePathRole = Qt::UserRole + 1
78  };
79 
82  {
84  None = 0x00,
86  Exists = 0x01,
88  Readable = 0x02,
90  Writable = 0x04,
92  Executable = 0x08
93  };
94  Q_DECLARE_FLAGS(PathOptions, PathOption)
95 
96  enum Mode
97  {
99  Any = 0,
103  DirectoriesOnly
104  };
105 
107  typedef QListView Superclass;
108 
110  explicit ctkPathListWidget(QWidget* parent = 0);
111 
114 
116  Mode mode() const;
117 
119  QIcon fileIcon() const;
120 
123  void setFileIcon(const QIcon& icon);
124 
127 
129  QIcon directoryIcon() const;
130 
133  void setDirectoryIcon(const QIcon& icon);
134 
137 
139  PathOptions fileOptions() const;
140 
143  void setFileOptions(PathOptions fileOptions);
144 
146  PathOptions directoryOptions() const;
147 
150  void setDirectoryOptions(PathOptions directoryOptions);
151 
154  bool contains(const QString& path)const;
155 
159  QStringList files(bool absolutePath = false) const;
160 
164  QStringList directories(bool absolutePath = false) const;
165 
169  QStringList paths(bool absolutePath = false) const;
170 
174  QStringList selectedPaths(bool absolutePath = false) const;
175 
179  QString currentPath(bool absolutePath = false) const;
180 
182  int count() const;
183 
185  QString path(int row) const;
186 
188  QStandardItem* item(int row) const;
189 
191  QStandardItem* item(const QString& absolutePath) const;
192 
195  QString pathAt(const QPoint& point) const;
196 
199  QStandardItem* itemAt(const QPoint& point) const;
200 
202  QString pathAt(int x, int y) const { return pathAt(QPoint(x, y)); }
203 
205  QStandardItem* itemAt(int x, int y) const { return itemAt(QPoint(x, y)); }
206 
209  int row(const QString& path) const;
210 
216  bool editPath(const QString& oldPath, const QString& newPath);
217 
223  bool editPath(const QModelIndex& index, const QString& newPath);
224 
227  bool isFile(const QString& path) const;
228 
231  bool isDirectory(const QString& path) const;
232 
233 public Q_SLOTS:
234 
237  void setMode(Mode mode);
238 
244  bool addPath(const QString& path);
245 
251  QStringList addPaths(const QStringList& paths);
252 
259  void setPaths(const QStringList& paths);
260 
267  bool removePath(const QString& path);
268 
272  QStringList removePaths(const QStringList& paths);
273 
276 
278  void clear();
279 
280 Q_SIGNALS:
281 
285  void pathsChanged(const QStringList& added, const QStringList& removed);
286 
288  void pathClicked(const QString& absolutePath);
289 
291  void pathDoubleClicked(const QString& absolutePath);
292 
297  void pathActivated(const QString& absolutePath);
298 
302  void currentPathChanged(const QString& currentAbsolutePath, const QString& previousAbsolutePath);
303 
304 protected:
305  QScopedPointer<ctkPathListWidgetPrivate> d_ptr;
306 
307 private:
308 
309  void setModel(QAbstractItemModel *model);
310 
311  Q_DECLARE_PRIVATE(ctkPathListWidget)
312  Q_DISABLE_COPY(ctkPathListWidget)
313 
314  Q_PRIVATE_SLOT(d_func(), void _q_emitPathClicked(const QModelIndex& index))
315  Q_PRIVATE_SLOT(d_func(), void _q_emitPathDoubleClicked(const QModelIndex& index))
316  Q_PRIVATE_SLOT(d_func(), void _q_emitPathActivated(const QModelIndex& index))
317  Q_PRIVATE_SLOT(d_func(), void _q_emitCurrentPathChanged(const QModelIndex &previous, const QModelIndex &current))
318 };
319 
320 Q_DECLARE_OPERATORS_FOR_FLAGS(ctkPathListWidget::PathOptions)
321 
322 #endif
323 
The ctkPathListWidget lists files and/or directories.
bool editPath(const QModelIndex &index, const QString &newPath)
bool contains(const QString &path) const
QStandardItem * item(const QString &absolutePath) const
void currentPathChanged(const QString &currentAbsolutePath, const QString &previousAbsolutePath)
QStandardItem * itemAt(const QPoint &point) const
void pathActivated(const QString &absolutePath)
bool editPath(const QString &oldPath, const QString &newPath)
QStringList addPaths(const QStringList &paths)
void setPaths(const QStringList &paths)
QStandardItem * itemAt(int x, int y) const
QStandardItem * item(int row) const
void pathsChanged(const QStringList &added, const QStringList &removed)
QStringList files(bool absolutePath=false) const
void setMode(Mode mode)
QScopedPointer< ctkPathListWidgetPrivate > d_ptr
void removeSelectedPaths()
Remove all currently selected paths from the list.
void setDirectoryIcon(const QIcon &icon)
void setFileOptions(PathOptions fileOptions)
void clear()
Remove all paths from the list.
void setFileIcon(const QIcon &icon)
QStringList removePaths(const QStringList &paths)
QIcon fileIcon() const
PathOption
Describes constraints on paths.
QStringList selectedPaths(bool absolutePath=false) const
bool isFile(const QString &path) const
int count() const
PathOptions directoryOptions() const
virtual ~ctkPathListWidget()
Destructor.
void pathClicked(const QString &absolutePath)
The user clicked on a path entry.
void setDirectoryOptions(PathOptions directoryOptions)
QStringList directories(bool absolutePath=false) const
void unsetDirectoryIcon()
Un-set any custom directory icon.
int row(const QString &path) const
QListView Superclass
Superclass typedef.
QIcon directoryIcon() const
ctkPathListWidget(QWidget *parent=0)
Constructor.
void pathDoubleClicked(const QString &absolutePath)
The user double-clicked on a path entry.
QStringList paths(bool absolutePath=false) const
PathOptions fileOptions() const
bool addPath(const QString &path)
@ FilesOnly
Allow only file entries.
QString pathAt(const QPoint &point) const
QString currentPath(bool absolutePath=false) const
void unsetFileIcon()
Un-set any custom file icon.
QString pathAt(int x, int y) const
Mode mode() const
QString path(int row) const
bool removePath(const QString &path)
bool isDirectory(const QString &path) const
Q_DECLARE_OPERATORS_FOR_FLAGS(ctkVTKDataSetModel::AttributeTypes)