28 #include <QStandardItemModel>    29 #include <QStandardItem>    31 #include <QToolButton>    35 static const int EFFECT_ITEM_TYPE = QStandardItem::UserType + 1;
    37 class EffectItem : 
public QStandardItem
    44       mWidget = propertiesWidget;
    53     int type()
 const override { 
return EFFECT_ITEM_TYPE; }
    60     QVariant data( 
int role )
 const override    62       if ( role == Qt::DisplayRole || role == Qt::EditRole )
    66       if ( role == Qt::CheckStateRole )
    68         return mEffect->enabled() ? Qt::Checked : Qt::Unchecked;
    70       return QStandardItem::data( role );
    73     void setData( 
const QVariant &value, 
int role )
 override    75       if ( role == Qt::CheckStateRole )
    77         mEffect->setEnabled( value.toBool() );
    78         mWidget->updatePreview();
    82         QStandardItem::setData( value, role );
   116   mModel = 
new QStandardItemModel();
   118   mEffectsList->setModel( 
mModel );
   120   QItemSelectionModel *selModel = mEffectsList->selectionModel();
   135   for ( 
int i = 0; i < stack->
count(); ++i )
   138     if ( stack->
effect( stack->
count() - i - 1 )->enabled() )
   144   QModelIndex newIndex = mEffectsList->model()->index( initialRow, 0 );
   145   mEffectsList->setCurrentIndex( newIndex );
   169   EffectItem *parent = 
static_cast<EffectItem *
>( 
mModel->invisibleRootItem() );
   171   int count = stack->
count();
   172   for ( 
int i = count - 1; i >= 0; i-- )
   174     EffectItem *effectItem = 
new EffectItem( stack->
effect( i ), this );
   175     effectItem->setEditable( 
false );
   176     parent->appendRow( effectItem );
   189   QModelIndex currentIdx = mEffectsList->currentIndex();
   190   if ( !currentIdx.isValid() )
   193   EffectItem *item = 
static_cast<EffectItem *
>( 
mModel->itemFromIndex( currentIdx ) );
   195   QStandardItem *root = 
mModel->invisibleRootItem();
   196   int rowCount = root->rowCount();
   197   int currentRow = item ? item->row() : 0;
   199   mUpButton->setEnabled( currentRow > 0 );
   200   mDownButton->setEnabled( currentRow < rowCount - 1 );
   201   mRemoveButton->setEnabled( rowCount > 1 );
   207   QImage previewImage( 150, 150, QImage::Format_ARGB32 );
   208   previewImage.fill( Qt::transparent );
   209   painter.begin( &previewImage );
   210   painter.setRenderHint( QPainter::Antialiasing );
   215     QPainter previewPicPainter;
   216     previewPicPainter.begin( &previewPic );
   217     previewPicPainter.setPen( Qt::red );
   218     previewPicPainter.setBrush( QColor( 255, 100, 100, 255 ) );
   219     previewPicPainter.drawEllipse( QPoint( 75, 75 ), 30, 30 );
   220     previewPicPainter.end();
   225     context.
painter()->translate( 35, 35 );
   230   lblPreview->setPixmap( QPixmap::fromImage( previewImage ) );
   236   QModelIndex idx = mEffectsList->currentIndex();
   237   if ( !idx.isValid() )
   240   EffectItem *item = 
static_cast<EffectItem *
>( 
mModel->itemFromIndex( idx ) );
   261   int index = stackedWidget->addWidget( widget );
   262   stackedWidget->setCurrentIndex( index );
   277   EffectItem *newEffectItem = 
new EffectItem( newEffect, 
this );
   280   mEffectsList->setCurrentIndex( 
mModel->indexFromItem( newEffectItem ) );
   288   int row = item->row();
   289   QStandardItem *root = 
mModel->invisibleRootItem();
   291   int layerIdx = root->rowCount() - row - 1;
   294   mModel->invisibleRootItem()->removeRow( row );
   296   int newSelection = std::min( row, root->rowCount() - 1 );
   297   QModelIndex newIdx = root->child( newSelection )->index();
   298   mEffectsList->setCurrentIndex( newIdx );
   322   int row = item->row();
   324   QStandardItem *root = 
mModel->invisibleRootItem();
   326   int layerIdx = root->rowCount() - row - 1;
   331   QList<QStandardItem *> toMove = root->takeRow( row );
   332   root->insertRows( row + offset, toMove );
   334   QModelIndex newIdx = toMove[ 0 ]->index();
   335   mEffectsList->setCurrentIndex( newIdx );
   344   item->setEffect( newEffect );
   346   QStandardItem *root = 
