Skip to content
Permalink
Browse files

fixed a number of bugs in stylemgr, importdlg and symbolslistwdgt

  • Loading branch information
tecoholic committed Aug 9, 2012
1 parent 360ccda commit b7f1dea91ed0a2cf55ee73bab5729ade6d8d1784
@@ -65,7 +65,7 @@ QgsStyleV2ExportImportDialog::QgsStyleV2ExportImportDialog( QgsStyleV2* style, Q
connect( importTypeCombo, SIGNAL( currentIndexChanged( int ) ), this, SLOT( importTypeChanged( int ) ) );

QStringList groups = mQgisStyle->groupNames();
groupCombo->addItem( "New Group", QVariant( "new" ) );
groupCombo->addItem( "imported", QVariant( "new" ) );
foreach ( QString gName, groups )
{
groupCombo->addItem( gName );
@@ -214,11 +214,11 @@ void QgsStyleV2ExportImportDialog::moveStyles( QModelIndexList* selection, QgsSt
if ( mDialogMode == Import )
{
int index = groupCombo->currentIndex();
if ( groupCombo->itemData( index ).toString() == "new" )
QString name = groupCombo->itemText( index );
if ( name.isEmpty() )
{
// get name of the group
bool nameInvalid = true;
QString name;
while ( nameInvalid )
{
bool ok;
@@ -239,24 +239,21 @@ void QgsStyleV2ExportImportDialog::moveStyles( QModelIndexList* selection, QgsSt
QMessageBox::warning( this, tr( "New group" ),
tr( "Cannot create a group without name. Enter a name." ) );
}
else if ( dst->groupNames().contains( name ) )
{
groupid = dst->groupId( name );
break;
}
else
{
// valid name
nameInvalid = false;
}
}
// check the valid name bool to avoid duplicate group names
if ( !nameInvalid )
groupid = dst->addGroup( name );
groupid = dst->addGroup( name );
}
else if ( dst->groupNames().contains( name ) )
{
groupid = dst->groupId( name );
}
else
{
groupid = dst->groupId( groupCombo->itemText( index ) );
groupid = dst->addGroup( name );
}
}

@@ -203,6 +203,7 @@ void QgsStyleV2ManagerDialog::populateSymbols( QStringList symbolNames, bool che
item->setIcon( icon );
item->setData( name ); // used to find out original name when user edited the name
item->setCheckable( check );
item->setToolTip( name );
// add to model
model->appendRow( item );
}
@@ -1139,23 +1140,23 @@ void QgsStyleV2ManagerDialog::grouptreeContextMenu( const QPoint& point )

QMenu groupMenu;

if ( index.parent().isValid() && ( index.data( Qt::UserRole + 1 ).toString() != "ungrouped" ) )
if ( index.parent().isValid() && ( index.data().toString() != "Ungrouped" ) )
{
if ( index.parent().data( Qt::UserRole + 1 ).toString() == "smartgroups" )
{
groupMenu.addAction( "Edit Group" );
groupMenu.addAction( "Remove Group" );
}
else
{
groupMenu.addAction( "Add Group" );
}
groupMenu.addAction( "Remove Group" );
}
else if ( index.data( Qt::UserRole + 1 ) == "groups" || index.data( Qt::UserRole + 1 ) == "smartgroups" )
{
groupMenu.addAction( "Add Group" );
}
else
{
groupMenu.addAction( "Add Group" );
groupMenu.addAction( "Remove Group" );
}


QAction* selectedItem = groupMenu.exec( globalPos );

@@ -49,14 +49,10 @@ QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbolV2* symbol, QgsStyleV2* sty
btnAdvanced->show();
}

// Populate the symbol groups
QStringList groups = style->groupNames();
groupsCombo->addItem( QString( "" ) ); //empty first item
foreach ( QString group, groups )
{
groupsCombo->addItem( group );
}
groups = style->smartgroupNames();
// populate the groups
groupsCombo->addItem( "" );
populateGroups();
QStringList groups = style->smartgroupNames();
foreach ( QString group, groups )
{
groupsCombo->addItem( group, QVariant( "smart" ) );
@@ -106,6 +102,27 @@ QgsSymbolsListWidget::QgsSymbolsListWidget( QgsSymbolV2* symbol, QgsStyleV2* sty
updateSymbolColor();
}

void QgsSymbolsListWidget::populateGroups( QString parent, QString prepend )
{
QgsSymbolGroupMap groups = mStyle->childGroupNames( parent );
QgsSymbolGroupMap::const_iterator i = groups.constBegin();
while ( i != groups.constEnd() )
{
QString text;
if ( !prepend.isEmpty() )
{
text = prepend + "/" + i.value();
}
else
{
text = i.value();
}
groupsCombo->addItem( text, QVariant( i.key() ) );
populateGroups( i.value(), text );
++i;
}
}

void QgsSymbolsListWidget::populateSymbolView()
{
populateSymbols( mStyle->symbolNames() );
@@ -223,7 +240,7 @@ void QgsSymbolsListWidget::addSymbolToStyle()
mStyle->addSymbol( name, mSymbol->clone() );

// make sure the symbol is stored
mStyle->save();
mStyle->saveSymbol( name, mSymbol->clone(), 0, QStringList() );

populateSymbolView();
}
@@ -315,12 +332,13 @@ void QgsSymbolsListWidget::on_groupsCombo_currentIndexChanged( int index )
if ( groupsCombo->itemData( index ).toString() == "smart" )
{
groupid = mStyle->smartgroupId( text );
symbols = mStyle->symbolsOfSmartgroup( SymbolEntity, groupid );
}
else
{
groupid = mStyle->groupId( text );
groupid = groupsCombo->itemData( index ).toInt();
symbols = mStyle->symbolsOfGroup( SymbolEntity, groupid );
}
symbols = mStyle->symbolsOfGroup( SymbolEntity, groupid );
}
populateSymbols( symbols );
}
@@ -62,8 +62,9 @@ class GUI_EXPORT QgsSymbolsListWidget : public QWidget, private Ui::SymbolsListW
private:
/**Displays alpha value as transparency in mTransparencyLabel*/
void displayTransparency( double alpha );
/** Recursive function to create the group tree in the widget */
void populateGroups( QString parent = "", QString prepend = "" );
};

#endif //QGSSYMBOLSLISTWIDGET_H


@@ -182,7 +182,7 @@ QgsSymbolV2SelectorDialog::QgsSymbolV2SelectorDialog( QgsSymbolV2* symbol, QgsSt

updateUi();

// set symbol as active item in the tree
// set symbol as active item in the tree
QModelIndex newIndex = layersTree->model()->index( 0, 0 );
layersTree->setCurrentIndex( newIndex );
}
@@ -46,12 +46,16 @@
<item row="2" column="0">
<widget class="QLabel" name="groupLabel">
<property name="text">
<string>Set Group</string>
<string>Save to group</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QComboBox" name="groupCombo"/>
<widget class="QComboBox" name="groupCombo">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>

0 comments on commit b7f1dea

Please sign in to comment.
You can’t perform that action at this time.