Skip to content
Permalink
Browse files

change list to view in single symbol dialog

git-svn-id: http://svn.osgeo.org/qgis/trunk@14392 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Oct 18, 2010
1 parent b21747b commit cde5a0693b1af25230d596d35a11ad1d7f29dd9c
Showing with 102 additions and 82 deletions.
  1. +64 −44 src/app/qgssinglesymboldialog.cpp
  2. +1 −1 src/app/qgssinglesymboldialog.h
  3. +37 −37 src/ui/qgssinglesymboldialogbase.ui
@@ -30,11 +30,48 @@
#include <QPainter>
#include <QImage>
#include <QFileDialog>
#include <QListWidgetItem>
#include <QKeyEvent>
#include <QAbstractListModel>

#define DO_NOT_USE_STR "<off>"


class QgsMarkerListModel : public QAbstractListModel
{
public:
QgsMarkerListModel( QObject* parent ) : QAbstractListModel( parent )
{
mMarkers = QgsMarkerCatalogue::instance()->list();
}

int rowCount( const QModelIndex & parent = QModelIndex() ) const
{
return mMarkers.size();
}

QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const
{
QString marker = mMarkers.at( index.row() );

if ( role == Qt::DecorationRole ) // icon
{
QPen pen( QColor( 0, 0, 255 ) );
QBrush brush( QColor( 220, 220, 220 ), Qt::SolidPattern );
return QPixmap::fromImage( QgsMarkerCatalogue::instance()->imageMarker( marker, 18, pen, brush ) );
}
else if ( role == Qt::UserRole || role == Qt::ToolTipRole )
{
return marker;
}

return QVariant();
}

protected:
QStringList mMarkers;
};


