Skip to content

Commit

Permalink
style manager : cosmetic changes (wider icons, splitter with save/res…
Browse files Browse the repository at this point in the history
…tore, changed buttons appearance, add menu icon) and use menu instead of dialog to select new color ramp type
  • Loading branch information
etiennesky committed Sep 16, 2012
1 parent e67ac05 commit d00c335
Show file tree
Hide file tree
Showing 4 changed files with 421 additions and 269 deletions.
81 changes: 67 additions & 14 deletions src/gui/symbology-ng/qgsstylev2managerdialog.cpp
Expand Up @@ -41,14 +41,15 @@
#include "qgslogger.h"



QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* parent )
: QDialog( parent ), mStyle( style ), mModified( false )
{
setupUi( this );

QSettings settings;
restoreGeometry( settings.value( "/Windows/StyleV2Manager/geometry" ).toByteArray() );
mSplitter->setSizes( QList<int>() << 170 << 540 );
mSplitter->restoreState( settings.value( "/Windows/StyleV2Manager/splitter" ).toByteArray() );

#if QT_VERSION >= 0x40500
tabItemType->setDocumentMode( true );
Expand All @@ -63,6 +64,7 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
btnAddItem->setIcon( QIcon( QgsApplication::iconPath( "symbologyAdd.png" ) ) );
btnEditItem->setIcon( QIcon( QgsApplication::iconPath( "symbologyEdit.png" ) ) );
btnRemoveItem->setIcon( QIcon( QgsApplication::iconPath( "symbologyRemove.png" ) ) );
btnShare->setIcon( QIcon( QgsApplication::iconPath( "user.png" ) ) );

connect( this, SIGNAL( finished( int ) ), this, SLOT( onFinished() ) );

Expand Down Expand Up @@ -111,13 +113,11 @@ QgsStyleV2ManagerDialog::QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* pa
connect( btnAddGroup, SIGNAL( clicked() ), this, SLOT( addGroup() ) );
connect( btnRemoveGroup, SIGNAL( clicked() ), this, SLOT( removeGroup() ) );

connect( tabItemType, SIGNAL( currentChanged( int ) ), this, SLOT( populateList() ) );
populateList();
on_tabItemType_currentChanged( 0 );

connect( searchBox, SIGNAL( textChanged( QString ) ), this, SLOT( filterSymbols( QString ) ) );
tagsLineEdit->installEventFilter( this );


// Context menu for groupTree
groupTree->setContextMenuPolicy( Qt::CustomContextMenu );
connect( groupTree, SIGNAL( customContextMenuRequested( const QPoint& ) ),
Expand All @@ -139,6 +139,7 @@ void QgsStyleV2ManagerDialog::onFinished()

QSettings settings;
settings.setValue( "/Windows/StyleV2Manager/geometry", saveGeometry() );
settings.setValue( "/Windows/StyleV2Manager/splitter", mSplitter->saveState() );
}

void QgsStyleV2ManagerDialog::populateTypes()
Expand Down Expand Up @@ -181,6 +182,48 @@ void QgsStyleV2ManagerDialog::populateTypes()
#endif
}

void QgsStyleV2ManagerDialog::on_tabItemType_currentChanged( int )
{
// when in Color Ramp tab, add menu to add item button
if ( currentItemType() == 3 )
{
QStringList rampTypes;
rampTypes << tr( "Gradient" ) << tr( "Random" ) << tr( "ColorBrewer" );
rampTypes << tr( "cpt-city" ); // todo, only for rasters?
QMenu* menu = new QMenu( btnAddItem );
foreach ( QString rampType, rampTypes )
{
menu->addAction( rampType );
}
btnAddItem->setMenu( menu );
connect( menu, SIGNAL( triggered( QAction* ) ),
this, SLOT( addColorRamp( QAction* ) ) );
}
else
{
if ( btnAddItem->menu() )
{
disconnect( btnAddItem->menu(), SIGNAL( triggered( QAction* ) ),
this, SLOT( addColorRamp( QAction* ) ) );
btnAddItem->setMenu( 0 );
}
}

// set icon and grid size, depending on type
if ( currentItemType() == 1 || currentItemType() == 3 )
{
listItems->setIconSize( QSize( 75, 50 ) );
listItems->setGridSize( QSize( 100, 80 ) );
}
else
{
listItems->setIconSize( QSize( 50, 50 ) );
listItems->setGridSize( QSize( 75, 80 ) );
}

populateList();
}

void QgsStyleV2ManagerDialog::populateList()
{
if ( currentItemType() > 3 )
Expand Down Expand Up @@ -360,15 +403,18 @@ bool QgsStyleV2ManagerDialog::addSymbol()
}


