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();
141 for (
int i = 0; i < stack->
count(); ++i )
144 if ( stack->
effect( stack->
count() - i - 1 )->enabled() )
150 QModelIndex newIndex = mEffectsList->model()->index( initialRow, 0 );
151 mEffectsList->setCurrentIndex( newIndex );
175 EffectItem *parent =
static_cast<EffectItem *
>(
mModel->invisibleRootItem() );
177 int count = stack->
count();
178 for (
int i = count - 1; i >= 0; i-- )
180 EffectItem *effectItem =
new EffectItem( stack->
effect( i ), this );
181 effectItem->setEditable(
false );
182 parent->appendRow( effectItem );
195 QModelIndex currentIdx = mEffectsList->currentIndex();
196 if ( !currentIdx.isValid() )
199 EffectItem *item =
static_cast<EffectItem *
>(
mModel->itemFromIndex( currentIdx ) );
201 QStandardItem *root =
mModel->invisibleRootItem();
202 int rowCount = root->rowCount();
203 int currentRow = item ? item->row() : 0;
205 mUpButton->setEnabled( currentRow > 0 );
206 mDownButton->setEnabled( currentRow < rowCount - 1 );
207 mRemoveButton->setEnabled( rowCount > 1 );
213 QImage previewImage( 100, 100, QImage::Format_ARGB32 );
214 previewImage.fill( Qt::transparent );
215 painter.begin( &previewImage );
216 painter.setRenderHint( QPainter::Antialiasing );
221 QPainter previewPicPainter;
222 previewPicPainter.begin( &previewPic );
223 previewPicPainter.setPen( Qt::red );
224 previewPicPainter.setBrush( QColor( 255, 100, 100, 255 ) );
225 previewPicPainter.drawEllipse( QPoint( 50, 50 ), 20, 20 );
226 previewPicPainter.end();
231 context.
painter()->translate( 20, 20 );
236 lblPreview->setPixmap( QPixmap::fromImage( previewImage ) );
242 QModelIndex idx = mEffectsList->currentIndex();
243 if ( !idx.isValid() )
246 EffectItem *item =
static_cast<EffectItem *
>(
mModel->itemFromIndex( idx ) );
267 int index = stackedWidget->addWidget( widget );
268 stackedWidget->setCurrentIndex( index );
283 EffectItem *newEffectItem =
new EffectItem( newEffect,
this );
286 mEffectsList->setCurrentIndex(
mModel->indexFromItem( newEffectItem ) );
294 int row = item->row();
295 QStandardItem *root =
mModel->invisibleRootItem();
297 int layerIdx = root->rowCount() - row - 1;
300 mModel->invisibleRootItem()->removeRow( row );
302 int newSelection = std::min( row, root->rowCount() - 1 );
303 QModelIndex newIdx = root->child( newSelection )->index();
304 mEffectsList->setCurrentIndex( newIdx );
328 int row = item->row();
330 QStandardItem *root =
mModel->invisibleRootItem();
332 int layerIdx = root->rowCount() - row - 1;
337 QList<QStandardItem *> toMove = root->takeRow( row );
338 root->insertRows( row + offset, toMove );
340 QModelIndex newIdx = toMove[ 0 ]->index();
341 mEffectsList->setCurrentIndex( newIdx );
350 item->setEffect( newEffect );
352 QStandardItem *root =
mModel->invisibleRootItem();
353 int effectIdx = root->rowCount() - item->row() - 1;
367 :
QgsDialog( parent, f, QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok )
370 setWindowTitle( tr(
"Effect Properties" ) );
373 QDialogButtonBox *
buttonBox = this->findChild<QDialogButtonBox *>( QString(), Qt::FindDirectChildrenOnly );
374 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsEffectStackPropertiesDialog::showHelp );
389 void QgsEffectStackPropertiesDialog::showHelp()
391 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#draw-effects" ) );
403 QHBoxLayout *layout =
new QHBoxLayout();
404 layout->setContentsMargins( 0, 0, 0, 0 );
405 layout->setSpacing( 6 );
408 mEnabledCheckBox =
new QCheckBox(
this );
409 mEnabledCheckBox->setText( tr(
"Draw effects" ) );
410 layout->addWidget( mEnabledCheckBox );
412 mButton =
new QToolButton(
this );
414 mButton->setToolTip( tr(
"Customize effects" ) );
415 layout->addWidget( mButton );
417 setFocusPolicy( Qt::StrongFocus );
418 setFocusProxy( mEnabledCheckBox );
420 connect( mButton, &QAbstractButton::clicked,
this, &QgsEffectStackCompactWidget::showDialog );
421 connect( mEnabledCheckBox, &QAbstractButton::toggled,
this, &QgsEffectStackCompactWidget::enableToggled );
428 delete mPreviewPicture;
435 mEnabledCheckBox->setChecked(
false );
436 mEnabledCheckBox->setEnabled(
false );
437 mButton->setEnabled(
false );
451 mEnabledCheckBox->setChecked( mStack->
enabled() );
452 mEnabledCheckBox->setEnabled(
true );
453 mButton->setEnabled( mStack->
enabled() );
463 delete mPreviewPicture;
464 mPreviewPicture =
new QPicture( picture );
467 void QgsEffectStackCompactWidget::showDialog()
474 if ( mPreviewPicture )
489 if ( dlg.exec() == QDialog::Accepted )
497 void QgsEffectStackCompactWidget::enableToggled(
bool checked )
505 mButton->setEnabled( checked );
509 void QgsEffectStackCompactWidget::updateAcceptWidget(
QgsPanelWidget *panel )
512 *mStack = *widget->
stack();
517 void QgsEffectStackCompactWidget::updateEffectLive()
520 *mStack = *widget->
stack();
static const double UI_SCALE_FACTOR
UI scaling factor.
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.
A dialog for modifying the properties of a QgsEffectStack, including adding and reordering effects wi...
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. ...
QDialogButtonBox * buttonBox()
Returns the button box.
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.
QgsPaintEffect * effect(int index) const
Returns a pointer to the effect at a specified index within the stack.
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.
bool enabled() const
Returns whether the effect is enabled.
QgsEffectStackPropertiesDialog(QgsEffectStack *stack, QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
QgsEffectStackPropertiesDialog constructor.
QgsEffectStack * stack()
Returns effect stack attached to the dialog.
QgsPaintEffectAbstractMetadata * effectMetadata(const QString &name) const
Returns the metadata for a specific effect.
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.
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
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.
bool changeEffect(int index, QgsPaintEffect *effect)
Replaces the effect at a specified position within the stack.