浏览代码

ENH: Allow edit on single click. Fixes #9393. Also fix row heights to be consistent.

Clinton Stimpson 16 年之前
父节点
当前提交
37805ff81c
共有 2 个文件被更改,包括 18 次插入4 次删除
  1. 17 4
      Source/QtDialog/QCMakeCacheView.cxx
  2. 1 0
      Source/QtDialog/QCMakeCacheView.h

+ 17 - 4
Source/QtDialog/QCMakeCacheView.cxx

@@ -24,6 +24,7 @@
 #include <QKeyEvent>
 #include <QSortFilterProxyModel>
 #include <QMetaProperty>
+#include <QApplication>
 
 #include "QCMakeWidgets.h"
 
@@ -139,10 +140,9 @@ QCMakeCacheView::QCMakeCacheView(QWidget* p)
   QCMakeCacheModelDelegate* delegate = new QCMakeCacheModelDelegate(this);
   this->setItemDelegate(delegate);
   
-  this->setEditTriggers(QAbstractItemView::DoubleClicked |
-                        QAbstractItemView::SelectedClicked |
-                        QAbstractItemView::EditKeyPressed |
-                        QAbstractItemView::AnyKeyPressed);
+  this->setUniformRowHeights(true);
+ 
+  this->setEditTriggers(QAbstractItemView::AllEditTriggers);
 
   // tab, backtab doesn't step through items
   this->setTabKeyNavigation(false);
@@ -664,6 +664,19 @@ void QCMakeCacheModelDelegate::setModelData(QWidget* editor,
   const_cast<QCMakeCacheModelDelegate*>(this)->recordChange(model, index);
 }
   
+QSize QCMakeCacheModelDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
+{
+  QSize sz = QItemDelegate::sizeHint(option, index);
+  QStyle *style = QApplication::style();
+
+  // increase to checkbox size
+  QStyleOptionButton opt;
+  opt.QStyleOption::operator=(option);
+  sz = sz.expandedTo(style->subElementRect(QStyle::SE_ViewItemCheckIndicator, &opt, NULL).size());
+
+  return sz;
+}
+  
 QSet<QCMakeProperty> QCMakeCacheModelDelegate::changes() const
 {
   return mChanges;

+ 1 - 0
Source/QtDialog/QCMakeCacheView.h

@@ -150,6 +150,7 @@ public:
        const QStyleOptionViewItem& option, const QModelIndex& index);
   bool eventFilter(QObject* object, QEvent* event);
   void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index ) const;
+  QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
 
   QSet<QCMakeProperty> changes() const;
   void clearChanges();