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 );
94 void 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 );
124 void QgsSymbolLevelsWidget::updateUi()
126 tableLevels->setEnabled( chkEnable->isChecked() );
147 void QgsSymbolLevelsWidget::setDefaultLevels()
161 return chkEnable->isChecked();
166 return mLegendSymbols;
169 void 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" ) );
228 void QgsSymbolLevelsDialog::showHelp()
230 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#symbols-levels" ) );
235 QWidget *SpinBoxDelegate::createEditor( QWidget *parent,
const QStyleOptionViewItem &,
const QModelIndex & )
const
237 QSpinBox *editor =
new QSpinBox( parent );
238 editor->setMinimum( 0 );
239 editor->setMaximum( 999 );
243 void 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 );
250 void 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 );
259 void SpinBoxDelegate::updateEditorGeometry( QWidget *editor,
const QStyleOptionViewItem &option,
const QModelIndex & )
const
261 editor->setGeometry( option.rect );