mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-23 00:03:02 -04:00
change list to view in single symbol dialog
git-svn-id: http://svn.osgeo.org/qgis/trunk@14392 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
b21747bc96
commit
cde5a0693b
@ -30,11 +30,48 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QListWidgetItem>
|
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
|
||||||
#define DO_NOT_USE_STR "<off>"
|
#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 )
|
QgsSingleSymbolDialog::QgsSingleSymbolDialog(): QDialog(), mVectorLayer( 0 )
|
||||||
{
|
{
|
||||||
setupUi( this );
|
setupUi( this );
|
||||||
@ -71,8 +108,8 @@ QgsSingleSymbolDialog::QgsSingleSymbolDialog( QgsVectorLayer * layer, bool disab
|
|||||||
connect( btnFillColor, SIGNAL( clicked() ), this, SLOT( selectFillColor() ) );
|
connect( btnFillColor, SIGNAL( clicked() ), this, SLOT( selectFillColor() ) );
|
||||||
connect( outlinewidthspinbox, SIGNAL( valueChanged( double ) ), this, SLOT( resendSettingsChanged() ) );
|
connect( outlinewidthspinbox, SIGNAL( valueChanged( double ) ), this, SLOT( resendSettingsChanged() ) );
|
||||||
connect( mLabelEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( resendSettingsChanged() ) );
|
connect( mLabelEdit, SIGNAL( textChanged( const QString& ) ), this, SLOT( resendSettingsChanged() ) );
|
||||||
connect( lstSymbols, SIGNAL( currentItemChanged( QListWidgetItem *, QListWidgetItem * ) ),
|
connect( lstSymbols, SIGNAL( currentChanged( const QModelIndex & , const QModelIndex & ) ),
|
||||||
this, SLOT( symbolChanged( QListWidgetItem *, QListWidgetItem * ) ) );
|
this, SLOT( symbolChanged( const QModelIndex & , const QModelIndex & ) ) );
|
||||||
connect( mPointSizeSpinBox, SIGNAL( valueChanged( double ) ), this, SLOT( resendSettingsChanged() ) );
|
connect( mPointSizeSpinBox, SIGNAL( valueChanged( double ) ), this, SLOT( resendSettingsChanged() ) );
|
||||||
connect( mPointSizeUnitsCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( resendSettingsChanged() ) );
|
connect( mPointSizeUnitsCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( resendSettingsChanged() ) );
|
||||||
connect( mRotationClassificationComboBox, SIGNAL( currentIndexChanged( const QString & ) ),
|
connect( mRotationClassificationComboBox, SIGNAL( currentIndexChanged( const QString & ) ),
|
||||||
@ -95,32 +132,8 @@ QgsSingleSymbolDialog::QgsSingleSymbolDialog( QgsVectorLayer * layer, bool disab
|
|||||||
|
|
||||||
void QgsSingleSymbolDialog::refreshMarkers()
|
void QgsSingleSymbolDialog::refreshMarkers()
|
||||||
{
|
{
|
||||||
lstSymbols->blockSignals( true );
|
QgsMarkerListModel *m = new QgsMarkerListModel( lstSymbols );
|
||||||
lstSymbols->clear();
|
lstSymbols->setModel( m );
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find out the numerical fields of mVectorLayer, and populate the ComboBoxes
|
// Find out the numerical fields of mVectorLayer, and populate the ComboBoxes
|
||||||
QgsVectorDataProvider *provider = mVectorLayer->dataProvider();
|
QgsVectorDataProvider *provider = mVectorLayer->dataProvider();
|
||||||
@ -283,9 +296,10 @@ void QgsSingleSymbolDialog::apply( QgsSymbol *sy )
|
|||||||
//
|
//
|
||||||
// Apply point symbol
|
// 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() )
|
if ( mPointSizeSpinBox->isEnabled() )
|
||||||
@ -376,12 +390,15 @@ void QgsSingleSymbolDialog::set( const QgsSymbol *sy )
|
|||||||
|
|
||||||
// Set point symbol
|
// Set point symbol
|
||||||
QString mySymbolName = sy->pointSymbolName();
|
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->setCurrentIndex( idx );
|
||||||
lstSymbols->item( i )->setBackground( QBrush( Qt::cyan ) );
|
// m->setData( idx, Qt::UserRole+1, Qt::cyan );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -478,8 +495,13 @@ void QgsSingleSymbolDialog::updateSet( const QgsSymbol *sy )
|
|||||||
if ( mLabelEdit->isEnabled() && mLabelEdit->text() != sy->label() )
|
if ( mLabelEdit->isEnabled() && mLabelEdit->text() != sy->label() )
|
||||||
mLabelEdit->setEnabled( false );
|
mLabelEdit->setEnabled( false );
|
||||||
|
|
||||||
if ( lstSymbols->isEnabled() && lstSymbols->currentItem()->data( Qt::UserRole ).toString() != sy->pointSymbolName() )
|
if ( lstSymbols->isEnabled() && lstSymbols->currentIndex().isValid() )
|
||||||
|
{
|
||||||
|
QAbstractItemModel *m = lstSymbols->model();
|
||||||
|
|
||||||
|
if ( m->data( lstSymbols->currentIndex(), Qt::UserRole ).toString() != sy->pointSymbolName() )
|
||||||
lstSymbols->setEnabled( false );
|
lstSymbols->setEnabled( false );
|
||||||
|
}
|
||||||
|
|
||||||
if ( mPointSizeSpinBox->isEnabled() && !doubleNear( mPointSizeSpinBox->value(), sy->pointSize() ) )
|
if ( mPointSizeSpinBox->isEnabled() && !doubleNear( mPointSizeSpinBox->value(), sy->pointSize() ) )
|
||||||
mPointSizeSpinBox->setEnabled( false );
|
mPointSizeSpinBox->setEnabled( false );
|
||||||
@ -612,14 +634,12 @@ void QgsSingleSymbolDialog::setLabel( QString label )
|
|||||||
mLabelEdit->setText( label );
|
mLabelEdit->setText( label );
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsSingleSymbolDialog::symbolChanged
|
void QgsSingleSymbolDialog::symbolChanged( const QModelIndex ¤t, const QModelIndex &previous )
|
||||||
( QListWidgetItem * current, QListWidgetItem * previous )
|
|
||||||
{
|
{
|
||||||
current->setBackground( QBrush( Qt::cyan ) );
|
QAbstractItemModel *m = lstSymbols->model();
|
||||||
if ( previous )
|
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 );
|
||||||
previous->setBackground( QBrush( Qt::white ) );
|
// m->setData( prev, Qt::UserRole+1, Qt::white );
|
||||||
}
|
|
||||||
emit settingsChanged();
|
emit settingsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ class QgsSingleSymbolDialog: public QDialog, private Ui::QgsSingleSymbolDialogBa
|
|||||||
void selectOutlineColor();
|
void selectOutlineColor();
|
||||||
void selectFillColor();
|
void selectFillColor();
|
||||||
void selectTextureImage();
|
void selectTextureImage();
|
||||||
void symbolChanged( QListWidgetItem * current, QListWidgetItem * previous );
|
void symbolChanged( const QModelIndex ¤t, const QModelIndex &previous );
|
||||||
private:
|
private:
|
||||||
/** Default constructor is private, do not use this */
|
/** Default constructor is private, do not use this */
|
||||||
QgsSingleSymbolDialog();
|
QgsSingleSymbolDialog();
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>360</width>
|
<width>366</width>
|
||||||
<height>470</height>
|
<height>470</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@ -33,8 +33,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>337</width>
|
<width>350</width>
|
||||||
<height>616</height>
|
<height>604</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_5">
|
<layout class="QGridLayout" name="gridLayout_5">
|
||||||
@ -50,40 +50,6 @@
|
|||||||
<string>Point Symbol</string>
|
<string>Point Symbol</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_4">
|
<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">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="textLabel1_2">
|
<widget class="QLabel" name="textLabel1_2">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -120,6 +86,40 @@
|
|||||||
<item row="2" column="2">
|
<item row="2" column="2">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout"/>
|
<layout class="QHBoxLayout" name="horizontalLayout"/>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user