浏览代码

BUG: ctkTreeComboBox now supports QComboBox::rootModelIndex

ctkTreeComboBox was resetting the root model index to the invalid
QModelIndex everytime the view was popup.
Julien Finet 15 年之前
父节点
当前提交
fa509d4d5b
共有 2 个文件被更改,包括 19 次插入13 次删除
  1. 17 10
      Libs/Widgets/ctkTreeComboBox.cpp
  2. 2 3
      Libs/Widgets/ctkTreeComboBox.h

+ 17 - 10
Libs/Widgets/ctkTreeComboBox.cpp

@@ -32,23 +32,24 @@
 class ctkTreeComboBoxPrivate: public ctkPrivate<ctkTreeComboBox>
 {
 public:
+  ctkTreeComboBoxPrivate();
   bool SkipNextHide;
   bool ResetPopupSize;
-  
-  void init()
-  {
-    this->SkipNextHide = false;
-    this->ResetPopupSize = false;
-  }
+  bool RootSet;
+  QPersistentModelIndex Root;
 };
 
+ctkTreeComboBoxPrivate::ctkTreeComboBoxPrivate()
+{
+  this->SkipNextHide = false;
+  this->ResetPopupSize = false;
+  this->RootSet = false;
+}
+
 // -------------------------------------------------------------------------
 ctkTreeComboBox::ctkTreeComboBox(QWidget* _parent):Superclass(_parent)
 {
   CTK_INIT_PRIVATE(ctkTreeComboBox);
-  CTK_D(ctkTreeComboBox);
-  
-  d->init();
   QTreeView* treeView = new QTreeView(this);
   treeView->setHeaderHidden(true);
   this->setView(treeView);
@@ -109,7 +110,13 @@ bool ctkTreeComboBox::eventFilter(QObject* object, QEvent* _event)
 // -------------------------------------------------------------------------
 void ctkTreeComboBox::showPopup()
 {
-  this->setRootModelIndex(QModelIndex());
+  CTK_D(ctkTreeComboBox);
+  if (!d->RootSet)
+    {
+    d->Root = this->rootModelIndex();
+    d->RootSet = true;
+    }
+  this->setRootModelIndex(QModelIndex(d->Root));
   this->QComboBox::showPopup();
 }
 

+ 2 - 3
Libs/Widgets/ctkTreeComboBox.h

@@ -29,7 +29,9 @@
 
 #include "CTKWidgetsExport.h"
 
+class ctkTreeComboBoxPrivate;
 class QTreeView;
+
 /// Description:
 /// ComboBox that displays the items as a tree view.
 /// See below for a use case:
@@ -43,9 +45,6 @@ class QTreeView;
 ///    model.appendRow(new QStandardItem("Test3"));
 ///    combo.setModel(&model);
 ///    combo.show();
-//
-class ctkTreeComboBoxPrivate;
-
 class CTK_WIDGETS_EXPORT ctkTreeComboBox : public QComboBox
 {
   Q_OBJECT