Skip to content

Commit b875fe0

Browse files
committedNov 17, 2012
allow to convert cpt-city ramps to standard gradients ramps, keeping author and license info in xml props ; allow to convert gradient ramps to/from discrete/continuous ramps and use float instead of integer stops
1 parent 31c11ed commit b875fe0

11 files changed

+356
-58
lines changed
 

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ QString QgsCptCityArchive::descFileName( const QString& path ) const
157157
baseDir() + QDir::separator() + path, baseDir() );
158158
}
159159

160-
QMap< QString, QString > QgsCptCityArchive::copyingInfo( const QString& fileName )
160+
QgsStringMap QgsCptCityArchive::copyingInfo( const QString& fileName )
161161
{
162-
QMap< QString, QString > copyingMap;
162+
QgsStringMap copyingMap;
163163

164164
if ( fileName.isNull() )
165165
return copyingMap;
@@ -258,9 +258,9 @@ QMap< QString, QString > QgsCptCityArchive::copyingInfo( const QString& fileName
258258
return copyingMap;
259259
}
260260

261-
QMap< QString, QString > QgsCptCityArchive::description( const QString& fileName )
261+
QgsStringMap QgsCptCityArchive::description( const QString& fileName )
262262
{
263-
QMap< QString, QString > descMap;
263+
QgsStringMap descMap;
264264

265265
QgsDebugMsg( "description fileName = " + fileName );
266266

@@ -435,7 +435,7 @@ void QgsCptCityArchive::initDefaultArchive()
435435

436436
void QgsCptCityArchive::initArchives( bool loadAll )
437437
{
438-
QMap< QString, QString > archivesMap;
438+
QgsStringMap archivesMap;
439439
QString baseDir, defArchiveName;
440440
QSettings settings;
441441

@@ -460,7 +460,7 @@ void QgsCptCityArchive::initArchives( bool loadAll )
460460
archivesMap[ defArchiveName ] = baseDir + QDir::separator() + defArchiveName;
461461
}
462462

463-
for ( QMap< QString, QString >::iterator it = archivesMap.begin();
463+
for ( QgsStringMap::iterator it = archivesMap.begin();
464464
it != archivesMap.end(); ++it )
465465
{
466466
if ( QDir( it.value() ).exists() )
@@ -871,7 +871,7 @@ QgsCptCityDirectoryItem::QgsCptCityDirectoryItem( QgsCptCityDataItem* parent,
871871
mInfo = "";
872872
QString fileName = QgsCptCityArchive::defaultBaseDir() + QDir::separator() + \
873873
mPath + QDir::separator() + "DESC.xml";
874-
QMap< QString, QString > descMap = QgsCptCityArchive::description( fileName );
874+
QgsStringMap descMap = QgsCptCityArchive::description( fileName );
875875
if ( descMap.contains( "name" ) )
876876
mInfo = descMap.value( "name" );
877877

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

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,15 @@ QgsVectorGradientColorRampV2::QgsVectorGradientColorRampV2( QColor color1, QColo
4646

4747
QgsVectorColorRampV2* QgsVectorGradientColorRampV2::create( const QgsStringMap& props )
4848
{
49+
// color1 and color2
4950
QColor color1 = DEFAULT_GRADIENT_COLOR1;
5051
QColor color2 = DEFAULT_GRADIENT_COLOR2;
5152
if ( props.contains( "color1" ) )
5253
color1 = QgsSymbolLayerV2Utils::decodeColor( props["color1"] );
5354
if ( props.contains( "color2" ) )
5455
color2 = QgsSymbolLayerV2Utils::decodeColor( props["color2"] );
5556

57+
//stops
5658
QgsGradientStopsList stops;
5759
if ( props.contains( "stops" ) )
5860
{
@@ -66,14 +68,26 @@ QgsVectorColorRampV2* QgsVectorGradientColorRampV2::create( const QgsStringMap&
6668
stops.append( QgsGradientStop( stop.left( i ).toDouble(), c ) );
6769
}
6870
}
71+
72+
// discrete vs. continuous
6973
bool discrete = false;
7074
if ( props.contains( "discrete" ) )
7175
{
7276
if ( props["discrete"] == "1" )
7377
discrete = true;
7478
}
7579

80+
// search for information keys starting with "info_"
81+
QgsStringMap info;
82+
for ( QgsStringMap::const_iterator it = props.constBegin();
83+
it != props.constEnd(); ++it )
84+
{
85+
if ( it.key().startsWith( "info_" ) )
86+
info[ it.key().mid( 5 )] = it.value();
87+
}
88+
7689
QgsVectorGradientColorRampV2* r = new QgsVectorGradientColorRampV2( color1, color2, discrete, stops );
90+
r->setInfo( info );
7791
return r;
7892
}
7993

@@ -118,6 +132,7 @@ QgsVectorColorRampV2* QgsVectorGradientColorRampV2::clone() const
118132
{
119133
QgsVectorGradientColorRampV2* r = new QgsVectorGradientColorRampV2( mColor1, mColor2,
120134
mDiscrete, mStops );
135+
r->setInfo( mInfo );
121136
return r;
122137
}
123138

@@ -135,10 +150,58 @@ QgsStringMap QgsVectorGradientColorRampV2::properties() const
135150
}
136151
map["stops"] = lst.join( ":" );
137152
}
153+
138154
map["discrete"] = mDiscrete ? "1" : "0";
155+
156+
for ( QgsStringMap::const_iterator it = mInfo.constBegin();
157+
it != mInfo.constEnd(); ++it )
158+
{
159+
map["info_" + it.key()] = it.value();
160+
}
161+
139162
return map;
140163
}
164+
void QgsVectorGradientColorRampV2::convertToDiscrete( bool discrete )
165+
{
166+
if ( discrete == mDiscrete )
167+
return;
141168

169+
// if going to/from Discrete, re-arrange stops
170+
// this will only work when stops are equally-spaced
171+
QgsGradientStopsList newStops;
172+
if ( discrete )
173+
{
174+
// re-arrange stops offset
175+
int numStops = mStops.count() + 2;
176+
int i = 1;
177+
for ( QgsGradientStopsList::const_iterator it = mStops.begin();
178+
it != mStops.end(); ++it )
179+
{
180+
newStops.append( QgsGradientStop(( double ) i / numStops, it->color ) );
181+
if ( i == numStops - 1 )
182+
break;
183+
i++;
184+
}
185+
// replicate last color
186+
newStops.append( QgsGradientStop(( double ) i / numStops, mColor2 ) );
187+
}
188+
else
189+
{
190+
// re-arrange stops offset, remove duplicate last color
191+
int numStops = mStops.count() + 2;
192+
int i = 1;
193+
for ( QgsGradientStopsList::const_iterator it = mStops.begin();
194+
it != mStops.end(); ++it )
195+
{
196+
newStops.append( QgsGradientStop(( double ) i / ( numStops - 2 ), it->color ) );
197+
if ( i == numStops - 3 )
198+
break;
199+
i++;
200+
}
201+
}
202+
mStops = newStops;
203+
mDiscrete = discrete;
204+
}
142205

143206
//////////////
144207

@@ -337,6 +400,20 @@ void QgsCptCityColorRampV2::copy( const QgsCptCityColorRampV2* other )
337400
mFileLoaded = other->mFileLoaded;
338401
}
339402

403+
QgsVectorGradientColorRampV2* QgsCptCityColorRampV2::cloneGradientRamp() const
404+
{
405+
QgsVectorGradientColorRampV2* ramp =
406+
new QgsVectorGradientColorRampV2( mColor1, mColor2, mDiscrete, mStops );
407+
// add author and copyright information
408+
// TODO also add COPYING.xml file/link?
409+
QgsStringMap info = copyingInfo();
410+
info["source"] = "cpt-city archive - " + mSchemeName + mVariantName + ".svg";
411+
info["license/file"] = copyingFileName();
412+
ramp->setInfo( info );
413+
return ramp;
414+
}
415+
416+
340417
QgsStringMap QgsCptCityColorRampV2::properties() const
341418
{
342419
QgsStringMap map;
@@ -368,7 +445,7 @@ QString QgsCptCityColorRampV2::descFileName() const
368445
QgsCptCityArchive::defaultBaseDir() );
369446
}
370447

371-
QMap< QString, QString > QgsCptCityColorRampV2::copyingInfo( ) const
448+
QgsStringMap QgsCptCityColorRampV2::copyingInfo( ) const
372449
{
373450
return QgsCptCityArchive::copyingInfo( copyingFileName() );
374451
}
@@ -425,6 +502,7 @@ bool QgsCptCityColorRampV2::loadFile()
425502
++it;
426503
}
427504

