35 #include <QColorDialog> 37 #include <QStandardItemModel> 38 #include <QInputDialog> 39 #include <QMessageBox> 45 #include <QStandardItem> 49 static const int SymbolLayerItemType = QStandardItem::UserType + 1;
53 , mMarkerSymbolLayer( nullptr )
55 , mLineSymbolLayer( nullptr )
62 mDDSize = mMarker->dataDefinedSize();
63 mDDAngle = mMarker->dataDefinedAngle();
72 mDDWidth = mLine->dataDefinedWidth();
80 void DataDefinedRestorer::save()
84 mSize = mMarkerSymbolLayer->size();
85 mAngle = mMarkerSymbolLayer->angle();
86 mMarkerOffset = mMarkerSymbolLayer->offset();
90 mWidth = mLineSymbolLayer->width();
91 mLineOffset = mLineSymbolLayer->offset();
95 void DataDefinedRestorer::restore()
100 ( mSize != mMarkerSymbolLayer->size() || mMarkerOffset != mMarkerSymbolLayer->offset() ) )
101 mMarker->setDataDefinedSize( mDDSize );
103 mAngle != mMarkerSymbolLayer->angle() )
104 mMarker->setDataDefinedAngle( mDDAngle );
109 ( mWidth != mLineSymbolLayer->width() || mLineOffset != mLineSymbolLayer->offset() ) )
110 mLine->setDataDefinedWidth( mDDWidth );
156 static_cast<SymbolLayerItem*
>(
parent() )->updatePreview();
159 int type()
const override {
return SymbolLayerItemType; }
160 bool isLayer() {
return mIsLayer; }
173 QVariant data(
int role )
const override 175 if ( role == Qt::DisplayRole || role == Qt::EditRole )
196 if ( role == Qt::CheckStateRole )
234 btnLock->setIcon( iconLock );
241 layersTree->setModel(
model );
242 layersTree->setHeaderHidden(
true );
262 layersTree->setCurrentIndex( newIndex );
284 mPresetExpressionContext.
reset( context );
293 QWidget* widget = stackedWidget->currentWidget();
311 SymbolLayerItem* symbolItem =
new SymbolLayerItem( symbol );
312 QFont boldFont = symbolItem->font();
314 symbolItem->setFont( boldFont );
315 parent->appendRow( symbolItem );
318 for (
int i = count - 1; i >= 0; i-- )
320 SymbolLayerItem *layerItem =
new SymbolLayerItem( symbol->
symbolLayer( i ) );
321 layerItem->setEditable(
false );
322 symbolItem->appendRow( layerItem );
327 layersTree->setExpanded( layerItem->index(), true );
329 layersTree->setExpanded( symbolItem->index(), true );
341 QModelIndex currentIdx = layersTree->currentIndex();
345 SymbolLayerItem *item =
static_cast<SymbolLayerItem*
>(
model->
itemFromIndex( currentIdx ) );
346 if ( !item->isLayer() )
348 btnUp->setEnabled(
false );
349 btnDown->setEnabled(
false );
350 btnRemoveLayer->setEnabled(
false );
351 btnLock->setEnabled(
false );
352 btnDuplicate->setEnabled(
false );
356 int rowCount = item->parent()->rowCount();
357 int currentRow = item->row();
359 btnUp->setEnabled( currentRow > 0 );
360 btnDown->setEnabled( currentRow < rowCount - 1 );
361 btnRemoveLayer->setEnabled( rowCount > 1 );
362 btnLock->setEnabled(
true );
363 btnDuplicate->setEnabled(
true );
379 item->updatePreview();
391 if ( !item->isLayer() )
404 if ( item->isLayer() )
405 return item->layer();
414 SymbolLayerItem *currentItem =
static_cast<SymbolLayerItem*
>(
model->
itemFromIndex( layersTree->currentIndex() ) );
418 if ( currentItem->isLayer() )
420 SymbolLayerItem *
parent =
static_cast<SymbolLayerItem*
>( currentItem->parent() );
421 mDataDefineRestorer.
reset(
new DataDefinedRestorer( parent->symbol(), currentItem->layer() ) );
427 connect( layerProp, SIGNAL( changed() ), mDataDefineRestorer.
data(), SLOT( restore() ) );
436 mDataDefineRestorer.
reset();
452 SymbolLayerItem *currentItem =
static_cast<SymbolLayerItem*
>(
model->
itemFromIndex( layersTree->currentIndex() ) );
453 if ( !currentItem || currentItem->isLayer() )
457 if ( currentItem->parent() )
461 SymbolLayerItem *
parent =
static_cast<SymbolLayerItem*
>( currentItem->parent() );
462 parent->removeRow( 0 );
464 layersTree->setCurrentIndex( parent->child( 0 )->index() );
465 parent->updatePreview();
472 layersTree->setCurrentIndex( newIndex );
481 int index = stackedWidget->addWidget( widget );
482 stackedWidget->setCurrentIndex( index );
493 btnLock->setChecked( layer->
isLocked() );
504 if ( item->isLayer() )
506 insertIdx = item->row();
507 item =
static_cast<SymbolLayerItem*
>( item->parent() );
524 if ( insertIdx == -1 )
531 static_cast<QgsMarkerSymbolV2 *>( parentSymbol )->setDataDefinedSize( ddSize );
533 static_cast<QgsMarkerSymbolV2 *
>( parentSymbol )->setDataDefinedAngle( ddAngle );
535 static_cast<QgsLineSymbolV2 *>( parentSymbol )->setDataDefinedWidth( ddWidth );
537 SymbolLayerItem *newLayerItem =
new SymbolLayerItem( newLayer );
538 item->insertRow( insertIdx == -1 ? 0 : insertIdx, newLayerItem );
539 item->updatePreview();
549 int row = item->row();
550 SymbolLayerItem *
parent =
static_cast<SymbolLayerItem*
>( item->parent() );
552 int layerIdx = parent->rowCount() - row - 1;
556 parent->removeRow( row );
557 parent->updatePreview();
560 layersTree->setCurrentIndex( newIdx );
583 int row = item->row();
585 SymbolLayerItem *
parent =
static_cast<SymbolLayerItem*
>( item->parent() );
588 int layerIdx = parent->rowCount() - row - 1;
594 parent->insertRows( row + offset, rowItems );
595 parent->updatePreview();
598 layersTree->setCurrentIndex( newIdx );
609 layer->
setLocked( btnLock->isChecked() );
620 if ( !item->isLayer() )
625 int insertIdx = item->row();
626 item =
static_cast<SymbolLayerItem*
>( item->parent() );
631 if ( insertIdx == -1 )
636 SymbolLayerItem *newLayerItem =
new SymbolLayerItem( newLayer );
637 item->insertRow( insertIdx == -1 ? 0 : insertIdx, newLayerItem );
641 layersTree->setExpanded( newLayerItem->index(), true );
643 item->updatePreview();
654 tr(
"Please enter name for the symbol:" ), QLineEdit::Normal,
tr(
"New symbol" ), &ok );
662 tr(
"Symbol with name '%1' already exists. Overwrite?" )
664 QMessageBox::Yes | QMessageBox::No );
665 if ( res != QMessageBox::Yes )
685 item->removeRow( 0 );
688 item->setLayer( newLayer );
693 layersTree->setExpanded( item->index(), true );
698 int layerIdx = item->parent()->rowCount() - item->row() - 1;
701 item->updatePreview();
712 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
760 return mSelectorWidget->
symbol();
783 mSelectorWidget->
loadSymbol( symbol, parent );
void setLocked(bool locked)
QByteArray toByteArray() const
void setExpressionContext(QgsExpressionContext *context)
Sets the optional expression context used for the widget.
void setContentsMargins(int left, int top, int right, int bottom)
static QgsSymbolLayerV2 * defaultSymbolLayer(QgsSymbolV2::SymbolType type)
create a new instance of symbol layer for specified symbol type with default settings ...
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const=0
~QgsSymbolV2SelectorDialog()
virtual QgsSymbolLayerV2 * clone() const =0
Shall be reimplemented by subclasses to create a deep copy of the instance.
A container class for data source field mapping or expression.
static QIcon symbolLayerPreviewIcon(QgsSymbolLayerV2 *layer, QgsSymbolV2::OutputUnit u, QSize size, const QgsMapUnitScale &scale=QgsMapUnitScale())
QgsSymbolLayerV2AbstractMetadata * symbolLayerMetadata(const QString &name) const
return metadata for specified symbol layer. Returns NULL if not found
QStandardItem * invisibleRootItem() const
bool addSymbol(const QString &name, QgsSymbolV2 *symbol, bool update=false)
add symbol to style. takes symbol's ownership
virtual QgsSymbolV2 * clone() const =0
void symbolChanged()
Slot to update tree when a new symbol from style.
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
#define Q_NOWARN_DEPRECATED_PUSH
bool contains(const QString &str, Qt::CaseSensitivity cs) const
bool changeSymbolLayer(int index, QgsSymbolLayerV2 *layer)
delete layer at specified index and set a new one
QPixmap fromImage(const QImage &image, QFlags< Qt::ImageConversionFlag > flags)
static QgsSymbolLayerV2Registry * instance()
return the single instance of this class (instantiate it if not exists)
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QString tr(const char *sourceText, const char *disambiguation, int n)
Map canvas is a class for displaying all GIS data types on a canvas.
void setBold(bool enable)
void setValue(const QString &key, const QVariant &value)
const char * name() const
The output shall be in millimeters.
static QIcon symbolPreviewIcon(QgsSymbolV2 *symbol, QSize size)
void setWidget(QWidget *widget)
bool appendSymbolLayer(QgsSymbolLayerV2 *layer)
Append symbol layer at the end of the list Ownership will be transferred.
bool saveSymbol(const QString &name, QgsSymbolV2 *symbol, int groupid, const QStringList &tags)
add the symbol to the DB with the tags
QModelIndex indexFromItem(const QStandardItem *item) const
QMenu * advancedMenu()
return menu for "advanced" button - create it if doesn't exist and show the advanced button ...
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsExpressionContext * expressionContext() const
Returns the expression context used for the dialog, if set.
int symbolLayerCount()
Returns total number of symbol layers contained in the symbol.
bool isLayer(QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
QStringList symbolNames()
return a list of names of symbols
QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode, const QString &text, bool *ok, QFlags< Qt::WindowType > flags, QFlags< Qt::InputMethodHint > inputMethodHints)
SymbolLayerItem * currentLayerItem()
QgsSymbolLayerV2 * currentLayer()
QImage bigSymbolPreviewImage(QgsExpressionContext *expressionContext=nullptr)
Returns a large (roughly 100x100 pixel) preview image for the symbol.
virtual QgsSymbolV2 * subSymbol()
void addFile(const QString &fileName, const QSize &size, Mode mode, State state)
#define Q_NOWARN_DEPRECATED_POP
virtual void keyPressEvent(QKeyEvent *e)
QVariant value(const QString &key, const QVariant &defaultValue) const
const QAbstractItemModel * model() const
void duplicateLayer()
Duplicates the current symbol layer and places the duplicated layer above the current symbol layer...
bool insertSymbolLayer(int index, QgsSymbolLayerV2 *layer)
Insert symbol layer to specified index Ownership will be transferred.
QStandardItem * itemFromIndex(const QModelIndex &index) const
QgsSymbolV2SelectorDialog(QgsSymbolV2 *symbol, QgsStyleV2 *style, const QgsVectorLayer *vl, QWidget *parent=nullptr, bool embedded=false)
void moveLayerByOffset(int offset)
QString translate(const char *context, const char *sourceText, const char *disambiguation, Encoding encoding)
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the dialog.
void changeLayer(QgsSymbolLayerV2 *layer)
alters tree and sets proper widget when Layer Type is changed
StandardButton warning(QWidget *parent, const QString &title, const QString &text, QFlags< QMessageBox::StandardButton > buttons, StandardButton defaultButton)
void keyPressEvent(QKeyEvent *e) override
Reimplements dialog keyPress event so we can ignore it.
Abstract base class for marker symbol layers.
QgsSymbolLayerV2 * takeSymbolLayer(int index)
Remove symbol layer from the list and return pointer to it.
QgsSymbolLayerV2 * symbolLayer(int layer)
Returns a specific symbol layers contained in the symbol.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Represents a vector layer which manages a vector based data sets.
QgsSymbolV2::SymbolType type() const
void updateLayerPreview()
virtual QVariant data(int role) const
QgsSymbolV2 * symbol()
Return the symbol that is currently active in the widget.
Q_DECL_DEPRECATED void saveSymbol()