void QgsStyleManagerDialog::populateSymbols( const QStringList& symbolNames, bool check )
{
  QStandardItemModel* model = qobject_cast<QStandardItemModel*>( listItems->model() );
  model->clear();

  int type = currentItemType();

  for ( int i = 0; i < symbolNames.count(); ++i )
  {
    QString name = symbolNames[i];
    QgsSymbol* symbol = mStyle->symbol( name );
    if ( symbol && symbol->type() == type )
    {
      QStandardItem* item = new QStandardItem( name );
      QIcon icon = QgsSymbolLayerUtils::symbolPreviewIcon( symbol, listItems->iconSize() );
      item->setIcon( icon );
      item->setData( name ); // used to find out original name when user edited the name
      item->setCheckable( check );
      item->setToolTip( name );
      // add to model
      model->appendRow( item );
    }
    delete symbol;
  }
  selectedSymbolsChanged( QItemSelection(), QItemSelection() );
  symbolSelected( listItems->currentIndex() );
}
void QgsMilXLibrary::itemClicked( const QModelIndex &index )
{

  QModelIndex sourceIndex = mFilterProxyModel->mapToSource( index );
  QList<QModelIndex> indexStack;
  indexStack.prepend( sourceIndex );
  while ( sourceIndex.parent().isValid() )
  {
    sourceIndex = sourceIndex.parent();
    indexStack.prepend( sourceIndex );
  }

  QStandardItem* item = mGalleryModel->itemFromIndex( indexStack.front() );
  if ( item )
  {
    for ( int i = 1, n = indexStack.size(); i < n; ++i )
    {
      item = item->child( indexStack[i].row() );
    }

    QgsMilxSymbolTemplate symbolTemplate;
    symbolTemplate.symbolXml = item->data( SymbolXmlRole ).toString();
    if ( symbolTemplate.symbolXml.isEmpty() )
    {
      return;
    }
    hide();
    if ( symbolTemplate.symbolXml == "<custom>" )
    {
      MilXClient::SymbolDesc desc;
      WId wid = mIface->mapCanvas()->winId();
      if ( !MilXClient::createSymbol( symbolTemplate.symbolXml, desc, wid ) )
      {
        return;
      }
      symbolTemplate.symbolMilitaryName = desc.militaryName;
      symbolTemplate.minNPoints = desc.minNumPoints;
      symbolTemplate.hasVariablePoints = desc.hasVariablePoints;
      symbolTemplate.pixmap = QPixmap::fromImage( desc.icon ).scaled( 32, 32, Qt::KeepAspectRatio );
    }
    else
    {
      symbolTemplate.symbolMilitaryName = item->data( SymbolMilitaryNameRole ).toString();
      symbolTemplate.minNPoints = item->data( SymbolPointCountRole ).toInt();
      symbolTemplate.hasVariablePoints = item->data( SymbolVariablePointsRole ).toInt();
      symbolTemplate.pixmap = item->icon().pixmap( item->icon().actualSize( QSize( 32, 32 ) ) );
    }
    emit symbolSelected( symbolTemplate );
  }
}
void QgsStyleManagerDialog::populateColorRamps( const QStringList& colorRamps, bool check )
{
  QStandardItemModel* model = qobject_cast<QStandardItemModel*>( listItems->model() );
  model->clear();

  for ( int i = 0; i < colorRamps.count(); ++i )
  {
    QString name = colorRamps[i];
    QScopedPointer< QgsColorRamp > ramp( mStyle->colorRamp( name ) );

    QStandardItem* item = new QStandardItem( name );
    QIcon icon = QgsSymbolLayerUtils::colorRampPreviewIcon( ramp.data(), listItems->iconSize() );
    item->setIcon( icon );
    item->setData( name ); // used to find out original name when user edited the name
    item->setCheckable( check );
    item->setToolTip( name );
    model->appendRow( item );
  }
  selectedSymbolsChanged( QItemSelection(), QItemSelection() );
  symbolSelected( listItems->currentIndex() );
}