Переглянути джерело

ctkTreeComboBox now controls what column is visible

Julien Finet 14 роки тому
батько
коміт
fa0b865590
2 змінених файлів з 36 додано та 0 видалено
  1. 29 0
      Libs/Widgets/ctkTreeComboBox.cpp
  2. 7 0
      Libs/Widgets/ctkTreeComboBox.h

+ 29 - 0
Libs/Widgets/ctkTreeComboBox.cpp

@@ -50,6 +50,7 @@ public:
   bool RootSet;
   bool RootSet;
   bool SendCurrentItem;
   bool SendCurrentItem;
   QPersistentModelIndex Root;
   QPersistentModelIndex Root;
+  int VisibleModelColumn;
 };
 };
 
 
 // -------------------------------------------------------------------------
 // -------------------------------------------------------------------------
@@ -59,6 +60,7 @@ ctkTreeComboBoxPrivate::ctkTreeComboBoxPrivate(ctkTreeComboBox& object)
   this->SkipNextHide = false;
   this->SkipNextHide = false;
   this->RootSet = false;
   this->RootSet = false;
   this->SendCurrentItem = false;
   this->SendCurrentItem = false;
+  this->VisibleModelColumn = -1; // all visible by default
 }
 }
 
 
 // -------------------------------------------------------------------------
 // -------------------------------------------------------------------------
@@ -90,6 +92,20 @@ ctkTreeComboBox::~ctkTreeComboBox()
 }
 }
 
 
 // -------------------------------------------------------------------------
 // -------------------------------------------------------------------------
+int ctkTreeComboBox::visibleModelColumn()const
+{
+  Q_D(const ctkTreeComboBox);
+  return d->VisibleModelColumn;
+}
+
+// -------------------------------------------------------------------------
+void ctkTreeComboBox::setVisibleModelColumn(int index)
+{
+  Q_D(ctkTreeComboBox);
+  d->VisibleModelColumn = index;
+}
+
+// -------------------------------------------------------------------------
 bool ctkTreeComboBox::eventFilter(QObject* object, QEvent* _event)
 bool ctkTreeComboBox::eventFilter(QObject* object, QEvent* _event)
 {
 {
   Q_D(ctkTreeComboBox);
   Q_D(ctkTreeComboBox);
@@ -150,6 +166,19 @@ bool ctkTreeComboBox::eventFilter(QObject* object, QEvent* _event)
 }
 }
 
 
 // -------------------------------------------------------------------------
 // -------------------------------------------------------------------------
+void ctkTreeComboBox::showPopup()
+{
+  Q_D(ctkTreeComboBox);
+  QHeaderView* header = qobject_cast<QTreeView*>(this->view())->header();
+  for (int i = 0; i < header->count(); ++i)
+    {
+    header->setSectionHidden(i, d->VisibleModelColumn != -1 &&
+                                i != d->VisibleModelColumn);
+    }
+  this->QComboBox::showPopup();
+}
+
+// -------------------------------------------------------------------------
 void ctkTreeComboBox::hidePopup()
 void ctkTreeComboBox::hidePopup()
 {
 {
   Q_D(ctkTreeComboBox);
   Q_D(ctkTreeComboBox);

+ 7 - 0
Libs/Widgets/ctkTreeComboBox.h

@@ -49,12 +49,19 @@ class QTreeView;
 class CTK_WIDGETS_EXPORT ctkTreeComboBox : public QComboBox
 class CTK_WIDGETS_EXPORT ctkTreeComboBox : public QComboBox
 {
 {
   Q_OBJECT
   Q_OBJECT
+  /// Column index visible in the view. If \sa visibleModelColumn is -1
+  /// (default) then all columns are visible.
+  Q_PROPERTY(int visibleModelColumn READ visibleModelColumn WRITE setVisibleModelColumn)
 public:
 public:
   typedef QComboBox Superclass;
   typedef QComboBox Superclass;
   explicit ctkTreeComboBox(QWidget* parent = 0);
   explicit ctkTreeComboBox(QWidget* parent = 0);
   virtual ~ctkTreeComboBox();
   virtual ~ctkTreeComboBox();
 
 
+  int visibleModelColumn()const;
+  void setVisibleModelColumn(int index);
+
   virtual bool eventFilter(QObject* object, QEvent* event);
   virtual bool eventFilter(QObject* object, QEvent* event);
+  virtual void showPopup();
   virtual void hidePopup();
   virtual void hidePopup();
   
   
   /// ctkTreeComboBox uses a QTreeView for its model view. treeView() is a
   /// ctkTreeComboBox uses a QTreeView for its model view. treeView() is a