QString QgsStyleV2ManagerDialog::addColorRampStatic( QWidget* parent, QgsStyleV2* style )
QString QgsStyleV2ManagerDialog::addColorRampStatic( QWidget* parent, QgsStyleV2* style, QString rampType )
{
// let the user choose the color ramp type
QStringList rampTypes;
rampTypes << tr( "Gradient" ) << tr( "Random" ) << tr( "ColorBrewer" );
rampTypes << tr( "cpt-city" ); // todo, only for rasters?
bool ok;
QString rampType = QInputDialog::getItem( parent, tr( "Color ramp type" ),
tr( "Please select color ramp type:" ), rampTypes, 0, false, &ok );
// let the user choose the color ramp type if rampType is not given
bool ok = true;
if ( rampType.isEmpty() )
{
QStringList rampTypes;
rampTypes << tr( "Gradient" ) << tr( "Random" ) << tr( "ColorBrewer" );
rampTypes << tr( "cpt-city" ); // todo, only for rasters?
rampType = QInputDialog::getItem( parent, tr( "Color ramp type" ),
tr( "Please select color ramp type:" ), rampTypes, 0, false, &ok );
}
if ( !ok || rampType.isEmpty() )
return QString();

Expand Down Expand Up @@ -479,17 +525,24 @@ QString QgsStyleV2ManagerDialog::addColorRampStatic( QWidget* parent, QgsStyleV2

bool QgsStyleV2ManagerDialog::addColorRamp()
{
QString rampName = addColorRampStatic( this , mStyle );
return addColorRamp( 0 );
}

bool QgsStyleV2ManagerDialog::addColorRamp( QAction* action )
{
// pass the action text, which is the color ramp type
QString rampName = addColorRampStatic( this , mStyle,
action ? action->text() : QString() );
if ( !rampName.isEmpty() )
{
mModified = true;
populateList();
return true;
}

return false;
}


void QgsStyleV2ManagerDialog::editItem()
{
bool changed = false;
Expand Down
6 changes: 5 additions & 1 deletion src/gui/symbology-ng/qgsstylev2managerdialog.h
Expand Up @@ -34,7 +34,8 @@ class GUI_EXPORT QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV
QgsStyleV2ManagerDialog( QgsStyleV2* style, QWidget* parent = NULL );

//! open add color ramp dialog, return color ramp's name if the ramp has been added
static QString addColorRampStatic( QWidget* parent, QgsStyleV2* style );
static QString addColorRampStatic( QWidget* parent, QgsStyleV2* style,
QString RampType = QString() );

public slots:
void addItem();
Expand All @@ -43,6 +44,7 @@ class GUI_EXPORT QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV
void exportItems();
void importItems();

void on_tabItemType_currentChanged( int );
//! adds symbols of some type to list
void populateList();

Expand Down Expand Up @@ -82,6 +84,8 @@ class GUI_EXPORT QgsStyleV2ManagerDialog : public QDialog, private Ui::QgsStyleV
//! Context menu for the listItems ( symbols list )
void listitemsContextMenu( const QPoint& );

protected slots:
bool addColorRamp( QAction* action );

protected:

Expand Down
15 changes: 9 additions & 6 deletions src/ui/qgisapp.ui
Expand Up @@ -17,7 +17,7 @@
<x>0</x>
<y>0</y>
<width>1052</width>
<height>22</height>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="mEditMenu">
Expand Down Expand Up @@ -1511,6 +1511,10 @@ Ctl (Cmd) increments by 15 deg.</string>
</property>
</action>
<action name="mActionStyleManagerV2">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/propertyicons/symbology.png</normaloff>:/images/themes/default/propertyicons/symbology.png</iconset>
</property>
<property name="text">
<string>Style Manager...</string>
</property>
Expand Down Expand Up @@ -1788,7 +1792,7 @@ Acts on all editable layers</string>
</property>
</action>
<action name="mActionShowHideLabels">
<property name="checkable">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
Expand All @@ -1803,13 +1807,12 @@ Acts on all editable layers</string>
Click or marquee on feature to show label
Shift+click or marquee on label to hide it
Acts on currently active editable layer</string>
</property>
</property>
</action>
<action name="mActionHtmlAnnotation">
<property name="icon">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionFormAnnotation.png</normaloff>:/images/themes/default/mActionFormAnnotation.png
</iconset>
<normaloff>:/images/themes/default/mActionFormAnnotation.png</normaloff>:/images/themes/default/mActionFormAnnotation.png</iconset>
</property>
<property name="text">
<string>Html Annotation</string>
Expand Down

0 comments on commit d00c335

Please sign in to comment.