-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Allow creation of color ramps in color ramp combo box.
git-svn-id: http://svn.osgeo.org/qgis/trunk@14421 c8812cc2-4d05-0410-92ff-de0c093fc19c
- Loading branch information
wonder
committed
Oct 20, 2010
1 parent
8ee79eb
commit 7f32157
Showing
9 changed files
with
279 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#include "qgscolorrampcombobox.h" | ||
|
||
#include "qgssymbollayerv2utils.h" | ||
#include "qgsvectorcolorrampv2.h" | ||
#include "qgsstylev2.h" | ||
#include "qgsstylev2managerdialog.h" | ||
|
||
QSize QgsColorRampComboBox::rampIconSize( 50, 16 ); | ||
|
||
QgsColorRampComboBox::QgsColorRampComboBox( QWidget *parent ) : | ||
QComboBox( parent ), mStyle( NULL ), mSourceColorRamp( NULL ) | ||
{ | ||
} | ||
|
||
QgsColorRampComboBox::~QgsColorRampComboBox() | ||
{ | ||
delete mSourceColorRamp; | ||
} | ||
|
||
void QgsColorRampComboBox::populate( QgsStyleV2* style ) | ||
{ | ||
if( count() != 0 ) | ||
return; // already populated! | ||
|
||
mStyle = style; | ||
|
||
setIconSize( rampIconSize ); | ||
|
||
QStringList rampNames = mStyle->colorRampNames(); | ||
for( QStringList::iterator it = rampNames.begin(); it != rampNames.end(); ++it ) | ||
{ | ||
QgsVectorColorRampV2* ramp = style->colorRamp( *it ); | ||
QIcon icon = QgsSymbolLayerV2Utils::colorRampPreviewIcon( ramp, rampIconSize ); | ||
|
||
addItem( icon, *it ); | ||
|
||
delete ramp; | ||
} | ||
|
||
addItem( tr( "New color ramp..." ) ); | ||
connect( this, SIGNAL( currentIndexChanged( int ) ), SLOT( colorRampChanged( int ) ) ); | ||
} | ||
|
||
QgsVectorColorRampV2* QgsColorRampComboBox::currentColorRamp() | ||
{ | ||
QString rampName = currentText(); | ||
if( rampName == "[source]" && mSourceColorRamp ) | ||
return mSourceColorRamp->clone(); | ||
else | ||
return mStyle->colorRamp( rampName ); | ||
} | ||
|
||
void QgsColorRampComboBox::setSourceColorRamp( QgsVectorColorRampV2* sourceRamp ) | ||
{ | ||
mSourceColorRamp = sourceRamp->clone(); | ||
|
||
QIcon icon = QgsSymbolLayerV2Utils::colorRampPreviewIcon( mSourceColorRamp, rampIconSize ); | ||
if( itemText( 0 ) == "[source]" ) | ||
setItemIcon( 0, icon ); | ||
else | ||
insertItem( 0, icon, "[source]" ); | ||
setCurrentIndex( 0 ); | ||
} | ||
|
||
void QgsColorRampComboBox::colorRampChanged( int index ) | ||
{ | ||
if( index != count() - 1 ) | ||
return; | ||
|
||
// last item: "new color ramp..." | ||
QString rampName = QgsStyleV2ManagerDialog::addColorRampStatic( this, mStyle ); | ||
if( rampName.isEmpty() ) | ||
return; | ||
|
||
// put newly added ramp into the combo | ||
QgsVectorColorRampV2* ramp = mStyle->colorRamp( rampName ); | ||
QIcon icon = QgsSymbolLayerV2Utils::colorRampPreviewIcon( ramp, rampIconSize ); | ||
|
||
blockSignals( true ); // avoid calling this method again! | ||
insertItem( index, icon, rampName ); | ||
blockSignals( false ); | ||
|
||
delete ramp; | ||
|
||
// ... and set it as active | ||
setCurrentIndex( index ); | ||
|
||
// make sure the color ramp is stored | ||
mStyle->save(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#ifndef QGSCOLORRAMPCOMBOBOX_H | ||
#define QGSCOLORRAMPCOMBOBOX_H | ||
|
||
#include <QComboBox> | ||
|
||
class QgsStyleV2; | ||
class QgsVectorColorRampV2; | ||
|
||
class QgsColorRampComboBox : public QComboBox | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit QgsColorRampComboBox( QWidget *parent = 0 ); | ||
|
||
~QgsColorRampComboBox(); | ||
|
||
//! initialize the combo box with color ramps from the style | ||
void populate( QgsStyleV2* style ); | ||
|
||
//! add/select color ramp which was used previously by the renderer | ||
void setSourceColorRamp( QgsVectorColorRampV2* sourceRamp ); | ||
|
||
//! return new instance of the current color ramp or NULL if there is no active color ramp | ||
QgsVectorColorRampV2* currentColorRamp(); | ||
|
||
static QSize rampIconSize; | ||
|
||
signals: | ||
|
||
public slots: | ||
|
||
void colorRampChanged( int index ); | ||
|
||
protected: | ||
QgsStyleV2* mStyle; | ||
QgsVectorColorRampV2* mSourceColorRamp; // owns the copy | ||
}; | ||
|
||
#endif // QGSCOLORRAMPCOMBOBOX_H |
Oops, something went wrong.