505+
// fill all stops
428506
it = prev = colorMap.constBegin();
429507
while ( it != colorMap.constEnd() )
430508
{
@@ -447,6 +525,12 @@ bool QgsCptCityColorRampV2::loadFile()
447525
++it;
448526
}
449527

528+
// remove first and last items (mColor1 and mColor2)
529+
if ( ! mStops.isEmpty() && mStops.first().offset == 0.0 )
530+
mColor1 = mStops.takeFirst().color;
531+
if ( ! mStops.isEmpty() && mStops.last().offset == 1.0 )
532+
mColor2 = mStops.takeLast().color;
533+
450534
mFileLoaded = true;
451535
return true;
452536
}

‎src/core/symbology-ng/qgsvectorcolorrampv2.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,24 @@ class CORE_EXPORT QgsVectorGradientColorRampV2 : public QgsVectorColorRampV2
6868

6969
QColor color1() const { return mColor1; }
7070
QColor color2() const { return mColor2; }
71-
7271
void setColor1( QColor color ) { mColor1 = color; }
7372
void setColor2( QColor color ) { mColor2 = color; }
7473

7574
bool isDiscrete() const { return mDiscrete; }
7675
void setDiscrete( bool discrete ) { mDiscrete = discrete; }
76+
void convertToDiscrete( bool discrete );
7777

