23#include <QTableWidgetItem>
24#include <QItemDelegate>
26#include <QDialogButtonBox>
42 tableLevels->setItemDelegate(
new SpinBoxDelegate(
this ) );
44 chkEnable->setChecked( usingSymbolLevels );
46 connect( chkEnable, &QAbstractButton::clicked,
this, &QgsSymbolLevelsWidget::updateUi );
52 mLegendSymbols << item;
57 tableLevels->setRowCount( mLegendSymbols.count() );
58 for (
int i = 0; i < mLegendSymbols.count(); i++ )
60 QgsSymbol *sym = mLegendSymbols.at( i ).symbol();
64 tableLevels->setVerticalHeaderItem( i,
new QTableWidgetItem( icon, QString() ) );
68 if ( layers > maxLayers )
72 tableLevels->setColumnCount( maxLayers + 1 );
73 tableLevels->setHorizontalHeaderItem( 0,
new QTableWidgetItem( QString() ) );
74 for (
int i = 0; i < maxLayers; i++ )
76 QString name = tr(
"Layer %1" ).arg( i );
77 tableLevels->setHorizontalHeaderItem( i + 1,
new QTableWidgetItem( name ) );
80 mMaxLayers = maxLayers;
84 if ( !usingSymbolLevels )
89 connect( tableLevels, &QTableWidget::cellChanged,
this, &QgsSymbolLevelsWidget::renderingPassChanged );
93void QgsSymbolLevelsWidget::populateTable()
96 for (
int row = 0; row < mLegendSymbols.count(); row++ )
98 QgsSymbol *sym = mLegendSymbols.at( row ).symbol();
99 const QString label = mLegendSymbols.at( row ).label();
100 QTableWidgetItem *itemLabel =
new QTableWidgetItem( label );
101 itemLabel->setFlags( itemLabel->flags() ^ Qt::ItemIsEditable );
102 tableLevels->setItem( row, 0, itemLabel );
103 for (
int layer = 0; layer < mMaxLayers; layer++ )
105 QTableWidgetItem *item =
nullptr;
108 item =
new QTableWidgetItem();
109 item->setFlags( Qt::ItemFlags() );
115 item =
new QTableWidgetItem( icon, QString::number( sl->
renderingPass() ) );
117 tableLevels->setItem( row, layer + 1, item );
118 tableLevels->resizeColumnToContents( 0 );
123void QgsSymbolLevelsWidget::updateUi()
125 tableLevels->setEnabled( chkEnable->isChecked() );
146void QgsSymbolLevelsWidget::setDefaultLevels()
160 return chkEnable->isChecked();
165 return mLegendSymbols;
168void QgsSymbolLevelsWidget::renderingPassChanged(
int row,
int column )
170 if ( row < 0 || row >= mLegendSymbols.count() )
172 QgsSymbol *sym = mLegendSymbols.at( row ).symbol();
182 mForceOrderingEnabled = enabled;
185 chkEnable->setChecked(
true );
200 QVBoxLayout *vLayout =
new QVBoxLayout();
202 vLayout->addWidget( mWidget );
203 QDialogButtonBox *bbox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
204 connect( bbox, &QDialogButtonBox::accepted,
this, &QgsSymbolLevelsDialog::accept );
205 connect( bbox, &QDialogButtonBox::rejected,
this, &QgsSymbolLevelsDialog::reject );
206 connect( bbox, &QDialogButtonBox::helpRequested,
this, &QgsSymbolLevelsDialog::showHelp );
207 vLayout->addWidget( bbox );
208 setLayout( vLayout );
209 setWindowTitle( tr(
"Symbol Levels" ) );
227void QgsSymbolLevelsDialog::showHelp()
229 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#symbols-levels" ) );
234QWidget *SpinBoxDelegate::createEditor( QWidget *parent,
const QStyleOptionViewItem &,
const QModelIndex & )
const
236 QSpinBox *editor =
new QSpinBox( parent );
237 editor->setMinimum( 0 );
238 editor->setMaximum( 999 );
242void SpinBoxDelegate::setEditorData( QWidget *editor,
const QModelIndex &index )
const
244 int value = index.model()->data( index, Qt::EditRole ).toInt();
245 QSpinBox *spinBox =
static_cast<QSpinBox *
>( editor );
246 spinBox->setValue( value );
249void SpinBoxDelegate::setModelData( QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index )
const
251 QSpinBox *spinBox =
static_cast<QSpinBox *
>( editor );
252 spinBox->interpretText();
253 int value = spinBox->value();
255 model->setData( index, value, Qt::EditRole );
258void SpinBoxDelegate::updateEditorGeometry( QWidget *editor,
const QStyleOptionViewItem &option,
const QModelIndex & )
const
260 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.
Stores properties relating to a screen.
static QIcon symbolLayerPreviewIcon(const QgsSymbolLayer *layer, Qgis::RenderUnit u, QSize size, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::SymbolType parentSymbolType=Qgis::SymbolType::Hybrid, QgsMapLayer *mapLayer=nullptr, const QgsScreenProperties &screen=QgsScreenProperties())
Draws a symbol layer preview to an icon.
static QIcon symbolPreviewIcon(const QgsSymbol *symbol, QSize size, int padding=0, QgsLegendPatchShape *shape=nullptr, const QgsScreenProperties &screen=QgsScreenProperties())
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.
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