Skip to content

Commit d971a69

Browse files
committedApr 1, 2013
sneak in color edit widget to accompany data defined symbology
1 parent 1bfb7ed commit d971a69

9 files changed

+120
-10
lines changed
 

‎src/app/qgsattributetypedialog.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@ void QgsAttributeTypeDialog::setPageForEditType( QgsVectorLayer::EditType editTy
338338
case QgsVectorLayer::Webview:
339339
setPage( 15 );
340340
break;
341+
342+
case QgsVectorLayer::Color:
343+
setPage( 16 );
344+
break;
341345
}
342346
}
343347

@@ -524,6 +528,7 @@ void QgsAttributeTypeDialog::setIndex( int index, QgsVectorLayer::EditType editT
524528
case QgsVectorLayer::TextEdit:
525529
case QgsVectorLayer::UuidGenerator:
526530
case QgsVectorLayer::Webview:
531+
case QgsVectorLayer::Color:
527532
break;
528533
}
529534
}
@@ -699,6 +704,9 @@ void QgsAttributeTypeDialog::accept()
699704
case 15:
700705
mEditType = QgsVectorLayer::Webview;
701706
break;
707+
case 16:
708+
mEditType = QgsVectorLayer::Color;
709+
break;
702710
}
703711

704712
QDialog::accept();

‎src/app/qgsfieldsproperties.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ void QgsFieldsProperties::attributeTypeDialog()
535535
case QgsVectorLayer::Hidden:
536536
case QgsVectorLayer::UuidGenerator:
537537
case QgsVectorLayer::Webview:
538+
case QgsVectorLayer::Color:
538539
break;
539540
}
540541

@@ -746,6 +747,7 @@ void QgsFieldsProperties::setupEditTypes()
746747
editTypeMap.insert( QgsVectorLayer::UuidGenerator, tr( "UUID generator" ) );
747748
editTypeMap.insert( QgsVectorLayer::Photo, tr( "Photo" ) );
748749
editTypeMap.insert( QgsVectorLayer::Webview, tr( "Webview" ) );
750+
editTypeMap.insert( QgsVectorLayer::Color, tr( "Color" ) );
749751
}
750752

751753
QString QgsFieldsProperties::editTypeButtonText( QgsVectorLayer::EditType type )
@@ -891,6 +893,7 @@ void QgsFieldsProperties::apply()
891893
case QgsVectorLayer::TextEdit:
892894
case QgsVectorLayer::UuidGenerator:
893895
case QgsVectorLayer::Webview:
896+
case QgsVectorLayer::Color:
894897
break;
895898
}
896899

‎src/core/qgsvectorlayer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,6 +2425,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
24252425
case UniqueValuesEditable:
24262426
case UuidGenerator:
24272427
case Webview:
2428+
case Color:
24282429
break;
24292430
}
24302431
}
@@ -2750,6 +2751,7 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
27502751
case Immutable:
27512752
case UuidGenerator:
27522753
case Webview:
2754+
case Color:
27532755
break;
27542756
}
27552757

‎src/core/qgsvectorlayer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
179179
UuidGenerator, /* uuid generator - readonly and automatically intialized @added in 1.9 */
180180
Photo, /* phote widget @added in 1.9 */
181181
Webview, /* webview widget @added in 1.9 */
182+
Color, /* color @added in 1.9 */
182183
};
183184

184185
struct RangeData

‎src/core/symbology-ng/qgsfillsymbollayerv2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2134,7 +2134,7 @@ const QgsExpression* QgsPointPatternFillSymbolLayer::dataDefinedProperty( const
21342134
QString QgsPointPatternFillSymbolLayer::dataDefinedPropertyString( const QString& property ) const
21352135
{
21362136
const QgsExpression* ex = dataDefinedProperty( property );
2137-
return ( ex ? ex->dump() : QString() );
2137+
return ex ? ex->dump() : QString();
21382138
}
21392139

21402140
void QgsPointPatternFillSymbolLayer::setDataDefinedProperty( const QString& property, const QString& expressionString )

‎src/gui/qgsattributeeditor.cpp

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <qgslogger.h>
2828
#include <qgsexpression.h>
2929
#include <qgsfilterlineedit.h>
30+
#include <qgscolorbutton.h>
3031

3132
#include <QScrollArea>
3233
#include <QPushButton>
@@ -187,6 +188,42 @@ void QgsAttributeEditor::updateUrl()
187188
le->blockSignals( false );
188189
}
189190

