Skip to content
Permalink
Browse files

Implement QgsEditorWidgetWrapper::showIndeterminateState() for setting

editor widgets into an indeterminant "unknown value" state

Works for all editor widgets except date time, range and uuid widgets.
  • Loading branch information
nyalldawson committed Apr 5, 2016
1 parent 16274d5 commit 22f1a1dee7f428c5a2c00e0aa2d3560904e42ede
Showing with 226 additions and 21 deletions.
  1. +5 −0 python/gui/editorwidgets/core/qgseditorwidgetwrapper.sip
  2. +5 −0 src/gui/editorwidgets/core/qgseditorwidgetwrapper.h
  3. +11 −2 src/gui/editorwidgets/qgscheckboxwidgetwrapper.cpp
  4. +2 −0 src/gui/editorwidgets/qgscheckboxwidgetwrapper.h
  5. +5 −0 src/gui/editorwidgets/qgsclassificationwidgetwrapper.cpp
  6. +1 −0 src/gui/editorwidgets/qgsclassificationwidgetwrapper.h
  7. +8 −0 src/gui/editorwidgets/qgscolorwidgetwrapper.cpp
  8. +1 −0 src/gui/editorwidgets/qgscolorwidgetwrapper.h
  9. +8 −0 src/gui/editorwidgets/qgsenumerationwidgetwrapper.cpp
  10. +1 −0 src/gui/editorwidgets/qgsenumerationwidgetwrapper.h
  11. +18 −0 src/gui/editorwidgets/qgsexternalresourcewidgetwrapper.cpp
  12. +1 −0 src/gui/editorwidgets/qgsexternalresourcewidgetwrapper.h
  13. +11 −0 src/gui/editorwidgets/qgsfilenamewidgetwrapper.cpp
  14. +1 −0 src/gui/editorwidgets/qgsfilenamewidgetwrapper.h
  15. +12 −0 src/gui/editorwidgets/qgsphotowidgetwrapper.cpp
  16. +1 −0 src/gui/editorwidgets/qgsphotowidgetwrapper.h
  17. +14 −0 src/gui/editorwidgets/qgsrelationreferencewidget.cpp
  18. +5 −0 src/gui/editorwidgets/qgsrelationreferencewidget.h
  19. +12 −1 src/gui/editorwidgets/qgsrelationreferencewidgetwrapper.cpp
  20. +2 −0 src/gui/editorwidgets/qgsrelationreferencewidgetwrapper.h
  21. +43 −18 src/gui/editorwidgets/qgstexteditwrapper.cpp
  22. +3 −0 src/gui/editorwidgets/qgstexteditwrapper.h
  23. +12 −0 src/gui/editorwidgets/qgsuniquevaluewidgetwrapper.cpp
  24. +1 −0 src/gui/editorwidgets/qgsuniquevaluewidgetwrapper.h
  25. +8 −0 src/gui/editorwidgets/qgsvaluemapwidgetwrapper.cpp
  26. +1 −0 src/gui/editorwidgets/qgsvaluemapwidgetwrapper.h
  27. +21 −0 src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.cpp
  28. +1 −0 src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.h
  29. +11 −0 src/gui/editorwidgets/qgswebviewwidgetwrapper.cpp
  30. +1 −0 src/gui/editorwidgets/qgswebviewwidgetwrapper.h
@@ -83,6 +83,11 @@ class QgsEditorWidgetWrapper : QgsWidgetWrapper
*/
void setEnabled( bool enabled );

/** Sets the widget to display in an indeterminate "mixed value" state.
* @note added in QGIS 2.16
*/
virtual void showIndeterminateState();

signals:
/**
* Emit this signal, whenever the value changed.
@@ -105,6 +105,11 @@ class GUI_EXPORT QgsEditorWidgetWrapper : public QgsWidgetWrapper
*/
void setEnabled( bool enabled ) override;

/** Sets the widget to display in an indeterminate "mixed value" state.
* @note added in QGIS 2.16
*/
virtual void showIndeterminateState() {}

signals:
/**
* Emit this signal, whenever the value changed.
@@ -37,6 +37,14 @@ QVariant QgsCheckboxWidgetWrapper::value() const
return v;
}

void QgsCheckboxWidgetWrapper::showIndeterminateState()
{
if ( mCheckBox )
{
whileBlocking( mCheckBox )->setCheckState( Qt::PartiallyChecked );
}
}

QWidget* QgsCheckboxWidgetWrapper::createWidget( QWidget* parent )
{
return new QCheckBox( parent );
@@ -60,13 +68,14 @@ bool QgsCheckboxWidgetWrapper::valid() const

void QgsCheckboxWidgetWrapper::setValue( const QVariant& value )
{
bool state = ( value == config( "CheckedState" ) );
if ( mGroupBox )
{
mGroupBox->setChecked( value == config( "CheckedState" ) );
mGroupBox->setChecked( state );
}

if ( mCheckBox )
{
mCheckBox->setChecked( value == config( "CheckedState" ) );
mCheckBox->setChecked( state );
}
}
@@ -43,6 +43,8 @@ class GUI_EXPORT QgsCheckboxWidgetWrapper : public QgsEditorWidgetWrapper
public:
QVariant value() const override;

void showIndeterminateState() override;

protected:
QWidget* createWidget( QWidget* parent ) override;
void initWidget( QWidget* editor ) override;
@@ -29,6 +29,11 @@ QVariant QgsClassificationWidgetWrapper::value() const
return mComboBox->itemData( mComboBox->currentIndex() );
}

void QgsClassificationWidgetWrapper::showIndeterminateState()
{
whileBlocking( mComboBox )->setCurrentIndex( -1 );
}

QWidget*QgsClassificationWidgetWrapper::createWidget( QWidget* parent )
{
return new QComboBox( parent );
@@ -33,6 +33,7 @@ class GUI_EXPORT QgsClassificationWidgetWrapper : public QgsEditorWidgetWrapper
// QgsEditorWidgetWrapper interface
public:
QVariant value() const override;
void showIndeterminateState() override;

protected:
QWidget*createWidget( QWidget* parent ) override;
@@ -32,6 +32,14 @@ QVariant QgsColorWidgetWrapper::value() const
return v;
}

void QgsColorWidgetWrapper::showIndeterminateState()
{
if ( mColorButton )
{
whileBlocking( mColorButton )->setColor( QColor() );
}
}

QWidget* QgsColorWidgetWrapper::createWidget( QWidget* parent )
{
QgsColorButtonV2* button = new QgsColorButtonV2( parent );
@@ -35,6 +35,7 @@ class GUI_EXPORT QgsColorWidgetWrapper : public QgsEditorWidgetWrapper
// QgsEditorWidgetWrapper interface
public:
QVariant value() const override;
void showIndeterminateState() override;

protected:
QWidget* createWidget( QWidget* parent ) override;
@@ -35,6 +35,14 @@ QVariant QgsEnumerationWidgetWrapper::value() const
return value;
}

void QgsEnumerationWidgetWrapper::showIndeterminateState()
{
if ( mComboBox )
{
whileBlocking( mComboBox )->setCurrentIndex( -1 );
}
}

QWidget* QgsEnumerationWidgetWrapper::createWidget( QWidget* parent )
{
return new QComboBox( parent );
@@ -33,6 +33,7 @@ class GUI_EXPORT QgsEnumerationWidgetWrapper : public QgsEditorWidgetWrapper
// QgsEditorWidgetWrapper interface
public:
QVariant value() const override;
void showIndeterminateState() override;

protected:
QWidget* createWidget( QWidget* parent ) override;
@@ -54,6 +54,24 @@ QVariant QgsExternalResourceWidgetWrapper::value() const
return QVariant( field().type() );
}

void QgsExternalResourceWidgetWrapper::showIndeterminateState()
{
if ( mLineEdit )
{
whileBlocking( mLineEdit )->clear();
}

if ( mLabel )
{
mLabel->clear();
}

if ( mQgsWidget )
{
whileBlocking( mQgsWidget )->setDocumentPath( QString() );
}
}

bool QgsExternalResourceWidgetWrapper::valid() const
{
return mLineEdit || mLabel || mQgsWidget;
@@ -42,6 +42,7 @@ class GUI_EXPORT QgsExternalResourceWidgetWrapper : public QgsEditorWidgetWrappe
// QgsEditorWidgetWrapper interface
public:
QVariant value() const override;
void showIndeterminateState() override;

protected:
QWidget* createWidget( QWidget* parent ) override;
@@ -53,6 +53,17 @@ bool QgsFileNameWidgetWrapper::valid() const
return mLineEdit || mLabel;
}

void QgsFileNameWidgetWrapper::showIndeterminateState()
{
if ( mLineEdit )
{
whileBlocking( mLineEdit )->clear();
}

if ( mLabel )
mLabel->clear();
}

QWidget* QgsFileNameWidgetWrapper::createWidget( QWidget* parent )
{
QWidget* container = new QWidget( parent );
@@ -41,6 +41,7 @@ class GUI_EXPORT QgsFileNameWidgetWrapper : public QgsEditorWidgetWrapper
public:
QVariant value() const override;
bool valid() const override;
void showIndeterminateState() override;

protected:
QWidget* createWidget( QWidget* parent ) override;
@@ -115,6 +115,18 @@ QVariant QgsPhotoWidgetWrapper::value() const
return v;
}

void QgsPhotoWidgetWrapper::showIndeterminateState()
{
if ( mLineEdit )
{
whileBlocking( mLineEdit )->clear();
}
if ( mPhotoLabel )
mPhotoLabel->clear();
if ( mPhotoPixmapLabel )
mPhotoPixmapLabel->clear();
}

QWidget* QgsPhotoWidgetWrapper::createWidget( QWidget* parent )
{
QWidget* container = new QWidget( parent );
@@ -49,6 +49,7 @@ class GUI_EXPORT QgsPhotoWidgetWrapper : public QgsEditorWidgetWrapper
// QgsEditorWidgetWrapper interface
public:
QVariant value() const override;
void showIndeterminateState() override;

protected:
QWidget* createWidget( QWidget* parent ) override;
@@ -346,6 +346,20 @@ QgsFeature QgsRelationReferenceWidget::referencedFeature()
return f;
}

void QgsRelationReferenceWidget::showIndeterminateState()
{
if ( mReadOnlySelector )
{
whileBlocking( mLineEdit )->setText( QString() );
}
else
{
whileBlocking( mComboBox )->setCurrentIndex( -1 );
}
mRemoveFKButton->setEnabled( false );
updateAttributeEditorFrame( QgsFeature() );
}

QVariant QgsRelationReferenceWidget::foreignKey()
{
if ( mReadOnlySelector )
@@ -108,6 +108,11 @@ class GUI_EXPORT QgsRelationReferenceWidget : public QWidget
//! if no feature is related, it returns an invalid feature
QgsFeature referencedFeature();

/** Sets the widget to display in an indeterminate "mixed value" state.
* @note added in QGIS 2.16
*/
void showIndeterminateState();

public slots:
//! open the form of the related feature in a new dialog
void openForm();
@@ -24,6 +24,7 @@ QgsRelationReferenceWidgetWrapper::QgsRelationReferenceWidgetWrapper( QgsVectorL
, mWidget( nullptr )
, mCanvas( canvas )
, mMessageBar( messageBar )
, mIndeterminateState( false )
{
}

@@ -103,11 +104,21 @@ bool QgsRelationReferenceWidgetWrapper::valid() const
return mWidget;
}

void QgsRelationReferenceWidgetWrapper::showIndeterminateState()
{
if ( mWidget )
{
mWidget->showIndeterminateState();
}
mIndeterminateState = true;
}

void QgsRelationReferenceWidgetWrapper::setValue( const QVariant& val )
{
if ( !mWidget || val == value() )
if ( !mWidget || ( !mIndeterminateState && val == value() ) )
return;

mIndeterminateState = false;
mWidget->setForeignKey( val );
}

@@ -50,6 +50,7 @@ class GUI_EXPORT QgsRelationReferenceWidgetWrapper : public QgsEditorWidgetWrapp
virtual void initWidget( QWidget* editor ) override;
virtual QVariant value() const override;
bool valid() const override;
void showIndeterminateState() override;

public slots:
virtual void setValue( const QVariant& value ) override;
@@ -62,6 +63,7 @@ class GUI_EXPORT QgsRelationReferenceWidgetWrapper : public QgsEditorWidgetWrapp
QgsRelationReferenceWidget* mWidget;
QgsMapCanvas* mCanvas;
QgsMessageBar* mMessageBar;
bool mIndeterminateState;
};

#endif // QGSRELATIONREFERENCEWIDGETWRAPPER_H
@@ -135,7 +135,50 @@ bool QgsTextEditWrapper::valid() const
return mLineEdit || mTextEdit || mPlainTextEdit;
}

void QgsTextEditWrapper::showIndeterminateState()
{
//note - this is deliberately a zero length string, not a null string!
if ( mTextEdit )
mTextEdit->blockSignals( true );
if ( mPlainTextEdit )
mPlainTextEdit->blockSignals( true );
if ( mLineEdit )
mLineEdit->blockSignals( true );

setWidgetValue( QString( "" ) );

if ( mTextEdit )
mTextEdit->blockSignals( false );
if ( mPlainTextEdit )
mPlainTextEdit->blockSignals( false );
if ( mLineEdit )
mLineEdit->blockSignals( false );
}

void QgsTextEditWrapper::setValue( const QVariant& val )
{
setWidgetValue( val );
}

void QgsTextEditWrapper::setEnabled( bool enabled )
{
if ( mTextEdit )
mTextEdit->setReadOnly( !enabled );

if ( mPlainTextEdit )
mPlainTextEdit->setReadOnly( !enabled );

if ( mLineEdit )
{
mLineEdit->setReadOnly( !enabled );
if ( enabled )
mLineEdit->setPalette( mWritablePalette );
else
mLineEdit->setPalette( mReadOnlyPalette );
}
}

void QgsTextEditWrapper::setWidgetValue( const QVariant& val )
{
QString v;
if ( val.isNull() )
@@ -166,21 +209,3 @@ void QgsTextEditWrapper::setValue( const QVariant& val )
if ( mLineEdit )
mLineEdit->setText( v );
}

void QgsTextEditWrapper::setEnabled( bool enabled )
{
if ( mTextEdit )
mTextEdit->setReadOnly( !enabled );

if ( mPlainTextEdit )
mPlainTextEdit->setReadOnly( !enabled );

if ( mLineEdit )
{
mLineEdit->setReadOnly( !enabled );
if ( enabled )
mLineEdit->setPalette( mWritablePalette );
else
mLineEdit->setPalette( mReadOnlyPalette );
}
}
@@ -42,6 +42,7 @@ class GUI_EXPORT QgsTextEditWrapper : public QgsEditorWidgetWrapper
// QgsEditorWidgetWrapper interface
public:
QVariant value() const override;
void showIndeterminateState() override;

protected:
QWidget*createWidget( QWidget* parent ) override;
@@ -58,6 +59,8 @@ class GUI_EXPORT QgsTextEditWrapper : public QgsEditorWidgetWrapper
QLineEdit* mLineEdit;
QPalette mReadOnlyPalette;
QPalette mWritablePalette;

void setWidgetValue( const QVariant& value );
};

#endif // QGSTEXTEDITWRAPPER_H

0 comments on commit 22f1a1d

Please sign in to comment.
You can’t perform that action at this time.