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 );
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 );
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() );
158 return chkEnable->isChecked();
161 void QgsSymbolLevelsWidget::renderingPassChanged(
int row,
int column )
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 );