QgsSingleSymbolDialog::QgsSingleSymbolDialog(): QDialog(), mVectorLayer( 0 )
{
setupUi( this );
@@ -71,8 +108,8 @@ QgsSingleSymbolDialog::QgsSingleSymbolDialog( QgsVectorLayer * layer, bool disab
connect( btnFillColor, SIGNAL( clicked() ), this, SLOT( selectFillColor() ) );
connect( outlinewidthspinbox, SIGNAL( valueChanged( double ) ), this, SLOT( resendSettingsChanged() ) );
connect( mLabelEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( resendSettingsChanged() ) );
connect( lstSymbols, SIGNAL( currentItemChanged( QListWidgetItem *, QListWidgetItem * ) ),
this, SLOT( symbolChanged( QListWidgetItem *, QListWidgetItem * ) ) );
connect( lstSymbols, SIGNAL( currentChanged( const QModelIndex & , const QModelIndex & ) ),
this, SLOT( symbolChanged( const QModelIndex & , const QModelIndex & ) ) );
connect( mPointSizeSpinBox, SIGNAL( valueChanged( double ) ), this, SLOT( resendSettingsChanged() ) );
connect( mPointSizeUnitsCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( resendSettingsChanged() ) );
connect( mRotationClassificationComboBox, SIGNAL( currentIndexChanged( const QString & ) ),
@@ -95,32 +132,8 @@ QgsSingleSymbolDialog::QgsSingleSymbolDialog( QgsVectorLayer * layer, bool disab

void QgsSingleSymbolDialog::refreshMarkers()
{
lstSymbols->blockSignals( true );
lstSymbols->clear();

QPen pen( QColor( 0, 0, 255 ) );
QBrush brush( QColor( 220, 220, 220 ), Qt::SolidPattern );
int size = 18;
int myCounter = 0;
QStringList ml = QgsMarkerCatalogue::instance()->list();
for ( QStringList::iterator it = ml.begin(); it != ml.end(); ++it )
{
QPixmap myPixmap = QPixmap::fromImage( QgsMarkerCatalogue::instance()->imageMarker( *it, size, pen, brush ) );
QListWidgetItem * mypItem = new QListWidgetItem( lstSymbols );
QIcon myIcon;
myIcon.addPixmap( myPixmap );
mypItem->setIcon( myIcon );
mypItem->setText( "" );
mypItem->setToolTip( *it );
//store the symbol offset in the UserData role for later retrieval
mypItem->setData( Qt::UserRole, *it );
mypItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
if ( mVectorLayer && mVectorLayer->geometryType() != QGis::Point )
{
break;
}
++myCounter;
}
QgsMarkerListModel *m = new QgsMarkerListModel( lstSymbols );
lstSymbols->setModel( m );

// Find out the numerical fields of mVectorLayer, and populate the ComboBoxes
QgsVectorDataProvider *provider = mVectorLayer->dataProvider();
@@ -283,9 +296,10 @@ void QgsSingleSymbolDialog::apply( QgsSymbol *sy )
//
// Apply point symbol
//
if ( lstSymbols->isEnabled() && lstSymbols->currentItem() )
if ( lstSymbols->isEnabled() && lstSymbols->currentIndex().isValid() )
{
sy->setNamedPointSymbol( lstSymbols->currentItem()->data( Qt::UserRole ).toString() ) ;
QAbstractItemModel *m = lstSymbols->model();
sy->setNamedPointSymbol( m->data( lstSymbols->currentIndex(), Qt::UserRole ).toString() );
}

if ( mPointSizeSpinBox->isEnabled() )
@@ -376,12 +390,15 @@ void QgsSingleSymbolDialog::set( const QgsSymbol *sy )

// Set point symbol
QString mySymbolName = sy->pointSymbolName();
for ( int i = 0; i < lstSymbols->count(); ++i )

QAbstractItemModel *m = lstSymbols->model();
for ( int i = 0; i < m->rowCount(); i++ )
{
if ( lstSymbols->item( i )->data( Qt::UserRole ).toString() == ( mySymbolName ) )
QModelIndex idx( m->index( i, 0 ) );
if ( m->data( idx, Qt::UserRole ).toString() == mySymbolName )
{
lstSymbols->setCurrentItem( lstSymbols->item( i ) );
lstSymbols->item( i )->setBackground( QBrush( Qt::cyan ) );
lstSymbols->setCurrentIndex( idx );
// m->setData( idx, Qt::UserRole+1, Qt::cyan );
break;
}
}
@@ -478,8 +495,13 @@ void QgsSingleSymbolDialog::updateSet( const QgsSymbol *sy )
if ( mLabelEdit->isEnabled() && mLabelEdit->text() != sy->label() )
mLabelEdit->setEnabled( false );

if ( lstSymbols->isEnabled() && lstSymbols->currentItem()->data( Qt::UserRole ).toString() != sy->pointSymbolName() )
lstSymbols->setEnabled( false );
if ( lstSymbols->isEnabled() && lstSymbols->currentIndex().isValid() )
{
QAbstractItemModel *m = lstSymbols->model();

if ( m->data( lstSymbols->currentIndex(), Qt::UserRole ).toString() != sy->pointSymbolName() )
lstSymbols->setEnabled( false );
}

if ( mPointSizeSpinBox->isEnabled() && !doubleNear( mPointSizeSpinBox->value(), sy->pointSize() ) )
mPointSizeSpinBox->setEnabled( false );
@@ -612,14 +634,12 @@ void QgsSingleSymbolDialog::setLabel( QString label )
mLabelEdit->setText( label );
}

void QgsSingleSymbolDialog::symbolChanged
( QListWidgetItem * current, QListWidgetItem * previous )
void QgsSingleSymbolDialog::symbolChanged( const QModelIndex &current, const QModelIndex &previous )
{
current->setBackground( QBrush( Qt::cyan ) );
if ( previous )
{
previous->setBackground( QBrush( Qt::white ) );
}
QAbstractItemModel *m = lstSymbols->model();
QgsDebugMsg( QString( "symbol changed to %1:%2" ).arg( current.row() ).arg( m->data( current, Qt::UserRole ).toString() ) );
// m->setData( current, Qt::UserRole+1, Qt::cyan );
// m->setData( prev, Qt::UserRole+1, Qt::white );
emit settingsChanged();
}

@@ -75,7 +75,7 @@ class QgsSingleSymbolDialog: public QDialog, private Ui::QgsSingleSymbolDialogBa
void selectOutlineColor();
void selectFillColor();
void selectTextureImage();
void symbolChanged( QListWidgetItem * current, QListWidgetItem * previous );
void symbolChanged( const QModelIndex &current, const QModelIndex &previous );
private:
/** Default constructor is private, do not use this */
QgsSingleSymbolDialog();
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>360</width>
<width>366</width>
<height>470</height>
</rect>
</property>
@@ -33,8 +33,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>337</width>
<height>616</height>
<width>350</width>
<height>604</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_5">
@@ -50,40 +50,6 @@
<string>Point Symbol</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0" colspan="3">
<widget class="QListWidget" name="lstSymbols">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragDrop</enum>
</property>
<property name="alternatingRowColors">
<bool>false</bool>
</property>
<property name="iconSize">
<size>
<width>0</width>
<height>-1</height>
</size>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
<property name="uniformItemSizes">
<bool>true</bool>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="textLabel1_2">
<property name="text">
@@ -120,6 +86,40 @@
<item row="2" column="2">
<layout class="QHBoxLayout" name="horizontalLayout"/>
</item>
<item row="0" column="0" colspan="3">
<widget class="QListView" name="lstSymbols">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragDrop</enum>
</property>
<property name="alternatingRowColors">
<bool>false</bool>
</property>
<property name="iconSize">
<size>
<width>0</width>
<height>-1</height>
</size>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
<property name="uniformItemSizes">
<bool>true</bool>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>

0 comments on commit cde5a06

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