Quellcode durchsuchen

Added getter for the standard item for further widget customization.

Sascha Zelzer vor 12 Jahren
Ursprung
Commit
97750a6bea
2 geänderte Dateien mit 51 neuen und 0 gelöschten Zeilen
  1. 36 0
      Libs/Widgets/ctkPathListWidget.cpp
  2. 15 0
      Libs/Widgets/ctkPathListWidget.h

+ 36 - 0
Libs/Widgets/ctkPathListWidget.cpp

@@ -584,6 +584,30 @@ QString ctkPathListWidget::path(int row) const
 }
 
 // --------------------------------------------------------------------------
+QStandardItem* ctkPathListWidget::item(int row) const
+{
+  Q_D(const ctkPathListWidget);
+  return d->PathListModel.item(row);
+}
+
+// --------------------------------------------------------------------------
+QStandardItem *ctkPathListWidget::item(const QString &absolutePath) const
+{
+  Q_D(const ctkPathListWidget);
+  QModelIndexList result = d->PathListModel.match(d->PathListModel.index(0,0), AbsolutePathRole,
+                                                  absolutePath, 1, Qt::MatchExactly);
+  Q_ASSERT(result.count() < 2);
+  if (result.isEmpty())
+  {
+    return NULL;
+  }
+  else
+  {
+    return d->PathListModel.item(result.front().row());
+  }
+}
+
+// --------------------------------------------------------------------------
 QString ctkPathListWidget::pathAt(const QPoint& point) const
 {
   Q_D(const ctkPathListWidget);
@@ -591,6 +615,18 @@ QString ctkPathListWidget::pathAt(const QPoint& point) const
 }
 
 // --------------------------------------------------------------------------
+QStandardItem* ctkPathListWidget::itemAt(const QPoint &point) const
+{
+  Q_D(const ctkPathListWidget);
+  QModelIndex index = this->indexAt(point);
+  if (index.isValid())
+  {
+    return d->PathListModel.item(index.row());
+  }
+  return NULL;
+}
+
+// --------------------------------------------------------------------------
 int ctkPathListWidget::row(const QString& path) const
 {
   Q_D(const ctkPathListWidget);

+ 15 - 0
Libs/Widgets/ctkPathListWidget.h

@@ -32,6 +32,8 @@
 
 class ctkPathListWidgetPrivate;
 
+class QStandardItem;
+
 /// \ingroup Widgets
 ///
 /// \brief The ctkPathListWidget lists files and/or directories.
@@ -181,13 +183,26 @@ public:
   /// \return The absolute path for \a row or a null QString if \a row is out of range.
   QString path(int row) const;
 
+  /// \return The item for \a row or NULL if \a row is out of range.
+  QStandardItem* item(int row) const;
+
+  /// \return The item for the given absolute path or NULL if the the path is not known.
+  QStandardItem* item(const QString& absolutePath) const;
+
   /// \return The absolute path for the entry located at the point \a point (in the
   ///         widget coordinate system) or a null QString if no entry could be found for \a point.
   QString pathAt(const QPoint& point) const;
 
+  /// \return The item for the entry located at the point \a point (in the widget
+  ///         coordinate system) or NULL if no ite could be found for \a point.
+  QStandardItem* itemAt(const QPoint& point) const;
+
   /// \see pathAt(const QPoint&)
   QString pathAt(int x, int y) const { return pathAt(QPoint(x, y)); }
 
+  /// \see itemAt(const QPoint&)
+  QStandardItem* itemAt(int x, int y) const { return itemAt(QPoint(x, y)); }
+
   /// \return The row number for the given \a path or -1 if \a path is not in the list of current
   ///         entries.
   int row(const QString& path) const;