7878
void setStops( const QgsGradientStopsList& stops ) { mStops = stops; }
7979
const QgsGradientStopsList& stops() const { return mStops; }
8080

81+
QgsStringMap info() const { return mInfo; }
82+
void setInfo( const QgsStringMap& info ) { mInfo = info; }
83+
8184
protected:
8285
QColor mColor1, mColor2;
8386
bool mDiscrete;
8487
QgsGradientStopsList mStops;
88+
QgsStringMap mInfo;
8589
};
8690

8791
#define DEFAULT_RANDOM_COUNT 10
@@ -191,6 +195,7 @@ class CORE_EXPORT QgsCptCityColorRampV2 : public QgsVectorGradientColorRampV2
191195

192196
virtual QgsVectorColorRampV2* clone() const;
193197
void copy( const QgsCptCityColorRampV2* other );
198+
QgsVectorGradientColorRampV2* cloneGradientRamp() const;
194199

195200
virtual QgsStringMap properties() const;
196201

@@ -215,7 +220,7 @@ class CORE_EXPORT QgsCptCityColorRampV2 : public QgsVectorGradientColorRampV2
215220

216221
QString copyingFileName() const;
217222
QString descFileName() const;
218-
QMap< QString, QString > copyingInfo() const;
223+
QgsStringMap copyingInfo() const;
219224

220225
protected:
221226