191+
void QgsAttributeEditor::updateColor()
192+
{
193+
QString color;
194+
QgsColorButton *scb = qobject_cast<QgsColorButton *>( sender() );
195+
QLineEdit *sle = qobject_cast<QLineEdit *>( sender() );
196+
197+
if ( !scb && !sle )
198+
return;
199+
200+
QWidget *hbox = qobject_cast<QWidget *>( sender()->parent() );
201+
if ( !hbox )
202+
return;
203+
204+
QgsColorButton *cb = hbox->findChild<QgsColorButton *>();
205+
if ( !cb )
206+
return;
207+
208+
QLineEdit *le = hbox->findChild<QLineEdit *>();
209+
if ( !le )
210+
return;
211+
212+
if ( scb )
213+
{
214+
le->blockSignals( true );
215+
le->setText( scb->color().name() );
216+
le->blockSignals( false );
217+
}
218+
219+
if ( sle )
220+
{
221+
cb->blockSignals( true );
222+
cb->setColor( QColor( sle->text() ) );
223+
cb->blockSignals( false );
224+
}
225+
}
226+
190227
QComboBox *QgsAttributeEditor::comboBox( QWidget *editor, QWidget *parent )
191228
{
192229
QComboBox *cb = 0;
@@ -672,6 +709,7 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
672709
case QgsVectorLayer::Calendar:
673710
case QgsVectorLayer::Photo:
674711
case QgsVectorLayer::Webview:
712+
case QgsVectorLayer::Color:
675713
{
676714
QCalendarWidget *cw = qobject_cast<QCalendarWidget *>( editor );
677715
if ( cw )
@@ -694,6 +732,13 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
694732
break;
695733
}
696734

735+
QgsColorButton *cb = qobject_cast<QgsColorButton *>( editor );
736+
if ( cb )
737+
{
738+
myWidget = cb;
739+
break;
740+
}
741+
697742
QPushButton *pb = 0;
698743
QLineEdit *le = qobject_cast<QLineEdit *>( editor );
699744
if ( le )
@@ -709,10 +754,24 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
709754
else
710755
{
711756
le = new QgsFilterLineEdit();
712-
if ( editType == QgsVectorLayer::FileName || editType == QgsVectorLayer::Photo )
713-
pb = new QPushButton( tr( "..." ) );
714-
else
715-
pb = new QPushButton( tr( "<" ) );
757+
switch ( editType )
758+
{
759+
case QgsVectorLayer::FileName:
760+
case QgsVectorLayer::Photo:
761+
pb = new QPushButton( tr( "..." ) );
762+
break;
763+
764+
case QgsVectorLayer::Webview:
765+
pb = new QPushButton( tr( "<" ) );
766+
break;
767+
768+
case QgsVectorLayer::Color:
769+
pb = new QgsColorButton();
770+
break;
771+
772+
default:
773+
break;
774+
}
716775

717776
int row = 0;
718777
QGridLayout *layout = new QGridLayout();
@@ -746,6 +805,8 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
746805
connect( le, SIGNAL( textChanged( const QString & ) ), new QgsAttributeEditor( le, vl, idx ), SLOT( loadUrl( const QString & ) ) );
747806
if ( lw )
748807
connect( le, SIGNAL( textChanged( const QString & ) ), new QgsAttributeEditor( le, vl, idx ), SLOT( loadPixmap( const QString & ) ) );
808+
if ( editType == QgsVectorLayer::Color )
809+
connect( le, SIGNAL( textChanged( const QString & ) ), new QgsAttributeEditor( le ), SLOT( updateColor() ) );
749810
}
750811

751812
if ( pb )
@@ -756,6 +817,8 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
756817
connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( updateUrl() ) );
757818
if ( editType == QgsVectorLayer::Calendar )
758819
connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( selectDate() ) );
820+
if ( editType == QgsVectorLayer::Color )
821+
connect( pb, SIGNAL( colorChanged( const QColor & ) ), new QgsAttributeEditor( pb ), SLOT( updateColor() ) );
759822
}
760823
}
761824
break;
@@ -1135,6 +1198,7 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx,
11351198
case QgsVectorLayer::Calendar:
11361199
case QgsVectorLayer::Photo:
11371200
case QgsVectorLayer::Webview:
1201+
case QgsVectorLayer::Color:
11381202
{
11391203
QCalendarWidget *cw = qobject_cast<QCalendarWidget *>( editor );
11401204
if ( cw )
@@ -1152,8 +1216,12 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx,
11521216

11531217
QLabel *lw = qobject_cast<QLabel *>( editor );
11541218
if ( lw )
1155-
{
1219+
break;
11561220

1221+
QgsColorButton *cb = qobject_cast<QgsColorButton *>( editor );
1222+
if ( cb )
1223+
{
1224+
cb->setColor( QColor( value.toString() ) );
11571225
break;
11581226
}
11591227

@@ -1165,9 +1233,7 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx,
11651233
fle = qobject_cast<QgsFilterLineEdit *>( le );
11661234
}
11671235
if ( !le )
1168-
{
11691236
return false;
1170-
}
11711237

11721238
if ( fle && !( myFieldType == QVariant::Int || myFieldType == QVariant::Double || myFieldType == QVariant::LongLong || myFieldType == QVariant::Date ) )
11731239
{

‎src/gui/qgsattributeeditor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class GUI_EXPORT QgsAttributeEditor : public QObject
8585
void loadUrl( const QString & );
8686
void loadPixmap( const QString & );
8787
void updateUrl();
88+
void updateColor();
8889

8990
private:
9091
QgsVectorLayer *mLayer;

‎src/gui/qgscolorbutton.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void QgsColorButton::setColor( const QColor &color )
140140
{
141141
// TODO: May be beneficial to have the option to set color without emitting this signal.
142142
// Now done by blockSignals( bool ) where button is used
143-
emit( colorChanged( mColor ) );
143+
emit colorChanged( mColor );
144144
}
145145
}
146146
}

