17#include "moc_qgseffectstackpropertieswidget.cpp"
30#include <QStandardItemModel>
31#include <QStandardItem>
37static const int EFFECT_ITEM_TYPE = QStandardItem::UserType + 1;
39class EffectItem :
public QStandardItem
46 mWidget = propertiesWidget;
55 int type()
const override {
return EFFECT_ITEM_TYPE; }
62 QVariant data(
int role )
const override
64 if ( role == Qt::DisplayRole || role == Qt::EditRole )
68 if ( role == Qt::CheckStateRole )
70 return mEffect->enabled() ? Qt::Checked : Qt::Unchecked;
72 return QStandardItem::data( role );
75 void setData(
const QVariant &value,
int role )
override
77 if ( role == Qt::CheckStateRole )
79 mEffect->setEnabled( value.toBool() );
80 mWidget->updatePreview();
84 QStandardItem::setData( value, role );
112 this->layout()->setContentsMargins( 0, 0, 0, 0 );
114 mEffectsList->setMaximumHeight(
static_cast< int >(
Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 7 ) );
115 mEffectsList->setMinimumHeight( mEffectsList->maximumHeight() );
116 lblPreview->setMaximumWidth( mEffectsList->maximumHeight() );
123 mModel =
new QStandardItemModel();
125 mEffectsList->setModel(
mModel );
127 QItemSelectionModel *selModel = mEffectsList->selectionModel();
151 const QModelIndex newIndex = mEffectsList->model()->index( initialRow, 0 );
152 mEffectsList->setCurrentIndex( newIndex );
172 EffectItem *parent =
static_cast<EffectItem *
>(
mModel->invisibleRootItem() );
175 for (
int i = count - 1; i >= 0; i-- )
177 EffectItem *effectItem =
new EffectItem(
stack->
effect( i ),
this );
178 effectItem->setEditable(
false );
179 parent->appendRow( effectItem );
192 const QModelIndex currentIdx = mEffectsList->currentIndex();
193 if ( !currentIdx.isValid() )
196 EffectItem *item =
static_cast<EffectItem *
>(
mModel->itemFromIndex( currentIdx ) );
198 QStandardItem *root =
mModel->invisibleRootItem();
199 const int rowCount = root->rowCount();
200 const int currentRow = item ? item->row() : 0;
202 mUpButton->setEnabled( currentRow > 0 );
203 mDownButton->setEnabled( currentRow < rowCount - 1 );
204 mRemoveButton->setEnabled( rowCount > 1 );
210 QImage previewImage( 100, 100, QImage::Format_ARGB32 );
211 previewImage.fill( Qt::transparent );
212 painter.begin( &previewImage );
213 painter.setRenderHint( QPainter::Antialiasing );
219 QPainter previewPicPainter;
220 previewPicPainter.begin( &previewPic );
221 previewPicPainter.setPen( Qt::red );
222 previewPicPainter.setBrush( QColor( 255, 100, 100, 255 ) );
223 previewPicPainter.drawEllipse( QPoint( 50, 50 ), 20, 20 );
224 previewPicPainter.end();
229 context.
painter()->translate( 20, 20 );
234 lblPreview->setPixmap( QPixmap::fromImage( previewImage ) );
240 const QModelIndex idx = mEffectsList->currentIndex();
241 if ( !idx.isValid() )
244 EffectItem *item =
static_cast<EffectItem *
>(
mModel->itemFromIndex( idx ) );
265 const int index = stackedWidget->addWidget( widget );
266 stackedWidget->setCurrentIndex( index );
281 EffectItem *newEffectItem =
new EffectItem( newEffect,
this );
284 mEffectsList->setCurrentIndex(
mModel->indexFromItem( newEffectItem ) );
292 const int row = item->row();
293 QStandardItem *root =
mModel->invisibleRootItem();
295 const int layerIdx = root->rowCount() - row - 1;
298 mModel->invisibleRootItem()->removeRow( row );
300 const int newSelection = std::min( row, root->rowCount() - 1 );
301 const QModelIndex newIdx = root->child( newSelection )->index();
302 mEffectsList->setCurrentIndex( newIdx );
326 const int row = item->row();
328 QStandardItem *root =
mModel->invisibleRootItem();
330 const int layerIdx = root->rowCount() - row - 1;
335 QList<QStandardItem *> toMove = root->takeRow( row );
336 root->insertRows( row + offset, toMove );
338 const QModelIndex newIdx = toMove[ 0 ]->index();
339 mEffectsList->setCurrentIndex( newIdx );
348 item->setEffect( newEffect );
350 QStandardItem *root =
mModel->invisibleRootItem();
351 const int effectIdx = root->rowCount() - item->row() - 1;
365 :
QgsDialog( parent, f, QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok )
368 setWindowTitle( tr(
"Effect Properties" ) );
371 QDialogButtonBox *
buttonBox = this->findChild<QDialogButtonBox *>( QString(), Qt::FindDirectChildrenOnly );
372 connect(
buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsEffectStackPropertiesDialog::showHelp );
387void QgsEffectStackPropertiesDialog::showHelp()
389 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#draw-effects" ) );
401 QHBoxLayout *layout =
new QHBoxLayout();
402 layout->setContentsMargins( 0, 0, 0, 0 );
403 layout->setSpacing( 6 );
406 mEnabledCheckBox =
new QCheckBox(
this );
407 mEnabledCheckBox->setText( tr(
"Draw effects" ) );
408 layout->addWidget( mEnabledCheckBox );
410 mButton =
new QToolButton(
this );
412 mButton->setToolTip( tr(
"Customize effects" ) );
413 layout->addWidget( mButton );
415 setFocusPolicy( Qt::StrongFocus );
416 setFocusProxy( mEnabledCheckBox );
418 connect( mButton, &QAbstractButton::clicked,
this, &QgsEffectStackCompactWidget::showDialog );
419 connect( mEnabledCheckBox, &QAbstractButton::toggled,
this, &QgsEffectStackCompactWidget::enableToggled );
430 mEnabledCheckBox->setChecked(
false );
431 mEnabledCheckBox->setEnabled(
false );
432 mButton->setEnabled(
false );
446 mEnabledCheckBox->setChecked( mStack->
enabled() );
447 mEnabledCheckBox->setEnabled(
true );
448 mButton->setEnabled( mStack->
enabled() );
458 mPreviewPicture = picture;
461void QgsEffectStackCompactWidget::showDialog()
480 dlg.setPreviewPicture( mPreviewPicture );
482 if ( dlg.exec() == QDialog::Accepted )
490void QgsEffectStackCompactWidget::enableToggled(
bool checked )
498 mButton->setEnabled( checked );
502void QgsEffectStackCompactWidget::updateAcceptWidget(
QgsPanelWidget *panel )
505 *mStack = *widget->
stack();
510void QgsEffectStackCompactWidget::updateEffectLive()
513 *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.