23 #include <QTableWidgetItem> 24 #include <QItemDelegate> 26 #include <QDialogButtonBox> 33 , mRenderer( renderer )
34 , mForceOrderingEnabled( false )
38 tableLevels->setItemDelegate(
new SpinBoxDelegate(
this ) );
40 chkEnable->setChecked( usingSymbolLevels );
42 connect( chkEnable, &QAbstractButton::clicked,
this, &QgsSymbolLevelsWidget::updateUi );
55 tableLevels->setRowCount(
mList.count() );
56 for (
int i = 0; i <
mList.count(); i++ )
62 tableLevels->setVerticalHeaderItem( i,
new QTableWidgetItem( icon, QString() ) );
66 if ( layers > maxLayers )
70 tableLevels->setColumnCount( maxLayers + 1 );
71 tableLevels->setHorizontalHeaderItem( 0,
new QTableWidgetItem( QString() ) );
72 for (
int i = 0; i < maxLayers; i++ )
74 QString name = tr(
"Layer %1" ).arg( i );
75 tableLevels->setHorizontalHeaderItem( i + 1,
new QTableWidgetItem( name ) );
82 if ( !usingSymbolLevels )
87 connect( tableLevels, &QTableWidget::cellChanged,
this, &QgsSymbolLevelsWidget::renderingPassChanged );
92 for (
int row = 0; row <
mList.count(); row++ )
95 QString label =
mList.at( row ).label();
96 QTableWidgetItem *itemLabel =
new QTableWidgetItem( label );
97 itemLabel->setFlags( itemLabel->flags() ^ Qt::ItemIsEditable );
98 tableLevels->setItem( row, 0, itemLabel );
99 for (
int layer = 0; layer <
mMaxLayers; layer++ )
101 QTableWidgetItem *item =
nullptr;
104 item =
new QTableWidgetItem();
105 item->setFlags( Qt::ItemFlags() );
111 item =
new QTableWidgetItem( icon, QString::number( sl->
renderingPass() ) );
113 tableLevels->setItem( row, layer + 1, item );
114 tableLevels->resizeColumnToContents( 0 );
120 void QgsSymbolLevelsWidget::updateUi()
122 tableLevels->setEnabled( chkEnable->isChecked() );
128 for (
int i = 0; i <
mList.count(); i++ )
142 for (
int i = 0; i <
mList.count(); i++ )
154 return chkEnable->isChecked();
157 void QgsSymbolLevelsWidget::renderingPassChanged(
int row,
int column )
159 if ( row < 0 || row >=
mList.count() )
174 chkEnable->setChecked(
true );
184 QVBoxLayout *vLayout =
new QVBoxLayout();
186 vLayout->addWidget( mWidget );
187 QDialogButtonBox *bbox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
189 connect( bbox, &QDialogButtonBox::accepted,
this, &QgsSymbolLevelsDialog::accept );
190 connect( bbox, &QDialogButtonBox::rejected,
this, &QgsSymbolLevelsDialog::reject );
191 connect( bbox, &QDialogButtonBox::helpRequested,
this, &QgsSymbolLevelsDialog::showHelp );
192 vLayout->addWidget( bbox );
193 setLayout( vLayout );
194 setWindowTitle( tr(
"Symbol Levels" ) );
202 void QgsSymbolLevelsDialog::showHelp()
204 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#symbols-levels" ) );
209 QWidget *SpinBoxDelegate::createEditor( QWidget *parent,
const QStyleOptionViewItem &,
const QModelIndex & )
const 211 QSpinBox *editor =
new QSpinBox( parent );
212 editor->setMinimum( 0 );
213 editor->setMaximum( 999 );
217 void SpinBoxDelegate::setEditorData( QWidget *editor,
const QModelIndex &index )
const 219 int value = index.model()->data( index, Qt::EditRole ).toInt();
220 QSpinBox *spinBox =
static_cast<QSpinBox *
>( editor );
221 spinBox->setValue( value );
224 void SpinBoxDelegate::setModelData( QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index )
const 226 QSpinBox *spinBox =
static_cast<QSpinBox *
>( editor );
227 spinBox->interpretText();
228 int value = spinBox->value();
230 model->setData( index, value, Qt::EditRole );
233 void SpinBoxDelegate::updateEditorGeometry( QWidget *editor,
const QStyleOptionViewItem &option,
const QModelIndex & )
const 235 editor->setGeometry( option.rect );
virtual QgsLegendSymbolList legendSymbolItems() const
Returns a list of symbology items for the legend.
void setRenderingPass(int renderingPass)
QgsSymbol * symbol() const
Returns associated symbol. May be null.
void setForceOrderingEnabled(bool enabled)
void setUsingSymbolLevels(bool usingSymbolLevels)
int symbolLayerCount() const
Returns total number of symbol layers contained in the symbol.
static QIcon symbolLayerPreviewIcon(QgsSymbolLayer *layer, QgsUnitTypes::RenderUnit u, QSize size, const QgsMapUnitScale &scale=QgsMapUnitScale())
Draws a symbol layer preview to an icon.
int renderingPass() const
static QIcon symbolPreviewIcon(QgsSymbol *symbol, QSize size, int padding=0)
Returns an icon preview for a color ramp.
QgsSymbolLayer * symbolLayer(int layer)
Returns a specific symbol layers contained in the symbol.
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
Gets 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.