24#include <QTableWidgetItem>
25#include <QItemDelegate>
27#include <QDialogButtonBox>
43 tableLevels->setItemDelegate(
new SpinBoxDelegate(
this ) );
45 chkEnable->setChecked( usingSymbolLevels );
47 connect( chkEnable, &QAbstractButton::clicked,
this, &QgsSymbolLevelsWidget::updateUi );
53 mLegendSymbols << item;
58 tableLevels->setRowCount( mLegendSymbols.count() );
59 for (
int i = 0; i < mLegendSymbols.count(); i++ )
61 QgsSymbol *sym = mLegendSymbols.at( i ).symbol();
65 tableLevels->setVerticalHeaderItem( i,
new QTableWidgetItem( icon, QString() ) );
69 if ( layers > maxLayers )
73 tableLevels->setColumnCount( maxLayers + 1 );
74 tableLevels->setHorizontalHeaderItem( 0,
new QTableWidgetItem( QString() ) );
75 for (
int i = 0; i < maxLayers; i++ )
77 QString name = tr(
"Layer %1" ).arg( i );
78 tableLevels->setHorizontalHeaderItem( i + 1,
new QTableWidgetItem( name ) );
81 mMaxLayers = maxLayers;
85 if ( !usingSymbolLevels )
90 connect( tableLevels, &QTableWidget::cellChanged,
this, &QgsSymbolLevelsWidget::renderingPassChanged );
94void QgsSymbolLevelsWidget::populateTable()
97 for (
int row = 0; row < mLegendSymbols.count(); row++ )
99 QgsSymbol *sym = mLegendSymbols.at( row ).symbol();
100 const QString label = mLegendSymbols.at( row ).label();
101 QTableWidgetItem *itemLabel =
new QTableWidgetItem( label );
102 itemLabel->setFlags( itemLabel->flags() ^ Qt::ItemIsEditable );
103 tableLevels->setItem( row, 0, itemLabel );
104 for (
int layer = 0; layer < mMaxLayers; layer++ )
106 QTableWidgetItem *item =
nullptr;
109 item =
new QTableWidgetItem();
110 item->setFlags( Qt::ItemFlags() );
116 item =
new QTableWidgetItem( icon, QString::number( sl->
renderingPass() ) );
118 tableLevels->setItem( row, layer + 1, item );
119 tableLevels->resizeColumnToContents( 0 );
124void QgsSymbolLevelsWidget::updateUi()
126 tableLevels->setEnabled( chkEnable->isChecked() );
147void QgsSymbolLevelsWidget::setDefaultLevels()
161 return chkEnable->isChecked();
166 return mLegendSymbols;
169void QgsSymbolLevelsWidget::renderingPassChanged(
int row,
int column )
171 if ( row < 0 || row >= mLegendSymbols.count() )
173 QgsSymbol *sym = mLegendSymbols.at( row ).symbol();
183 mForceOrderingEnabled = enabled;
186 chkEnable->setChecked(
true );
201 QVBoxLayout *vLayout =
new QVBoxLayout();
203 vLayout->addWidget( mWidget );
204 QDialogButtonBox *bbox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
205 connect( bbox, &QDialogButtonBox::accepted,
this, &QgsSymbolLevelsDialog::accept );
206 connect( bbox, &QDialogButtonBox::rejected,
this, &QgsSymbolLevelsDialog::reject );
207 connect( bbox, &QDialogButtonBox::helpRequested,
this, &QgsSymbolLevelsDialog::showHelp );
208 vLayout->addWidget( bbox );
209 setLayout( vLayout );
210 setWindowTitle( tr(
"Symbol Levels" ) );
228void QgsSymbolLevelsDialog::showHelp()
230 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#symbols-levels" ) );
235QWidget *SpinBoxDelegate::createEditor( QWidget *parent,
const QStyleOptionViewItem &,
const QModelIndex & )
const
237 QSpinBox *editor =
new QSpinBox( parent );
238 editor->setMinimum( 0 );
239 editor->setMaximum( 999 );
243void SpinBoxDelegate::setEditorData( QWidget *editor,
const QModelIndex &index )
const
245 int value = index.model()->data( index, Qt::EditRole ).toInt();
246 QSpinBox *spinBox =
static_cast<QSpinBox *
>( editor );
247 spinBox->setValue( value );
250void SpinBoxDelegate::setModelData( QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index )
const
252 QSpinBox *spinBox =
static_cast<QSpinBox *
>( editor );
253 spinBox->interpretText();
254 int value = spinBox->value();
256 model->setData( index, value, Qt::EditRole );
259void SpinBoxDelegate::updateEditorGeometry( QWidget *editor,
const QStyleOptionViewItem &option,
const QModelIndex & )
const
261 editor->setGeometry( option.rect );
virtual void setLegendSymbolItem(const QString &key, QgsSymbol *symbol)
Sets the symbol to be used for a legend symbol item.
void setUsingSymbolLevels(bool usingSymbolLevels)
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
Struct for storing maximum and minimum scales for measurements in map units.
static QIcon symbolLayerPreviewIcon(const QgsSymbolLayer *layer, QgsUnitTypes::RenderUnit u, QSize size, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::SymbolType parentSymbolType=Qgis::SymbolType::Hybrid, QgsMapLayer *mapLayer=nullptr)
Draws a symbol layer preview to an icon.
static QIcon symbolPreviewIcon(const QgsSymbol *symbol, QSize size, int padding=0, QgsLegendPatchShape *shape=nullptr)
Returns an icon preview for a color ramp.
void setRenderingPass(int renderingPass)
Specifies the rendering pass in which this symbol layer should be rendered.
int renderingPass() const
Specifies the rendering pass in which this symbol layer should be rendered.
QgsLegendSymbolList symbolLevels() const
Returns the current legend symbols with rendering passes set, as defined in the widget.
QgsSymbolLevelsDialog(QgsFeatureRenderer *renderer, bool usingSymbolLevels, QWidget *parent=nullptr)
Constructor for QgsSymbolLevelsDialog.
bool usingLevels() const
Returns whether the level ordering is enabled.
void setForceOrderingEnabled(bool enabled)
Abstract base class for all rendered symbols.
QgsSymbolLayer * symbolLayer(int layer)
Returns the symbol layer at the specified index.
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
Qgis::SymbolType type() const
Returns the symbol's type.
@ RenderMillimeters
Millimeters.
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly,...
QList< QgsLegendSymbolItem > QgsLegendSymbolList