29 #include <QStandardItemModel>
30 #include <QStandardItem>
32 #include <QToolButton>
36 static const int EFFECT_ITEM_TYPE = QStandardItem::UserType + 1;
38 class EffectItem :
public QStandardItem
45 mWidget = propertiesWidget;
54 int type()
const override {
return EFFECT_ITEM_TYPE; }
61 QVariant data(
int role )
const override
63 if ( role == Qt::DisplayRole || role == Qt::EditRole )
67 if ( role == Qt::CheckStateRole )
69 return mEffect->enabled() ? Qt::Checked : Qt::Unchecked;
71 return QStandardItem::data( role );
74 void setData(
const QVariant &value,
int role )
override
76 if ( role == Qt::CheckStateRole )
78 mEffect->setEnabled( value.toBool() );
79 mWidget->updatePreview();
83 QStandardItem::setData( value, role );
111 this->layout()->setContentsMargins( 0, 0, 0, 0 );
113 mEffectsList->setMaximumHeight(
static_cast< int >(
Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 7 ) );
114 mEffectsList->setMinimumHeight( mEffectsList->maximumHeight() );
115 lblPreview->setMaximumWidth( mEffectsList->maximumHeight() );
122 mModel =
new QStandardItemModel();
124 mEffectsList->setModel(
mModel );
126 QItemSelectionModel *selModel = mEffectsList->selectionModel();
150 const QModelIndex newIndex = mEffectsList->model()->index( initialRow, 0 );
151 mEffectsList->setCurrentIndex( newIndex );
171 EffectItem *parent =
static_cast<EffectItem *
>(
mModel->invisibleRootItem() );
174 for (
int i = count - 1; i >= 0; i-- )
176 EffectItem *effectItem =
new EffectItem(
stack->
effect( i ),
this );
177 effectItem->setEditable(
false );
178 parent->appendRow( effectItem );
191 const QModelIndex currentIdx = mEffectsList->currentIndex();
192 if ( !currentIdx.isValid() )
195 EffectItem *item =
static_cast<EffectItem *
>(
mModel->itemFromIndex( currentIdx ) );
197 QStandardItem *root =
mModel->invisibleRootItem();
198 const int rowCount = root->rowCount();
199 const int currentRow = item ? item->row() : 0;
201 mUpButton->setEnabled( currentRow > 0 );
202 mDownButton->setEnabled( currentRow < rowCount - 1 );
203 mRemoveButton->setEnabled( rowCount > 1 );
209 QImage previewImage( 100, 100, QImage::Format_ARGB32 );
210 previewImage.fill( Qt::transparent );
211 painter.begin( &previewImage );
212 painter.setRenderHint( QPainter::Antialiasing );
218 QPainter previewPicPainter;
219 previewPicPainter.begin( &previewPic );
220 previewPicPainter.setPen( Qt::red );
221 previewPicPainter.setBrush( QColor( 255, 100, 100, 255 ) );
222 previewPicPainter.drawEllipse( QPoint( 50, 50 ), 20, 20 );
223 previewPicPainter.end();
228 context.
painter()->translate( 20, 20 );
233 lblPreview->setPixmap( QPixmap::fromImage( previewImage ) );
239 const QModelIndex idx = mEffectsList->currentIndex();
240 if ( !idx.isValid() )
243 EffectItem *item =
static_cast<EffectItem *
>(
mModel->itemFromIndex( idx ) );
264 const int index = stackedWidget->addWidget( widget );
265 stackedWidget->setCurrentIndex( index );
280 EffectItem *newEffectItem =
new EffectItem( newEffect,
this );
283 mEffectsList->setCurrentIndex(
mModel->indexFromItem( newEffectItem ) );
291 const int row = item->row();
292 QStandardItem *root =
mModel->invisibleRootItem();
294 const int layerIdx = root->rowCount() - row - 1;
297 mModel->invisibleRootItem()->removeRow( row );
299 const int newSelection = std::min( row, root->rowCount() - 1 );
300 const QModelIndex newIdx = root->child( newSelection )->index();
301 mEffectsList->setCurrentIndex( newIdx );
325 const int row = item->row();
327 QStandardItem *root =
mModel->invisibleRootItem();
329 const int layerIdx = root->rowCount() - row - 1;
334 QList<QStandardItem *> toMove = root->takeRow( row );
335 root->insertRows( row + offset, toMove );
337 const QModelIndex newIdx = toMove[ 0 ]->index();
338 mEffectsList->setCurrentIndex( newIdx );
347 item->setEffect( newEffect );
349 QStandardItem *root =
mModel->invisibleRootItem();
350 const int effectIdx = root->rowCount() - item->row() - 1;
364 :
QgsDialog( parent, f, QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok )
367 setWindowTitle( tr(
"Effect Properties" ) );
370 QDialogButtonBox *
buttonBox = this->findChild<QDialogButtonBox *>( QString(), Qt::FindDirectChildrenOnly );
371 connect(
buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsEffectStackPropertiesDialog::showHelp );
386 void QgsEffectStackPropertiesDialog::showHelp()
388 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#draw-effects" ) );
400 QHBoxLayout *layout =
new QHBoxLayout();
401 layout->setContentsMargins( 0, 0, 0, 0 );
402 layout->setSpacing( 6 );
405 mEnabledCheckBox =
new QCheckBox(
this );
406 mEnabledCheckBox->setText( tr(
"Draw effects" ) );
407 layout->addWidget( mEnabledCheckBox );
409 mButton =
new QToolButton(
this );
411 mButton->setToolTip( tr(
"Customize effects" ) );
412 layout->addWidget( mButton );
414 setFocusPolicy( Qt::StrongFocus );
415 setFocusProxy( mEnabledCheckBox );
417 connect( mButton, &QAbstractButton::clicked,
this, &QgsEffectStackCompactWidget::showDialog );
418 connect( mEnabledCheckBox, &QAbstractButton::toggled,
this, &QgsEffectStackCompactWidget::enableToggled );
429 mEnabledCheckBox->setChecked(
false );
430 mEnabledCheckBox->setEnabled(
false );
431 mButton->setEnabled(
false );
445 mEnabledCheckBox->setChecked( mStack->
enabled() );
446 mEnabledCheckBox->setEnabled(
true );
447 mButton->setEnabled( mStack->
enabled() );
457 mPreviewPicture = picture;
460 void QgsEffectStackCompactWidget::showDialog()
479 dlg.setPreviewPicture( mPreviewPicture );
481 if ( dlg.exec() == QDialog::Accepted )
489 void QgsEffectStackCompactWidget::enableToggled(
bool checked )
497 mButton->setEnabled( checked );
501 void QgsEffectStackCompactWidget::updateAcceptWidget(
QgsPanelWidget *panel )
504 *mStack = *widget->
stack();
509 void QgsEffectStackCompactWidget::updateEffectLive()
512 *mStack = *widget->
stack();