mModel->invisibleRootItem();
   347   int effectIdx = root->rowCount() - item->row() - 1;
   361   : 
QgsDialog( parent, f, QDialogButtonBox::Ok | QDialogButtonBox::Cancel )
   364   setWindowTitle( tr( 
"Effect Properties" ) );
   387   QHBoxLayout *layout = 
new QHBoxLayout();
   388   layout->setContentsMargins( 0, 0, 0, 0 );
   389   layout->setSpacing( 6 );
   392   mEnabledCheckBox = 
new QCheckBox( 
this );
   393   mEnabledCheckBox->setText( tr( 
"Draw effects" ) );
   394   layout->addWidget( mEnabledCheckBox );
   396   mButton = 
new QToolButton( 
this );
   398   mButton->setToolTip( tr( 
"Customize effects" ) );
   399   layout->addWidget( mButton );
   401   setFocusPolicy( Qt::StrongFocus );
   402   setFocusProxy( mEnabledCheckBox );
   404   connect( mButton, &QAbstractButton::clicked, 
this, &QgsEffectStackCompactWidget::showDialog );
   405   connect( mEnabledCheckBox, &QAbstractButton::toggled, 
this, &QgsEffectStackCompactWidget::enableToggled );
   412   delete mPreviewPicture;
   419     mEnabledCheckBox->setChecked( 
false );
   420     mEnabledCheckBox->setEnabled( 
false );
   421     mButton->setEnabled( 
false );
   435   mEnabledCheckBox->setChecked( mStack->
enabled() );
   436   mEnabledCheckBox->setEnabled( 
true );
   437   mButton->setEnabled( mStack->
enabled() );
   447   delete mPreviewPicture;
   448   mPreviewPicture = 
new QPicture( picture );
   451 void QgsEffectStackCompactWidget::showDialog()
   458   if ( mPreviewPicture )
   476 void QgsEffectStackCompactWidget::enableToggled( 
bool checked )
   484   mButton->setEnabled( checked );
   488 void QgsEffectStackCompactWidget::updateAcceptWidget( 
QgsPanelWidget *panel )
   491   *mStack = *widget->
stack();
   496 void QgsEffectStackCompactWidget::updateEffectLive()
   499   *mStack = *widget->
stack();
 
bool insertEffect(int index, QgsPaintEffect *effect)
Inserts an effect at a specified index within the stack. 
 
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file. 
 
bool enabled() const 
Returns whether the effect is enabled. 
 
Base class for visual effects which can be applied to QPicture drawings. 
 
A generic dialog with layout and button box. 
 
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon. 
 
static QgsPaintEffectRegistry * paintEffectRegistry()
Returns the application's paint effect registry, used for managing paint effects. ...
 
void setEnabled(bool enabled)
Sets whether the effect is enabled. 
 
int count() const 
Returns count of effects contained by the stack. 
 
void setPreviewPicture(const QPicture &picture)
Sets the picture to use for effect previews for the dialog. 
 
static QgsRenderContext fromQPainter(QPainter *painter)
Creates a default render context given a pixel based QPainter destination. 
 
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. 
 
QgsPaintEffectAbstractMetadata * effectMetadata(const QString &name) const 
Returns the metadata for a specific effect. 
 
QgsEffectStackPropertiesDialog(QgsEffectStack *stack, QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
QgsEffectStackPropertiesDialog constructor. 
 
QgsEffectStack * stack()
Returns effect stack attached to the dialog. 
 
Contains information about the context of a rendering operation. 
 
QPainter * painter()
Returns the destination QPainter for the render operation. 
 
QVBoxLayout * layout()
Returns the central layout. Widgets added to it must have this dialog as parent. 
 
QgsEffectStackPropertiesWidget * mPropertiesWidget
 
virtual void render(QPicture &picture, QgsRenderContext &context)
Renders a picture using the effect. 
 
QgsPaintEffect * takeEffect(int index)
Removes an effect from the stack and returns a pointer to it. 
 
A paint effect which draws the source picture with minor or no alterations. 
 
QgsPaintEffect * effect(int index) const 
Returns a pointer to the effect at a specified index within the stack. 
 
bool changeEffect(int index, QgsPaintEffect *effect)
Replaces the effect at a specified position within the stack.