‎src/ui/qgsattributetypeedit.ui

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@
106106
<string>Webview</string>
107107
</property>
108108
</item>
109+
<item>
110+
<property name="text">
111+
<string>Color</string>
112+
</property>
113+
</item>
109114
</widget>
110115
</item>
111116
<item row="0" column="1">
@@ -127,7 +132,7 @@
127132
</sizepolicy>
128133
</property>
129134
<property name="currentIndex">
130-
<number>15</number>
135+
<number>16</number>
131136
</property>
132137
<widget class="QWidget" name="lineEditPage">
133138
<layout class="QVBoxLayout" name="verticalLayout_1">
@@ -863,6 +868,30 @@
863868
</item>
864869
</layout>
865870
</widget>
871+
<widget class="QWidget" name="page_3">
872+
<layout class="QVBoxLayout" name="verticalLayout_6">
873+
<item>
874+
<widget class="QLabel" name="label_15">
875+
<property name="text">
876+
<string>Field contains a color</string>
877+
</property>
878+
</widget>
879+
</item>
880+
<item>
881+
<spacer name="verticalSpacer_14">
882+
<property name="orientation">
883+
<enum>Qt::Vertical</enum>
884+
</property>
885+
<property name="sizeHint" stdset="0">
886+
<size>
887+
<width>20</width>
888+
<height>320</height>
889+
</size>
890+
</property>
891+
</spacer>
892+
</item>
893+
</layout>
894+
</widget>
866895
</widget>
867896
</item>
868897
</layout>

0 commit comments

Comments
 (0)
Please sign in to comment.