29#include <QStandardItemModel>
30#include <QStandardItem>
36static const int EFFECT_ITEM_TYPE = QStandardItem::UserType + 1;
38class 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 );
386void 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;
460void QgsEffectStackCompactWidget::showDialog()
479 dlg.setPreviewPicture( mPreviewPicture );
481 if ( dlg.exec() == QDialog::Accepted )
489void QgsEffectStackCompactWidget::enableToggled(
bool checked )
497 mButton->setEnabled( checked );
501void QgsEffectStackCompactWidget::updateAcceptWidget(
QgsPanelWidget *panel )
504 *mStack = *widget->
stack();
509void QgsEffectStackCompactWidget::updateEffectLive()
512 *mStack = *widget->
stack();
@ RenderSymbolPreview
The render is for a symbol preview only and map based properties may not be available,...
static const double UI_SCALE_FACTOR
UI scaling factor.
static QgsPaintEffectRegistry * paintEffectRegistry()
Returns the application's paint effect registry, used for managing paint effects.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
A generic dialog with layout and button box.
QDialogButtonBox * buttonBox()
Returns the button box.
QVBoxLayout * layout()
Returns the central layout. Widgets added to it must have this dialog as parent.
A paint effect which draws the source picture with minor or no alterations.
A dialog for modifying the properties of a QgsEffectStack, including adding and reordering effects wi...
void setPreviewPicture(const QPicture &picture)
Sets the picture to use for effect previews for the dialog.
QgsEffectStackPropertiesWidget * mPropertiesWidget
QgsEffectStackPropertiesDialog(QgsEffectStack *stack, QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
QgsEffectStackPropertiesDialog constructor.
QgsEffectStack * stack()
Returns effect stack attached to the dialog.
A paint effect which consists of a stack of other chained paint effects.
int count() const
Returns count of effects contained by the stack.
QgsEffectStack * clone() const override
Duplicates an effect by creating a deep copy of the effect.
bool insertEffect(int index, QgsPaintEffect *effect)
Inserts an effect at a specified index within the stack.
QgsPaintEffect * takeEffect(int index)
Removes an effect from the stack and returns a pointer to it.
bool changeEffect(int index, QgsPaintEffect *effect)
Replaces the effect at a specified position within the stack.
QgsPaintEffect * effect(int index) const
Returns a pointer to the effect at a specified index within the stack.
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
QgsPaintEffectAbstractMetadata * effectMetadata(const QString &name) const
Returns the metadata for a specific effect.
Base class for visual effects which can be applied to QPicture drawings.
void setEnabled(bool enabled)
Sets whether the effect is enabled.
virtual void render(QPicture &picture, QgsRenderContext &context)
Renders a picture using the effect.
bool enabled() const
Returns whether the effect is enabled.
Contains information about the context of a rendering operation.
QPainter * painter()
Returns the destination QPainter for the render operation.
void setFlag(Qgis::RenderContextFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
static QgsRenderContext fromQPainter(QPainter *painter)
Creates a default render context given a pixel based QPainter destination.