34 #include <QColorDialog>
36 #include <QStandardItemModel>
37 #include <QInputDialog>
38 #include <QMessageBox>
44 #include <QStandardItem>
110 QVariant
data(
int role )
const override
112 if ( role == Qt::DisplayRole || role == Qt::EditRole )
123 default:
return "Symbol";
127 if ( role == Qt::SizeHintRole )
128 return QVariant( QSize( 32, 32 ) );
129 if ( role == Qt::CheckStateRole )
143 : QDialog( parent ), mAdvancedMenu( NULL ), mVectorLayer( vl )
146 setWindowModality( Qt::WindowModal );
157 layout()->setContentsMargins( 0, 0, 0, 0 );
165 btnLock->setIcon( iconLock );
169 model =
new QStandardItemModel();
171 layersTree->setModel(
model );
172 layersTree->setHeaderHidden(
true );
174 QItemSelectionModel* selModel = layersTree->selectionModel();
175 connect( selModel, SIGNAL( currentChanged(
const QModelIndex&,
const QModelIndex& ) ),
this, SLOT(
layerChanged() ) );
177 loadSymbol( symbol, static_cast<SymbolLayerItem*>(
model->invisibleRootItem() ) );
180 connect( btnUp, SIGNAL( clicked() ),
this, SLOT(
moveLayerUp() ) );
181 connect( btnDown, SIGNAL( clicked() ),
this, SLOT(
moveLayerDown() ) );
182 connect( btnAddLayer, SIGNAL( clicked() ),
this, SLOT(
addLayer() ) );
183 connect( btnRemoveLayer, SIGNAL( clicked() ),
this, SLOT(
removeLayer() ) );
184 connect( btnLock, SIGNAL( clicked() ),
this, SLOT(
lockLayer() ) );
185 connect( btnSaveSymbol, SIGNAL( clicked() ),
this, SLOT(
saveSymbol() ) );
190 QModelIndex newIndex = layersTree->model()->index( 0, 0 );
191 layersTree->setCurrentIndex( newIndex );
197 if ( !isWindow() && e->key() == Qt::Key_Escape )
221 QFont boldFont = symbolItem->font();
222 boldFont.setBold(
true );
223 symbolItem->setFont( boldFont );
224 parent->appendRow( symbolItem );
227 for (
int i = count - 1; i >= 0; i-- )
230 layerItem->setEditable(
false );
231 symbolItem->appendRow( layerItem );
237 layersTree->setExpanded( symbolItem->index(), true );
249 QModelIndex currentIdx = layersTree->currentIndex();
250 if ( !currentIdx.isValid() )
256 btnUp->setEnabled(
false );
257 btnDown->setEnabled(
false );
258 btnRemoveLayer->setEnabled(
false );
259 btnLock->setEnabled(
false );
263 int rowCount = item->parent()->rowCount();
264 int currentRow = item->row();
266 btnUp->setEnabled( currentRow > 0 );
267 btnDown->setEnabled( currentRow < rowCount - 1 );
268 btnRemoveLayer->setEnabled( rowCount > 1 );
269 btnLock->setEnabled(
true );
275 lblPreview->setPixmap( QPixmap::fromImage( preview ) );
292 QModelIndex idx = layersTree->currentIndex();
293 if ( !idx.isValid() )
305 QModelIndex idx = layersTree->currentIndex();
306 if ( !idx.isValid() )
311 return item->
layer();
321 if ( currentItem == NULL )
339 connect( symbolsList, SIGNAL( changed() ),
this, SLOT(
symbolChanged() ) );
347 if ( currentItem == NULL || currentItem->
isLayer() )
350 disconnect( layersTree->selectionModel(), SIGNAL( currentChanged(
const QModelIndex&,
const QModelIndex& ) ),
this, SLOT(
layerChanged() ) );
351 if ( currentItem->parent() )
356 parent->removeRow( 0 );
358 layersTree->setCurrentIndex( parent->child( 0 )->index() );
365 QModelIndex newIndex = layersTree->model()->index( 0, 0 );
366 layersTree->setCurrentIndex( newIndex );
370 connect( layersTree->selectionModel(), SIGNAL( currentChanged(
const QModelIndex&,
const QModelIndex& ) ),
this, SLOT(
layerChanged() ) );
375 int index = stackedWidget->addWidget( widget );
376 stackedWidget->setCurrentIndex( index );
391 btnLock->setChecked( layer->
isLocked() );
396 QModelIndex idx = layersTree->currentIndex();
397 if ( !idx.isValid() )
404 insertIdx = item->row();
410 if ( insertIdx == -1 )
415 item->insertRow( insertIdx == -1 ? 0 : insertIdx, newLayerItem );
418 layersTree->setCurrentIndex(
model->indexFromItem( newLayerItem ) );
426 int row = item->row();
429 int layerIdx = parent->rowCount() - row - 1;
433 parent->removeRow( row );
436 QModelIndex newIdx = parent->child( 0 )->index();
437 layersTree->setCurrentIndex( newIdx );
460 int row = item->row();
465 int layerIdx = parent->rowCount() - row - 1;
470 QList<QStandardItem*> rowItems = parent->takeRow( row );
471 parent->insertRows( row + offset, rowItems );
474 QModelIndex newIdx = rowItems[ 0 ]->index();
475 layersTree->setCurrentIndex( newIdx );
486 layer->
setLocked( btnLock->isChecked() );
492 QString name = QInputDialog::getText(
this,
tr(
"Symbol name" ),
493 tr(
"Please enter name for the symbol:" ), QLineEdit::Normal,
tr(
"New symbol" ), &ok );
494 if ( !ok || name.isEmpty() )
500 int res = QMessageBox::warning(
this,
tr(
"Save symbol" ),
501 tr(
"Symbol with name '%1' already exists. Overwrite?" )
503 QMessageBox::Yes | QMessageBox::No );
504 if ( res != QMessageBox::Yes )
524 item->removeRow( 0 );
532 layersTree->setExpanded( item->index(), true );
537 int layerIdx = item->parent()->rowCount() - item->row() - 1;