Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed #3006 and added a convenience spin box for setting symbol level…
…s (constrained to 0-999)

git-svn-id: http://svn.osgeo.org/qgis/trunk@14454 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Oct 30, 2010
1 parent b21f5e6 commit 1494e42
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -840,6 +840,8 @@ void QgsVectorLayer::drawRendererV2Levels( QgsRenderContext& rendererContext, bo
for ( int j = 0; j < sym->symbolLayerCount(); j++ )
{
int level = sym->symbolLayer( j )->renderingPass();
if ( level < 0 || level >= 1000 ) // ignore invalid levels
continue;
QgsSymbolV2LevelItem item( sym, j );
while ( level >= levels.count() ) // append new empty levels
levels.append( QgsSymbolV2Level() );
Expand Down
43 changes: 43 additions & 0 deletions src/gui/symbology-ng/qgssymbollevelsv2dialog.cpp
Expand Up @@ -6,12 +6,55 @@
#include "qgssymbolv2.h"

#include <QTableWidgetItem>
#include <QItemDelegate>
#include <QSpinBox>

// delegate used from Qt Spin Box example
class SpinBoxDelegate : public QItemDelegate
{
public:
SpinBoxDelegate(QObject *parent = 0) : QItemDelegate(parent) {}

QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem & /*option*/, const QModelIndex &/*index*/) const
{
QSpinBox *editor = new QSpinBox(parent);
editor->setMinimum(0);
editor->setMaximum(999);
return editor;
}

void setEditorData(QWidget *editor, const QModelIndex &index) const
{
int value = index.model()->data(index, Qt::EditRole).toInt();
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
spinBox->setValue(value);
}

void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
spinBox->interpretText();
int value = spinBox->value();

model->setData(index, value, Qt::EditRole);
}

void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex & /*index*/) const
{
editor->setGeometry(option.rect);
}

};

////////////////

QgsSymbolLevelsV2Dialog::QgsSymbolLevelsV2Dialog( QgsSymbolV2List symbols, bool usingSymbolLevels, QWidget* parent )
: QDialog( parent ), mSymbols( symbols )
{
setupUi( this );

tableLevels->setItemDelegate( new SpinBoxDelegate(this) );

chkEnable->setChecked( usingSymbolLevels );

connect( chkEnable, SIGNAL( clicked() ), this, SLOT( updateUi() ) );
Expand Down

0 comments on commit 1494e42

Please sign in to comment.