24 #include <QTableWidgetItem> 25 #include <QItemDelegate> 27 #include <QDialogButtonBox> 34 , mRenderer( renderer )
35 , mForceOrderingEnabled( false )
39 tableLevels->setItemDelegate(
new SpinBoxDelegate(
this ) );
41 chkEnable->setChecked( usingSymbolLevels );
43 connect( chkEnable, &QAbstractButton::clicked,
this, &QgsSymbolLevelsWidget::updateUi );
58 tableLevels->setRowCount(
mList.count() );
59 for (
int i = 0; i <
mList.count(); i++ )
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 ) );
85 if ( !usingSymbolLevels )
90 connect( tableLevels, &QTableWidget::cellChanged,
this, &QgsSymbolLevelsWidget::renderingPassChanged );
96 for (
int row = 0; row <
mList.count(); row++ )
99 QString label =
mList.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 );
124 void QgsSymbolLevelsWidget::updateUi()
126 tableLevels->setEnabled( chkEnable->isChecked() );
132 for (
int i = 0; i <
mList.count(); i++ )
146 for (
int i = 0; i <
mList.count(); i++ )
158 return chkEnable->isChecked();
161 void QgsSymbolLevelsWidget::renderingPassChanged(
int row,
int column )
163 if ( row < 0 || row >=
mList.count() )
178 chkEnable->setChecked(
true );
188 QVBoxLayout *vLayout =
new QVBoxLayout();
190 vLayout->addWidget( mWidget );
191 QDialogButtonBox *bbox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
193 connect( bbox, &QDialogButtonBox::accepted,
this, &QgsSymbolLevelsDialog::accept );
194 connect( bbox, &QDialogButtonBox::rejected,
this, &QgsSymbolLevelsDialog::reject );
195 connect( bbox, &QDialogButtonBox::helpRequested,
this, &QgsSymbolLevelsDialog::showHelp );
196 vLayout->addWidget( bbox );
197 setLayout( vLayout );
198 setWindowTitle( tr(
"Symbol Levels" ) );
206 void QgsSymbolLevelsDialog::showHelp()
208 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#symbols-levels" ) );
213 QWidget *SpinBoxDelegate::createEditor( QWidget *parent,
const QStyleOptionViewItem &,
const QModelIndex & )
const 215 QSpinBox *editor =
new QSpinBox( parent );
216 editor->setMinimum( 0 );
217 editor->setMaximum( 999 );
221 void SpinBoxDelegate::setEditorData( QWidget *editor,
const QModelIndex &index )
const 223 int value = index.model()->data( index, Qt::EditRole ).toInt();
224 QSpinBox *spinBox =
static_cast<QSpinBox *
>( editor );
225 spinBox->setValue( value );
228 void SpinBoxDelegate::setModelData( QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index )
const 230 QSpinBox *spinBox =
static_cast<QSpinBox *
>( editor );
231 spinBox->interpretText();
232 int value = spinBox->value();
234 model->setData( index, value, Qt::EditRole );
237 void SpinBoxDelegate::updateEditorGeometry( QWidget *editor,
const QStyleOptionViewItem &option,
const QModelIndex & )
const 239 editor->setGeometry( option.rect );
virtual QgsLegendSymbolList legendSymbolItems() const
Returns a list of symbology items for the legend.
static QIcon symbolLayerPreviewIcon(const QgsSymbolLayer *layer, QgsUnitTypes::RenderUnit u, QSize size, const QgsMapUnitScale &scale=QgsMapUnitScale())
Draws a symbol layer preview to an icon.
void setRenderingPass(int renderingPass)
Specifies the rendering pass in which this symbol layer should be rendered.
Abstract base class for all rendered symbols.
int scaleIconSize(int standardSize)
Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly...
static QIcon symbolPreviewIcon(const QgsSymbol *symbol, QSize size, int padding=0)
Returns an icon preview for a color ramp.
void setForceOrderingEnabled(bool enabled)
void setUsingSymbolLevels(bool usingSymbolLevels)
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
int renderingPass() const
Specifies the rendering pass in which this symbol layer should be rendered.
QgsSymbolLayer * symbolLayer(int layer)
Returns the symbol layer at the specified index.
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
virtual void setLegendSymbolItem(const QString &key, QgsSymbol *symbol)
Sets the symbol to be used for a legend symbol item.
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
QgsSymbolLevelsDialog(QgsFeatureRenderer *renderer, bool usingSymbolLevels, QWidget *parent=nullptr)
Constructor for QgsSymbolLevelsDialog.