‎src/gui/symbology-ng/qgscptcitycolorrampv2dialog.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ QgsCptCityColorRampV2Dialog::QgsCptCityColorRampV2Dialog( QgsCptCityColorRampV2*
5858
{
5959
setupUi( this );
6060

61+
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
62+
6163
QSettings settings;
6264
restoreGeometry( settings.value( "/Windows/CptCityColorRampV2Dialog/geometry" ).toByteArray() );
6365
mSplitter->setSizes( QList<int>() << 250 << 550 );
@@ -93,7 +95,6 @@ QgsCptCityColorRampV2Dialog::QgsCptCityColorRampV2Dialog( QgsCptCityColorRampV2*
9395
mStackedWidget->addWidget( edit );
9496
mStackedWidget->setCurrentIndex( 1 );
9597
tabBar->setVisible( false );
96-
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
9798
// dlg.layout()->addWidget( edit );
9899
// dlg.resize(500,400);
99100
// dlg.exec();
@@ -154,11 +155,13 @@ QgsCptCityColorRampV2Dialog::QgsCptCityColorRampV2Dialog( QgsCptCityColorRampV2*
154155
setTreeModel( mSelectionsModel );
155156
}
156157
}
158+
if ( found )
159+
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( true );
157160
}
158161

159162
tabBar->blockSignals( false );
160163

161-
connect( this, SIGNAL( finished( int ) ), this, SLOT( onFinished() ) );
164+
connect( this, SIGNAL( finished( int ) ), this, SLOT( onFinished( int ) ) );
162165

163166
// TODO - remove this when basic archive is complete
164167
if ( mArchive->archiveName() == DEFAULT_CPTCITY_ARCHIVE )
@@ -261,6 +264,7 @@ void QgsCptCityColorRampV2Dialog::on_mTreeView_clicked( const QModelIndex &index
261264
QgsCptCityDataItem *item = mModel->dataItem( sourceIndex );
262265
if ( ! item )
263266
return;
267+
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
264268
updateTreeView( item );
265269
}
266270

@@ -304,6 +308,7 @@ void QgsCptCityColorRampV2Dialog::on_mListWidget_itemClicked( QListWidgetItem *
304308
QgsCptCityColorRampItem *rampItem = mListRamps.at( item->data( Qt::UserRole ).toInt() );
305309
if ( rampItem )
306310
{
311+
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( true );
307312
lblSchemeName->setText( QFileInfo( rampItem->name() ).fileName() );
308313
mRamp->copy( &rampItem->ramp() );
309314
QgsDebugMsg( QString( "variant= %1 - %2 variants" ).arg( mRamp->variantName() ).arg( mRamp->variantList().count() ) );
@@ -479,11 +484,19 @@ void QgsCptCityColorRampV2Dialog::on_cboVariantName_currentIndexChanged( int ind
479484

480485
void QgsCptCityColorRampV2Dialog::onFinished()
481486
{
487+
// save settings
482488
QSettings settings;
483489
settings.setValue( "/Windows/CptCityColorRampV2Dialog/geometry", saveGeometry() );
484490
settings.setValue( "/Windows/CptCityColorRampV2Dialog/splitter", mSplitter->saveState() );
485491
}
486492

493+
bool QgsCptCityColorRampV2Dialog::saveAsGradientRamp() const
494+
{
495+
QgsDebugMsg( QString( "result: %1 checked: %2" ).arg( result() ).arg( cboConvertStandard->isChecked() ) );
496+
// if "save as standard gradient" is checked, convert to QgsVectorGradientColorRampV2
497+
return ( result() == Accepted && cboConvertStandard->isChecked() );
498+
}
499+
487500
void QgsCptCityColorRampV2Dialog::updateListWidget( QgsCptCityDataItem *item )
488501
{
489502
QgsCptCityCollectionItem* colItem = dynamic_cast<QgsCptCityCollectionItem*>( item );
@@ -554,6 +567,7 @@ bool QgsCptCityColorRampV2Dialog::updateRamp()
554567
cboVariantName->clear();
555568
updatePreview( true );
556569
clearCopyingInfo( );
570+
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
557571

558572
QgsDebugMsg( "schemeName= " + mRamp->schemeName() );
559573
if ( mRamp->schemeName() == "" )
@@ -598,6 +612,7 @@ bool QgsCptCityColorRampV2Dialog::updateRamp()
598612
populateVariants();
599613
mListWidget->scrollToItem( listItem, QAbstractItemView::EnsureVisible );
600614
// mListView->selectionModel()->select( childIndex, QItemSelectionModel::Select );
615+
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( true );
601616
return true;
602617
}
603618
}

‎src/gui/symbology-ng/qgscptcitycolorrampv2dialog.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class GUI_EXPORT QgsCptCityColorRampV2Dialog : public QDialog, private Ui::QgsCp
4141
QString selectedName() const
4242
{ return mRamp ? QFileInfo( mRamp->schemeName() ).baseName() + mRamp->variantName() : QString(); }
4343

44+
bool saveAsGradientRamp() const;
45+
4446
public slots:
4547
void populateVariants();
4648

@@ -50,7 +52,6 @@ class GUI_EXPORT QgsCptCityColorRampV2Dialog : public QDialog, private Ui::QgsCp
5052
void on_pbtnLicenseDetails_pressed();
5153
void on_cboVariantName_currentIndexChanged( int index );
5254
void onFinished();
53-
5455
/* void refresh(); */
5556

5657
protected:

‎src/gui/symbology-ng/qgsstylev2managerdialog.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,17 @@ QString QgsStyleV2ManagerDialog::addColorRampStatic( QWidget* parent, QgsStyleV2
466466
delete cptCityRamp;
467467
return QString();
468468
}
469-
ramp = cptCityRamp;
470469
// name = dlg.selectedName();
471470
name = QFileInfo( cptCityRamp->schemeName() ).baseName() + cptCityRamp->variantName();
471+
if ( dlg.saveAsGradientRamp() )
472+
{
473+
ramp = cptCityRamp->cloneGradientRamp();
474+
delete cptCityRamp;
475+
}
476+
else
477+
{
478+
ramp = cptCityRamp;
479+
}
472480
}
473481
else
474482
{
@@ -632,6 +640,11 @@ bool QgsStyleV2ManagerDialog::editColorRamp()
632640
delete ramp;
633641
return false;
634642
}
643+
if ( dlg.saveAsGradientRamp() )
644+
{
645+
ramp = cptCityRamp->cloneGradientRamp();
646+
delete cptCityRamp;
647+
}
635648
}
636649
else
637650
{

‎src/gui/symbology-ng/qgsvectorgradientcolorrampv2dialog.cpp

Lines changed: 111 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616
#include "qgsvectorgradientcolorrampv2dialog.h"
1717

1818
#include "qgsvectorcolorrampv2.h"
19+
#include "qgsdialog.h"
1920

2021
#include <QColorDialog>
2122
#include <QInputDialog>
2223
#include <QPainter>
24+
#include <QTableWidget>
25+
#include <QTextEdit>
2326

2427
QgsVectorGradientColorRampV2Dialog::QgsVectorGradientColorRampV2Dialog( QgsVectorGradientColorRampV2* ramp, QWidget* parent )
2528
: QDialog( parent ), mRamp( ramp )
@@ -30,15 +33,105 @@ QgsVectorGradientColorRampV2Dialog::QgsVectorGradientColorRampV2Dialog( QgsVecto
3033
connect( btnColor2, SIGNAL( clicked() ), this, SLOT( setColor2() ) );
3134

3235
// handle stops
33-
QgsGradientStopsList stops = ramp->stops();
36+
updateStops();
37+
connect( groupStops, SIGNAL( toggled( bool ) ), this, SLOT( toggledStops( bool ) ) );
38+
connect( btnAddStop, SIGNAL( clicked() ), this, SLOT( addStop() ) );
39+
connect( btnRemoveStop, SIGNAL( clicked() ), this, SLOT( removeStop() ) );
40+
connect( treeStops, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ), this, SLOT( stopDoubleClicked( QTreeWidgetItem*, int ) ) );
41+
42+
// fill type combobox
43+
cboType->blockSignals( true );
44+
cboType->addItem( tr( "Discrete" ) );
45+
cboType->addItem( tr( "Continous" ) );
46+
if ( mRamp->isDiscrete() )
47+
cboType->setCurrentIndex( 0 );
48+
else
49+
cboType->setCurrentIndex( 1 );
50+
cboType->blockSignals( false );
51+
52+
// information button if needed
53+
// QPushButton* button = buttonBox->addButton( tr( "Information" ), QDialogButtonBox::ActionRole );
54+
if ( mRamp->info().isEmpty() )
55+
btnInformation->setEnabled( false );
56+
// else
57+
// connect( button, SIGNAL( pressed() ), this, SLOT( showInformation() ) );
58+
59+
updatePreview();
60+
}
61+
62+
void QgsVectorGradientColorRampV2Dialog::on_cboType_currentIndexChanged( int index )
63+
{
64+
if (( index == 0 && mRamp->isDiscrete() ) ||
65+
( index == 1 && !mRamp->isDiscrete() ) )
66+
return;
67+
mRamp->convertToDiscrete( index == 0 );
68+
updateStops();
69+
updatePreview();
70+
}
71+
72+
void QgsVectorGradientColorRampV2Dialog::on_btnInformation_pressed()
73+
{
74+
if ( mRamp->info().isEmpty() )
75+
return;
76+
77+
QgsDialog *dlg = new QgsDialog( this );
78+
79+
// information table
80+
QTableWidget *tableInfo = new QTableWidget( dlg );
81+
tableInfo->verticalHeader()->hide();
82+
tableInfo->horizontalHeader()->hide();
83+
tableInfo->setColumnCount( 2 );
84+
tableInfo->setRowCount( mRamp->info().count() );
85+
int i = 0;
86+
for ( QgsStringMap::const_iterator it = mRamp->info().constBegin();
87+
it != mRamp->info().constEnd(); ++it )
88+
{
89+
QgsDebugMsg( it.key() + "-" + it.value() );
90+
tableInfo->setItem( i, 0, new QTableWidgetItem( it.key() ) );
91+
tableInfo->setItem( i, 1, new QTableWidgetItem( it.value() ) );
92+
tableInfo->resizeRowToContents( i );
93+
i++;
94+
}
95+
tableInfo->resizeColumnToContents( 0 );
96+
tableInfo->horizontalHeader()->setStretchLastSection( true );
97+
tableInfo->setFixedHeight( tableInfo->rowHeight( 0 ) * i + 5 );
98+
dlg->layout()->addWidget( tableInfo );
99+
dlg->resize( 600, 250 );
100+
101+
// license file
102+
QString licenseFile = mRamp->info().value( "license/file" );
103+
if ( !licenseFile.isNull() && QFile::exists( licenseFile ) )
104+
{
105+
QTextEdit *textEdit = new QTextEdit( dlg );
106+
textEdit->setReadOnly( true );
107+
QFile file( licenseFile );
108+
if ( file.open( QIODevice::ReadOnly | QIODevice::Text ) )
109+
{
110+
textEdit->setText( file.readAll() );
111+
file.close();
112+
dlg->layout()->addSpacing( 10 );
113+
dlg->layout()->addWidget( new QLabel( tr( "License file : %1" ).arg( licenseFile ), dlg ) );
114+
dlg->layout()->addSpacing( 5 );
115+
dlg->layout()->addWidget( textEdit );
116+
dlg->resize( 600, 500 );
117+
}
118+
}
119+
120+
dlg->show(); //non modal
121+
}
122+
123+
void QgsVectorGradientColorRampV2Dialog::updateStops()
124+
{
125+
QgsGradientStopsList stops = mRamp->stops();
34126
groupStops->setChecked( !stops.isEmpty() );
35127

36128
QList<QTreeWidgetItem *> items;
37129
for ( QgsGradientStopsList::iterator it = stops.begin();
38130
it != stops.end(); ++it )
39131
{
132+
double val = it->offset * 100.0;
40133
QStringList lst;
41-
lst << "." << QString::number( it->offset*100, 'f', 0 );
134+
lst << "." << QString(( val < 10 ) ? '0' + QString::number( val ) : QString::number( val ) );
42135
QTreeWidgetItem* item = new QTreeWidgetItem( lst );
43136

44137
setStopColor( item, it->color );
@@ -49,15 +142,9 @@ QgsVectorGradientColorRampV2Dialog::QgsVectorGradientColorRampV2Dialog( QgsVecto
49142
treeStops->clear();
50143
treeStops->insertTopLevelItems( 0, items );
51144
treeStops->resizeColumnToContents( 0 );
145+
treeStops->setColumnWidth( 0, treeStops->columnWidth( 0 ) + 20 );
52146
treeStops->sortByColumn( 1, Qt::AscendingOrder );
53147
treeStops->setSortingEnabled( true );
54-
55-
connect( groupStops, SIGNAL( toggled( bool ) ), this, SLOT( toggledStops( bool ) ) );
56-
connect( btnAddStop, SIGNAL( clicked() ), this, SLOT( addStop() ) );
57-
connect( btnRemoveStop, SIGNAL( clicked() ), this, SLOT( removeStop() ) );
58-
connect( treeStops, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ), this, SLOT( stopDoubleClicked( QTreeWidgetItem*, int ) ) );
59-
60-
updatePreview();
61148
}
62149

63150
void QgsVectorGradientColorRampV2Dialog::updatePreview()
@@ -160,26 +247,26 @@ void QgsVectorGradientColorRampV2Dialog::stopDoubleClicked( QTreeWidgetItem* ite
160247
{
161248
bool ok;
162249
double key = item->data( 0, StopOffsetRole ).toDouble();
163-
int val = ( int )( key * 100 );
250+
// allow for floating-point values
251+
double val = key * 100;
164252
#if QT_VERSION >= 0x40500
165-
val = QInputDialog::getInt( this, tr( "Offset of the stop" ),
166-
tr( "Please enter offset in percents (%) of the new stop" ),
167-
val, 0, 100, 1, &ok );
253+
val = QInputDialog::getDouble( this, tr( "Offset of the stop" ),
254+
tr( "Please enter offset in percents (%) of the new stop" ),
255+
val, 0, 100, 2, &ok );
168256
#else
169257
QString res = QInputDialog::getText( this, tr( "Offset of the stop" ),
170258
tr( "Please enter offset in percents (%) of the new stop" ),
171259
QLineEdit::Normal, QString::number( val ), &ok );
172260
if ( ok )
173-
val = res.toInt( &ok );
261+
val = res.toDouble( &ok );
174262
if ( ok )
175263
ok = val >= 0 && val <= 100;
176264
#endif
177265
if ( !ok )
178266
return;
179267

180268
double newkey = val / 100.0;
181-
item->setText( 1, QString::number( val ) );
182-
269+
item->setText( 1, ( val < 10 ) ? '0' + QString::number( val ) : QString::number( val ) );
183270
item->setData( 0, StopOffsetRole, newkey );
184271

185272
updatePreview();
@@ -203,17 +290,17 @@ void QgsVectorGradientColorRampV2Dialog::addStop()
203290
return;
204291

205292
bool ok;
206-
int val = 50;
293+
double val = 50.0;
207294
#if QT_VERSION >= 0x40500
208-
val = QInputDialog::getInt( this, tr( "Offset of the stop" ),
209-
tr( "Please enter offset in percents (%) of the new stop" ),
210-
val, 0, 100, 1, &ok );
295+
val = QInputDialog::getDouble( this, tr( "Offset of the stop" ),
296+
tr( "Please enter offset in percents (%) of the new stop" ),
297+
val, 0, 100, 2, &ok );
211298
#else
212299
QString res = QInputDialog::getText( this, tr( "Offset of the stop" ),
213300
tr( "Please enter offset in percents (%) of the new stop" ),
214301
QLineEdit::Normal, QString::number( val ), &ok );
215302
if ( ok )
216-
val = res.toInt( &ok );
303+
val = res.toDouble( &ok );
217304
if ( ok )
218305
ok = val >= 0 && val <= 100;
219306
#endif
@@ -222,7 +309,8 @@ void QgsVectorGradientColorRampV2Dialog::addStop()
222309

223310
double key = val / 100.0;
224311
QStringList lst;
225-
lst << "." << QString::number( val, 'f', 0 );
312+
lst << "." << QString(( val < 10 ) ? '0' + QString::number( val ) : QString::number( val ) );
313+
226314
QTreeWidgetItem* item = new QTreeWidgetItem( lst );
227315

228316
setStopColor( item, color );
@@ -231,6 +319,7 @@ void QgsVectorGradientColorRampV2Dialog::addStop()
231319
treeStops->addTopLevelItem( item );
232320

233321
treeStops->resizeColumnToContents( 0 );
322+
treeStops->setColumnWidth( 0, treeStops->columnWidth( 0 ) + 20 );
234323

235324
updatePreview();
236325
}

‎src/gui/symbology-ng/qgsvectorgradientcolorrampv2dialog.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,13 @@ class GUI_EXPORT QgsVectorGradientColorRampV2Dialog : public QDialog, private Ui
3939

4040
void stopDoubleClicked( QTreeWidgetItem* item, int column );
4141

42+
protected slots:
43+
void on_cboType_currentIndexChanged( int index );
44+
void on_btnInformation_pressed();
45+
4246
protected:
4347

48+
void updateStops();
4449
void updatePreview();
4550
void setStopColor( QTreeWidgetItem* item, QColor color );
4651

‎src/ui/qgscptcitycolorrampv2dialogbase.ui

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -486,14 +486,38 @@
486486
</widget>
487487
</item>
488488
<item>
489-
<widget class="QDialogButtonBox" name="buttonBox">
490-
<property name="orientation">
491-
<enum>Qt::Horizontal</enum>
492-
</property>
493-
<property name="standardButtons">
494-
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
495-
</property>
496-
</widget>
489+
<layout class="QHBoxLayout" name="horizontalLayout_3">
490+
<item>
491+
<spacer name="horizontalSpacer_4">
492+
<property name="orientation">
493+
<enum>Qt::Horizontal</enum>
494+
</property>
495+
<property name="sizeHint" stdset="0">
496+
<size>
497+
<width>40</width>
498+
<height>20</height>
499+
</size>
500+
</property>
501+
</spacer>
502+
</item>
503+
<item>
504+
<widget class="QCheckBox" name="cboConvertStandard">
505+
<property name="text">
506+
<string>Save as standard gradient</string>
507+
</property>
508+
</widget>
509+
</item>
510+
<item>
511+
<widget class="QDialogButtonBox" name="buttonBox">
512+
<property name="orientation">
513+
<enum>Qt::Horizontal</enum>
514+
</property>
515+
<property name="standardButtons">
516+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
517+
</property>
518+
</widget>
519+
</item>
520+
</layout>
497521
</item>
498522
</layout>
499523
</widget>
@@ -505,9 +529,6 @@
505529
<container>1</container>
506530
</customwidget>
507531
</customwidgets>
508-
<tabstops>
509-
<tabstop>buttonBox</tabstop>
510-
</tabstops>
511532
<resources/>
512533
<connections>
513534
<connection>

‎src/ui/qgsstylev2managerdialogbase.ui

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,19 @@ QMenu::item:selected { background-color: gray; } */
295295
</item>
296296
<item row="4" column="0" colspan="2">
297297
<layout class="QHBoxLayout" name="horizontalLayout">
298+
<item>
299+
<spacer name="horizontalSpacer_2">
300+
<property name="orientation">
301+
<enum>Qt::Horizontal</enum>
302+
</property>
303+
<property name="sizeHint" stdset="0">
304+
<size>
305+
<width>40</width>
306+
<height>20</height>
307+
</size>
308+
</property>
309+
</spacer>
310+
</item>
298311
<item>
299312
<layout class="QHBoxLayout" name="symbolBtnsLayout">
300313
<property name="spacing">
@@ -366,6 +379,19 @@ QMenu::item:selected { background-color: gray; } */
366379
</item>
367380
</layout>
368381
</item>
382+
<item>
383+
<spacer name="horizontalSpacer_3">
384+
<property name="orientation">
385+
<enum>Qt::Horizontal</enum>
386+
</property>
387+
<property name="sizeHint" stdset="0">
388+
<size>
389+
<width>40</width>
390+
<height>20</height>
391+
</size>
392+
</property>
393+
</spacer>
394+
</item>
369395
<item>
370396
<widget class="QDialogButtonBox" name="buttonBox">
371397
<property name="orientation">

‎src/ui/qgsvectorgradientcolorrampv2dialogbase.ui

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,39 @@
6666
</property>
6767
</widget>
6868
</item>
69+
<item row="2" column="0">
70+
<widget class="QLabel" name="label_3">
71+
<property name="text">
72+
<string>Type</string>
73+
</property>
74+
</widget>
75+
</item>
76+
<item row="2" column="1">
77+
<widget class="QComboBox" name="cboType">
78+
<property name="sizePolicy">
79+
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
80+
<horstretch>0</horstretch>
81+
<verstretch>0</verstretch>
82+
</sizepolicy>
83+
</property>
84+
<property name="styleSheet">
85+
<string notr="true"/>
86+
</property>
87+
<property name="sizeAdjustPolicy">
88+
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
89+
</property>
90+
</widget>
91+
</item>
6992
</layout>
7093
</item>
7194
<item>
7295
<widget class="QGroupBox" name="groupStops">
96+
<property name="sizePolicy">
97+
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
98+
<horstretch>0</horstretch>
99+
<verstretch>1</verstretch>
100+
</sizepolicy>
101+
</property>
73102
<property name="title">
74103
<string>Multiple stops</string>
75104
</property>
@@ -109,7 +138,7 @@
109138
</column>
110139
<column>
111140
<property name="text">
112-
<string>Offset</string>
141+
<string>Offset (%)</string>
113142
</property>
114143
</column>
115144
</widget>
@@ -122,7 +151,7 @@
122151
<property name="title">
123152
<string>Preview</string>
124153
</property>
125-
<layout class="QVBoxLayout">
154+
<layout class="QVBoxLayout" name="verticalLayout_2">
126155
<item>
127156
<widget class="QLabel" name="lblPreview">
128157
<property name="frameShape">
@@ -140,14 +169,25 @@
140169
</widget>
141170
</item>
142171
<item>
143-
<widget class="QDialogButtonBox" name="buttonBox">
144-
<property name="orientation">
145-
<enum>Qt::Horizontal</enum>
146-
</property>
147-
<property name="standardButtons">
148-
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
149-
</property>
150-
</widget>
172+
<layout class="QHBoxLayout" name="horizontalLayout">
173+
<item>
174+
<widget class="QPushButton" name="btnInformation">
175+
<property name="text">
176+
<string>Information</string>
177+
</property>
178+
</widget>
179+
</item>
180+
<item>
181+
<widget class="QDialogButtonBox" name="buttonBox">
182+
<property name="orientation">
183+
<enum>Qt::Horizontal</enum>
184+
</property>
185+
<property name="standardButtons">
186+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
187+
</property>
188+
</widget>
189+
</item>
190+
</layout>
151191
</item>
152192
</layout>
153193
</widget>
@@ -165,7 +205,6 @@
165205
<tabstop>treeStops</tabstop>
166206
<tabstop>btnAddStop</tabstop>
167207
<tabstop>btnRemoveStop</tabstop>
168-
<tabstop>buttonBox</tabstop>
169208
</tabstops>
170209
<resources/>
171210
<connections>

0 commit comments

Comments
 (0)
Please sign in to comment.