31#include <QStandardItem>
32#include <QStandardItemModel>
35#include "moc_qgseffectstackpropertieswidget.cpp"
39static const int EFFECT_ITEM_TYPE = QStandardItem::UserType + 1;
41class EffectItem :
public QStandardItem
44 EffectItem( QgsPaintEffect *effect, QgsEffectStackPropertiesWidget *propertiesWidget )
48 mWidget = propertiesWidget;
51 void setEffect( QgsPaintEffect *effect )
57 int type()
const override {
return EFFECT_ITEM_TYPE; }
59 QgsPaintEffect *effect()
64 QVariant data(
int role )
const override
66 if ( role == Qt::DisplayRole || role == Qt::EditRole )
70 if ( role == Qt::CheckStateRole )
72 return mEffect->enabled() ? Qt::Checked : Qt::Unchecked;
74 return QStandardItem::data( role );
77 void setData(
const QVariant &value,
int role )
override
79 if ( role == Qt::CheckStateRole )
81 mEffect->setEnabled( value.toBool() );
82 mWidget->updatePreview();
86 QStandardItem::setData( value, role );
91 QgsPaintEffect *mEffect =
nullptr;
92 QgsEffectStackPropertiesWidget *mWidget =
nullptr;
113 this->layout()->setContentsMargins( 0, 0, 0, 0 );
115 mEffectsList->setMaximumHeight(
static_cast<int>(
Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 7 ) );
116 mEffectsList->setMinimumHeight( mEffectsList->maximumHeight() );
117 lblPreview->setMaximumWidth( mEffectsList->maximumHeight() );
124 mModel =
new QStandardItemModel();
126 mEffectsList->setModel(
mModel );
128 QItemSelectionModel *selModel = mEffectsList->selectionModel();
143 for (
int i = 0; i <
stack->count(); ++i )
146 if (
stack->effect(
stack->count() - i - 1 )->enabled() )
152 const QModelIndex newIndex = mEffectsList->model()->index( initialRow, 0 );
153 mEffectsList->setCurrentIndex( newIndex );
173 EffectItem *parent =
static_cast<EffectItem *
>(
mModel->invisibleRootItem() );
175 const int count =
stack->count();
176 for (
int i = count - 1; i >= 0; i-- )
178 EffectItem *effectItem =
new EffectItem(
stack->effect( i ),
this );
179 effectItem->setEditable(
false );
180 parent->appendRow( effectItem );
193 const QModelIndex currentIdx = mEffectsList->currentIndex();
194 if ( !currentIdx.isValid() )
197 EffectItem *item =
static_cast<EffectItem *
>(
mModel->itemFromIndex( currentIdx ) );
199 QStandardItem *root =
mModel->invisibleRootItem();
200 const int rowCount = root->rowCount();
201 const int currentRow = item ? item->row() : 0;
203 mUpButton->setEnabled( currentRow > 0 );
204 mDownButton->setEnabled( currentRow < rowCount - 1 );
205 mRemoveButton->setEnabled( rowCount > 1 );
211 QImage previewImage( 100, 100, QImage::Format_ARGB32 );
212 previewImage.fill( Qt::transparent );
213 painter.begin( &previewImage );
214 painter.setRenderHint( QPainter::Antialiasing );
220 QPainter previewPicPainter;
221 previewPicPainter.begin( &previewPic );
222 previewPicPainter.setPen( Qt::red );
223 previewPicPainter.setBrush( QColor( 255, 100, 100, 255 ) );
224 previewPicPainter.drawEllipse( QPoint( 50, 50 ), 20, 20 );
225 previewPicPainter.end();
226 mStack->render( previewPic, context );
230 context.
painter()->translate( 20, 20 );
235 lblPreview->setPixmap( QPixmap::fromImage( previewImage ) );
241 const QModelIndex idx = mEffectsList->currentIndex();
242 if ( !idx.isValid() )
245 EffectItem *item =
static_cast<EffectItem *
>(
mModel->itemFromIndex( idx ) );
266 const int index = stackedWidget->addWidget( widget );
267 stackedWidget->setCurrentIndex( index );
280 mStack->insertEffect( 0, newEffect );
282 EffectItem *newEffectItem =
new EffectItem( newEffect,
this );
283 mModel->invisibleRootItem()->insertRow(
mStack->count() - 1, newEffectItem );
285 mEffectsList->setCurrentIndex(
mModel->indexFromItem( newEffectItem ) );
293 const int row = item->row();
294 QStandardItem *root =
mModel->invisibleRootItem();
296 const int layerIdx = root->rowCount() - row - 1;
299 mModel->invisibleRootItem()->removeRow( row );
301 const int newSelection = std::min( row, root->rowCount() - 1 );
302 const QModelIndex newIdx = root->child( newSelection )->index();
303 mEffectsList->setCurrentIndex( newIdx );
327 const int row = item->row();
329 QStandardItem *root =
mModel->invisibleRootItem();
331 const int layerIdx = root->rowCount() - row - 1;
334 mStack->insertEffect( layerIdx - offset, tmpEffect );
336 QList<QStandardItem *> toMove = root->takeRow( row );
337 root->insertRows( row + offset, toMove );
339 const QModelIndex newIdx = toMove[0]->index();
340 mEffectsList->setCurrentIndex( newIdx );
349 item->setEffect( newEffect );
351 QStandardItem *root =
mModel->invisibleRootItem();
352 const int effectIdx = root->rowCount() - item->row() - 1;
353 mStack->changeEffect( effectIdx, newEffect );
366 :
QgsDialog( parent, f, QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok )
369 setWindowTitle( tr(
"Effect Properties" ) );
372 QDialogButtonBox *
buttonBox = this->findChild<QDialogButtonBox *>( QString(), Qt::FindDirectChildrenOnly );
373 connect(
buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsEffectStackPropertiesDialog::showHelp );
388void QgsEffectStackPropertiesDialog::showHelp()
390 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#draw-effects" ) );
402 QHBoxLayout *layout =
new QHBoxLayout();
403 layout->setContentsMargins( 0, 0, 0, 0 );
404 layout->setSpacing( 6 );
407 mEnabledCheckBox =
new QCheckBox(
this );
408 mEnabledCheckBox->setText( tr(
"Draw effects" ) );
409 layout->addWidget( mEnabledCheckBox );
411 mButton =
new QToolButton(
this );
413 mButton->setToolTip( tr(
"Customize effects" ) );
414 layout->addWidget( mButton );
416 setFocusPolicy( Qt::StrongFocus );
417 setFocusProxy( mEnabledCheckBox );
419 connect( mButton, &QAbstractButton::clicked,
this, &QgsEffectStackCompactWidget::showDialog );
420 connect( mEnabledCheckBox, &QAbstractButton::toggled,
this, &QgsEffectStackCompactWidget::enableToggled );
431 mEnabledCheckBox->setChecked(
false );
432 mEnabledCheckBox->setEnabled(
false );
433 mButton->setEnabled(
false );
447 mEnabledCheckBox->setChecked( mStack->enabled() );
449 mButton->setEnabled( mStack->enabled() );
459 mPreviewPicture = picture;
462void QgsEffectStackCompactWidget::showDialog()
480 QgsEffectStackPropertiesDialog dlg( clone,
this );
481 dlg.setPreviewPicture( mPreviewPicture );
483 if ( dlg.exec() == QDialog::Accepted )
491void QgsEffectStackCompactWidget::enableToggled(
bool checked )
498 mStack->setEnabled( checked );
499 mButton->setEnabled( checked );
503void QgsEffectStackCompactWidget::updateAcceptWidget(
QgsPanelWidget *panel )
505 QgsEffectStackPropertiesWidget *widget = qobject_cast<QgsEffectStackPropertiesWidget *>( panel );
506 *mStack = *widget->
stack();
511void QgsEffectStackCompactWidget::updateEffectLive()
513 QgsEffectStackPropertiesWidget *widget = qobject_cast<QgsEffectStackPropertiesWidget *>( sender() );
514 *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.
QDialogButtonBox * buttonBox()
Returns the button box.
QgsDialog(QWidget *parent=nullptr, Qt::WindowFlags fl=QgsGuiUtils::ModalDialogFlags, QDialogButtonBox::StandardButtons buttons=QDialogButtonBox::Close, Qt::Orientation orientation=Qt::Horizontal)
Constructor for QgsDialog.
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.
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.
QgsEffectStack * clone() const override
Duplicates an effect by creating a deep copy of the effect.
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.
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.