Skip to content

Instantly share code, notes, and snippets.

@slarosa
Created September 5, 2015 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slarosa/8659f6bc1dda3477d275 to your computer and use it in GitHub Desktop.
Save slarosa/8659f6bc1dda3477d275 to your computer and use it in GitHub Desktop.
diff --git a/src/providers/postgres/qgspgsourceselect.cpp b/src/providers/postgres/qgspgsourceselect.cpp
index 773bb86..678a529 100644
--- a/src/providers/postgres/qgspgsourceselect.cpp
+++ b/src/providers/postgres/qgspgsourceselect.cpp
@@ -76,6 +76,8 @@ QWidget *QgsPgSourceSelectDelegate::createEditor( QWidget *parent, const QStyleO
if ( values.size() > 0 )
{
QComboBox *cb = new QComboBox( parent );
+ ComboBoxItemDelegate* cbid = new ComboBoxItemDelegate();
+ cb->setItemDelegate( cbid );
QStandardItemModel *model = new QStandardItemModel( values.size(), 1, cb );
@@ -84,11 +86,9 @@ QWidget *QgsPgSourceSelectDelegate::createEditor( QWidget *parent, const QStyleO
{
QStandardItem *item = new QStandardItem( value );
item->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
- item->setCheckable( true );
item->setData( Qt::Unchecked, Qt::CheckStateRole );
model->setItem( row++, 0, item );
}
-
cb->setModel( model );
return cb;
@@ -646,3 +646,24 @@ void QgsPgSourceSelect::setSearchExpression( const QString& regexp )
{
Q_UNUSED( regexp );
}
+
+/** Used to solve the issue with GTK+ and Cleanlooks style.
+ * In these styles the checkboes are not displayed
+ */
+
+QWidget* ComboBoxItemDelegate::createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const
+{
+ return QStyledItemDelegate::createEditor( parent, option, index );
+}
+
+
+void ComboBoxItemDelegate::setEditorData( QWidget* editor, const QModelIndex& index ) const
+{
+ QStyledItemDelegate::setEditorData( editor, index );
+}
+
+
+void ComboBoxItemDelegate::setModelData( QWidget* editor, QAbstractItemModel* model, const QModelIndex& index ) const
+{
+ QStyledItemDelegate::setModelData( editor, model, index );
+}
diff --git a/src/providers/postgres/qgspgsourceselect.h b/src/providers/postgres/qgspgsourceselect.h
index 0b5c9bf..218934e 100644
--- a/src/providers/postgres/qgspgsourceselect.h
+++ b/src/providers/postgres/qgspgsourceselect.h
@@ -27,6 +27,7 @@
#include <QPair>
#include <QIcon>
#include <QItemDelegate>
+#include <QStyledItemDelegate>
class QPushButton;
class QStringList;
@@ -39,7 +40,7 @@ class QgsPgSourceSelectDelegate : public QItemDelegate
Q_OBJECT;
public:
- QgsPgSourceSelectDelegate( QObject *parent = NULL )
+ QgsPgSourceSelectDelegate( QObject* parent = NULL )
: QItemDelegate( parent )
{}
@@ -49,6 +50,21 @@ class QgsPgSourceSelectDelegate : public QItemDelegate
};
+class ComboBoxItemDelegate : public QStyledItemDelegate
+{
+ Q_OBJECT;
+
+ public:
+ ComboBoxItemDelegate( QObject* parent = NULL )
+ : QStyledItemDelegate( parent )
+ {}
+
+ QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const override;
+ void setEditorData( QWidget* editor, const QModelIndex& index ) const override;
+ void setModelData( QWidget* editor, QAbstractItemModel* model, const QModelIndex& index ) const override;
+};
+
+
/** \class QgsPgSourceSelect
* \brief Dialog to create connections and add tables from PostgresQL.
*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment