From d971a693299ca0c4ebc310d3dbfe44bbb00d686d Mon Sep 17 00:00:00 2001 From: "Juergen E. Fischer" Date: Mon, 1 Apr 2013 17:52:39 +0200 Subject: [PATCH] sneak in color edit widget to accompany data defined symbology --- src/app/qgsattributetypedialog.cpp | 8 ++ src/app/qgsfieldsproperties.cpp | 3 + src/core/qgsvectorlayer.cpp | 2 + src/core/qgsvectorlayer.h | 1 + .../symbology-ng/qgsfillsymbollayerv2.cpp | 2 +- src/gui/qgsattributeeditor.cpp | 80 +++++++++++++++++-- src/gui/qgsattributeeditor.h | 1 + src/gui/qgscolorbutton.cpp | 2 +- src/ui/qgsattributetypeedit.ui | 31 ++++++- 9 files changed, 120 insertions(+), 10 deletions(-) diff --git a/src/app/qgsattributetypedialog.cpp b/src/app/qgsattributetypedialog.cpp index 1ab9aa4c71a..283632898cb 100644 --- a/src/app/qgsattributetypedialog.cpp +++ b/src/app/qgsattributetypedialog.cpp @@ -338,6 +338,10 @@ void QgsAttributeTypeDialog::setPageForEditType( QgsVectorLayer::EditType editTy case QgsVectorLayer::Webview: setPage( 15 ); break; + + case QgsVectorLayer::Color: + setPage( 16 ); + break; } } @@ -524,6 +528,7 @@ void QgsAttributeTypeDialog::setIndex( int index, QgsVectorLayer::EditType editT case QgsVectorLayer::TextEdit: case QgsVectorLayer::UuidGenerator: case QgsVectorLayer::Webview: + case QgsVectorLayer::Color: break; } } @@ -699,6 +704,9 @@ void QgsAttributeTypeDialog::accept() case 15: mEditType = QgsVectorLayer::Webview; break; + case 16: + mEditType = QgsVectorLayer::Color; + break; } QDialog::accept(); diff --git a/src/app/qgsfieldsproperties.cpp b/src/app/qgsfieldsproperties.cpp index bfbe53b8246..d00dafa6ccb 100644 --- a/src/app/qgsfieldsproperties.cpp +++ b/src/app/qgsfieldsproperties.cpp @@ -535,6 +535,7 @@ void QgsFieldsProperties::attributeTypeDialog() case QgsVectorLayer::Hidden: case QgsVectorLayer::UuidGenerator: case QgsVectorLayer::Webview: + case QgsVectorLayer::Color: break; } @@ -746,6 +747,7 @@ void QgsFieldsProperties::setupEditTypes() editTypeMap.insert( QgsVectorLayer::UuidGenerator, tr( "UUID generator" ) ); editTypeMap.insert( QgsVectorLayer::Photo, tr( "Photo" ) ); editTypeMap.insert( QgsVectorLayer::Webview, tr( "Webview" ) ); + editTypeMap.insert( QgsVectorLayer::Color, tr( "Color" ) ); } QString QgsFieldsProperties::editTypeButtonText( QgsVectorLayer::EditType type ) @@ -891,6 +893,7 @@ void QgsFieldsProperties::apply() case QgsVectorLayer::TextEdit: case QgsVectorLayer::UuidGenerator: case QgsVectorLayer::Webview: + case QgsVectorLayer::Color: break; } diff --git a/src/core/qgsvectorlayer.cpp b/src/core/qgsvectorlayer.cpp index 6fbae9ad21a..f81aff5a100 100644 --- a/src/core/qgsvectorlayer.cpp +++ b/src/core/qgsvectorlayer.cpp @@ -2425,6 +2425,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage case UniqueValuesEditable: case UuidGenerator: case Webview: + case Color: break; } } @@ -2750,6 +2751,7 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString& case Immutable: case UuidGenerator: case Webview: + case Color: break; } diff --git a/src/core/qgsvectorlayer.h b/src/core/qgsvectorlayer.h index 55c8f660e3f..c59417207f7 100644 --- a/src/core/qgsvectorlayer.h +++ b/src/core/qgsvectorlayer.h @@ -179,6 +179,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer UuidGenerator, /* uuid generator - readonly and automatically intialized @added in 1.9 */ Photo, /* phote widget @added in 1.9 */ Webview, /* webview widget @added in 1.9 */ + Color, /* color @added in 1.9 */ }; struct RangeData diff --git a/src/core/symbology-ng/qgsfillsymbollayerv2.cpp b/src/core/symbology-ng/qgsfillsymbollayerv2.cpp index 1c2b1459510..9d56d795fe6 100644 --- a/src/core/symbology-ng/qgsfillsymbollayerv2.cpp +++ b/src/core/symbology-ng/qgsfillsymbollayerv2.cpp @@ -2134,7 +2134,7 @@ const QgsExpression* QgsPointPatternFillSymbolLayer::dataDefinedProperty( const QString QgsPointPatternFillSymbolLayer::dataDefinedPropertyString( const QString& property ) const { const QgsExpression* ex = dataDefinedProperty( property ); - return ( ex ? ex->dump() : QString() ); + return ex ? ex->dump() : QString(); } void QgsPointPatternFillSymbolLayer::setDataDefinedProperty( const QString& property, const QString& expressionString ) diff --git a/src/gui/qgsattributeeditor.cpp b/src/gui/qgsattributeeditor.cpp index bf5240a1d7e..50100716208 100644 --- a/src/gui/qgsattributeeditor.cpp +++ b/src/gui/qgsattributeeditor.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -187,6 +188,42 @@ void QgsAttributeEditor::updateUrl() le->blockSignals( false ); } +void QgsAttributeEditor::updateColor() +{ + QString color; + QgsColorButton *scb = qobject_cast( sender() ); + QLineEdit *sle = qobject_cast( sender() ); + + if ( !scb && !sle ) + return; + + QWidget *hbox = qobject_cast( sender()->parent() ); + if ( !hbox ) + return; + + QgsColorButton *cb = hbox->findChild(); + if ( !cb ) + return; + + QLineEdit *le = hbox->findChild(); + if ( !le ) + return; + + if ( scb ) + { + le->blockSignals( true ); + le->setText( scb->color().name() ); + le->blockSignals( false ); + } + + if ( sle ) + { + cb->blockSignals( true ); + cb->setColor( QColor( sle->text() ) ); + cb->blockSignals( false ); + } +} + QComboBox *QgsAttributeEditor::comboBox( QWidget *editor, QWidget *parent ) { QComboBox *cb = 0; @@ -672,6 +709,7 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed case QgsVectorLayer::Calendar: case QgsVectorLayer::Photo: case QgsVectorLayer::Webview: + case QgsVectorLayer::Color: { QCalendarWidget *cw = qobject_cast( editor ); if ( cw ) @@ -694,6 +732,13 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed break; } + QgsColorButton *cb = qobject_cast( editor ); + if ( cb ) + { + myWidget = cb; + break; + } + QPushButton *pb = 0; QLineEdit *le = qobject_cast( editor ); if ( le ) @@ -709,10 +754,24 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed else { le = new QgsFilterLineEdit(); - if ( editType == QgsVectorLayer::FileName || editType == QgsVectorLayer::Photo ) - pb = new QPushButton( tr( "..." ) ); - else - pb = new QPushButton( tr( "<" ) ); + switch ( editType ) + { + case QgsVectorLayer::FileName: + case QgsVectorLayer::Photo: + pb = new QPushButton( tr( "..." ) ); + break; + + case QgsVectorLayer::Webview: + pb = new QPushButton( tr( "<" ) ); + break; + + case QgsVectorLayer::Color: + pb = new QgsColorButton(); + break; + + default: + break; + } int row = 0; QGridLayout *layout = new QGridLayout(); @@ -746,6 +805,8 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed connect( le, SIGNAL( textChanged( const QString & ) ), new QgsAttributeEditor( le, vl, idx ), SLOT( loadUrl( const QString & ) ) ); if ( lw ) connect( le, SIGNAL( textChanged( const QString & ) ), new QgsAttributeEditor( le, vl, idx ), SLOT( loadPixmap( const QString & ) ) ); + if ( editType == QgsVectorLayer::Color ) + connect( le, SIGNAL( textChanged( const QString & ) ), new QgsAttributeEditor( le ), SLOT( updateColor() ) ); } if ( pb ) @@ -756,6 +817,8 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( updateUrl() ) ); if ( editType == QgsVectorLayer::Calendar ) connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( selectDate() ) ); + if ( editType == QgsVectorLayer::Color ) + connect( pb, SIGNAL( colorChanged( const QColor & ) ), new QgsAttributeEditor( pb ), SLOT( updateColor() ) ); } } break; @@ -1135,6 +1198,7 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx, case QgsVectorLayer::Calendar: case QgsVectorLayer::Photo: case QgsVectorLayer::Webview: + case QgsVectorLayer::Color: { QCalendarWidget *cw = qobject_cast( editor ); if ( cw ) @@ -1152,8 +1216,12 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx, QLabel *lw = qobject_cast( editor ); if ( lw ) - { + break; + QgsColorButton *cb = qobject_cast( editor ); + if ( cb ) + { + cb->setColor( QColor( value.toString() ) ); break; } @@ -1165,9 +1233,7 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx, fle = qobject_cast( le ); } if ( !le ) - { return false; - } if ( fle && !( myFieldType == QVariant::Int || myFieldType == QVariant::Double || myFieldType == QVariant::LongLong || myFieldType == QVariant::Date ) ) { diff --git a/src/gui/qgsattributeeditor.h b/src/gui/qgsattributeeditor.h index 681157ede64..d652e85d057 100644 --- a/src/gui/qgsattributeeditor.h +++ b/src/gui/qgsattributeeditor.h @@ -85,6 +85,7 @@ class GUI_EXPORT QgsAttributeEditor : public QObject void loadUrl( const QString & ); void loadPixmap( const QString & ); void updateUrl(); + void updateColor(); private: QgsVectorLayer *mLayer; diff --git a/src/gui/qgscolorbutton.cpp b/src/gui/qgscolorbutton.cpp index 47be78eaad0..73ab54f6beb 100644 --- a/src/gui/qgscolorbutton.cpp +++ b/src/gui/qgscolorbutton.cpp @@ -140,7 +140,7 @@ void QgsColorButton::setColor( const QColor &color ) { // TODO: May be beneficial to have the option to set color without emitting this signal. // Now done by blockSignals( bool ) where button is used - emit( colorChanged( mColor ) ); + emit colorChanged( mColor ); } } } diff --git a/src/ui/qgsattributetypeedit.ui b/src/ui/qgsattributetypeedit.ui index fab4d7b72a5..eb9b24de6db 100644 --- a/src/ui/qgsattributetypeedit.ui +++ b/src/ui/qgsattributetypeedit.ui @@ -106,6 +106,11 @@ Webview + + + Color + + @@ -127,7 +132,7 @@ - 15 + 16 @@ -863,6 +868,30 @@ + + + + + + Field contains a color + + + + + + + Qt::Vertical + + + + 20 + 320 + + + + + +