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 );
57 tableLevels->setRowCount(
mList.count() );
58 for (
int i = 0; i <
mList.count(); i++ )
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 ) );
84 if ( !usingSymbolLevels )
89 connect( tableLevels, &QTableWidget::cellChanged,
this, &QgsSymbolLevelsWidget::renderingPassChanged );
95 for (
int row = 0; row <
mList.count(); row++ )
98 QString label =
mList.at( row ).label();
99 QTableWidgetItem *itemLabel =
new QTableWidgetItem( label );
100 itemLabel->setFlags( itemLabel->flags() ^ Qt::ItemIsEditable );
101 tableLevels->setItem( row, 0, itemLabel );
102 for (
int layer = 0; layer <
mMaxLayers; layer++ )
104 QTableWidgetItem *item =
nullptr;
107 item =
new QTableWidgetItem();
108 item->setFlags( Qt::ItemFlags() );
114 item =
new QTableWidgetItem( icon, QString::number( sl->
renderingPass() ) );
116 tableLevels->setItem( row, layer + 1, item );
117 tableLevels->resizeColumnToContents( 0 );
123 void QgsSymbolLevelsWidget::updateUi()
125 tableLevels->setEnabled( chkEnable->isChecked() );
131 for (
int i = 0; i <
mList.count(); i++ )
145 for (
int i = 0; i <
mList.count(); i++ )
157 return chkEnable->isChecked();
160 void QgsSymbolLevelsWidget::renderingPassChanged(
int row,
int column )
162 if ( row < 0 || row >=
mList.count() )
177 chkEnable->setChecked(
true );
187 QVBoxLayout *vLayout =
new QVBoxLayout();
189 vLayout->addWidget( mWidget );
190 QDialogButtonBox *bbox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
192 connect( bbox, &QDialogButtonBox::accepted,
this, &QgsSymbolLevelsDialog::accept );
193 connect( bbox, &QDialogButtonBox::rejected,
this, &QgsSymbolLevelsDialog::reject );
194 connect( bbox, &QDialogButtonBox::helpRequested,
this, &QgsSymbolLevelsDialog::showHelp );
195 vLayout->addWidget( bbox );
196 setLayout( vLayout );
197 setWindowTitle( tr(
"Symbol Levels" ) );
205 void QgsSymbolLevelsDialog::showHelp()
207 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#symbols-levels" ) );
212 QWidget *SpinBoxDelegate::createEditor( QWidget *parent,
const QStyleOptionViewItem &,
const QModelIndex & )
const 214 QSpinBox *editor =
new QSpinBox( parent );
215 editor->setMinimum( 0 );
216 editor->setMaximum( 999 );
220 void SpinBoxDelegate::setEditorData( QWidget *editor,
const QModelIndex &index )
const 222 int value = index.model()->data( index, Qt::EditRole ).toInt();
223 QSpinBox *spinBox =
static_cast<QSpinBox *
>( editor );
224 spinBox->setValue( value );
227 void SpinBoxDelegate::setModelData( QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index )
const 229 QSpinBox *spinBox =
static_cast<QSpinBox *
>( editor );
230 spinBox->interpretText();
231 int value = spinBox->value();
233 model->setData( index, value, Qt::EditRole );
236 void SpinBoxDelegate::updateEditorGeometry( QWidget *editor,
const QStyleOptionViewItem &option,
const QModelIndex & )
const 238 editor->setGeometry( option.rect );
void setRenderingPass(int renderingPass)
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...
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
virtual QgsLegendSymbolList legendSymbolItems() const
Returns a list of symbology items for the legend.
void setForceOrderingEnabled(bool enabled)
void setUsingSymbolLevels(bool usingSymbolLevels)
static QIcon symbolLayerPreviewIcon(QgsSymbolLayer *layer, QgsUnitTypes::RenderUnit u, QSize size, const QgsMapUnitScale &scale=QgsMapUnitScale())
Draws a symbol layer preview to an icon.
static QIcon symbolPreviewIcon(QgsSymbol *symbol, QSize size, int padding=0)
Returns an icon preview for a color ramp.
int renderingPass() const
QgsSymbolLayer * symbolLayer(int layer)
Returns a specific symbol layer 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
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.
QgsSymbol * symbol() const
Returns associated symbol. May be null.
QgsSymbolLevelsDialog(QgsFeatureRenderer *renderer, bool usingSymbolLevels, QWidget *parent=nullptr)
Constructor for QgsSymbolLevelsDialog.