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();
150 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 QModelIndex currentIdx = mEffectsList->currentIndex();
192 if ( !currentIdx.isValid() )
195 EffectItem *item =
static_cast<EffectItem *
>(
mModel->itemFromIndex( currentIdx ) );
197 QStandardItem *root =
mModel->invisibleRootItem();
198 int rowCount = root->rowCount();
199 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 );
217 QPainter previewPicPainter;
218 previewPicPainter.begin( &previewPic );
219 previewPicPainter.setPen( Qt::red );
220 previewPicPainter.setBrush( QColor( 255, 100, 100, 255 ) );
221 previewPicPainter.drawEllipse( QPoint( 50, 50 ), 20, 20 );
222 previewPicPainter.end();
227 context.
painter()->translate( 20, 20 );
232 lblPreview->setPixmap( QPixmap::fromImage( previewImage ) );
238 QModelIndex idx = mEffectsList->currentIndex();
239 if ( !idx.isValid() )
242 EffectItem *item =
static_cast<EffectItem *
>(
mModel->itemFromIndex( idx ) );
263 int index = stackedWidget->addWidget( widget );
264 stackedWidget->setCurrentIndex( index );
279 EffectItem *newEffectItem =
new EffectItem( newEffect,
this );
282 mEffectsList->setCurrentIndex(
mModel->indexFromItem( newEffectItem ) );
290 int row = item->row();
291 QStandardItem *root =
mModel->invisibleRootItem();
293 int layerIdx = root->rowCount() - row - 1;
296 mModel->invisibleRootItem()->removeRow( row );
298 int newSelection = std::min( row, root->rowCount() - 1 );
299 QModelIndex newIdx = root->child( newSelection )->index();
300 mEffectsList->setCurrentIndex( newIdx );
324 int row = item->row();
326 QStandardItem *root =
mModel->invisibleRootItem();
328 int layerIdx = root->rowCount() - row - 1;
333 QList<QStandardItem *> toMove = root->takeRow( row );
334 root->insertRows( row + offset, toMove );
336 QModelIndex newIdx = toMove[ 0 ]->index();
337 mEffectsList->setCurrentIndex( newIdx );
346 item->setEffect( newEffect );
348 QStandardItem *root =
mModel->invisibleRootItem();
349 int effectIdx = root->rowCount() - item->row() - 1;
363 :
QgsDialog( parent, f, QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok )
366 setWindowTitle( tr(
"Effect Properties" ) );
369 QDialogButtonBox *
buttonBox = this->findChild<QDialogButtonBox *>( QString(), Qt::FindDirectChildrenOnly );
370 connect(
buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsEffectStackPropertiesDialog::showHelp );
385 void QgsEffectStackPropertiesDialog::showHelp()
387 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#draw-effects" ) );
399 QHBoxLayout *layout =
new QHBoxLayout();
400 layout->setContentsMargins( 0, 0, 0, 0 );
401 layout->setSpacing( 6 );
404 mEnabledCheckBox =
new QCheckBox(
this );
405 mEnabledCheckBox->setText( tr(
"Draw effects" ) );
406 layout->addWidget( mEnabledCheckBox );
408 mButton =
new QToolButton(
this );
410 mButton->setToolTip( tr(
"Customize effects" ) );
411 layout->addWidget( mButton );
413 setFocusPolicy( Qt::StrongFocus );
414 setFocusProxy( mEnabledCheckBox );
416 connect( mButton, &QAbstractButton::clicked,
this, &QgsEffectStackCompactWidget::showDialog );
417 connect( mEnabledCheckBox, &QAbstractButton::toggled,
this, &QgsEffectStackCompactWidget::enableToggled );
428 mEnabledCheckBox->setChecked(
false );
429 mEnabledCheckBox->setEnabled(
false );
430 mButton->setEnabled(
false );
444 mEnabledCheckBox->setChecked( mStack->
enabled() );
445 mEnabledCheckBox->setEnabled(
true );
446 mButton->setEnabled( mStack->
enabled() );
456 mPreviewPicture = picture;
459 void QgsEffectStackCompactWidget::showDialog()
478 dlg.setPreviewPicture( mPreviewPicture );
480 if ( dlg.exec() == QDialog::Accepted )
488 void QgsEffectStackCompactWidget::enableToggled(
bool checked )
496 mButton->setEnabled( checked );
500 void QgsEffectStackCompactWidget::updateAcceptWidget(
QgsPanelWidget *panel )
503 *mStack = *widget->
stack();
508 void QgsEffectStackCompactWidget::updateEffectLive()
511 *mStack = *widget->
stack();
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 QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
A generic dialog with layout and button box.
QVBoxLayout * layout()
Returns the central layout. Widgets added to it must have this dialog as parent.
QDialogButtonBox * buttonBox()
Returns the button box.
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.
static QgsRenderContext fromQPainter(QPainter *painter)
Creates a default render context given a pixel based QPainter destination.