void QgsComposerColumnSourceDelegate::setEditorData( QWidget* editor, const QModelIndex& index ) const
{
  QString field = index.model()->data( index, Qt::EditRole ).toString();

  //set the value for the field combobox
  QgsFieldExpressionWidget *fieldExpression = static_cast<QgsFieldExpressionWidget*>( editor );
  fieldExpression->setField( field );
}
Пример #2
0
QgsDataDefinedSymbolDialog::QgsDataDefinedSymbolDialog( const QList< DataDefinedSymbolEntry >& entries, const QgsVectorLayer* vl, QWidget * parent, Qt::WindowFlags f )
    : QDialog( parent, f )
    , mVectorLayer( vl )
{
  setupUi( this );

  QgsFields attributeFields;
  if ( mVectorLayer )
  {
    attributeFields = mVectorLayer->pendingFields();
  }

  int i = 0;
  QList< DataDefinedSymbolEntry >::const_iterator entryIt = entries.constBegin();
  for ( ; entryIt != entries.constEnd(); ++entryIt )
  {
    QTreeWidgetItem* item = new QTreeWidgetItem( mTreeWidget );

    //check box
    QCheckBox* cb = new QCheckBox( entryIt->title, this );
    cb->setChecked( !entryIt->initialValue.isEmpty() );
    item->setData( 0, Qt::UserRole, entryIt->property );
    mTreeWidget->setItemWidget( item, 0, cb );

    // expression
    QgsFieldExpressionWidget* few = new QgsFieldExpressionWidget( this );
    few->setMaximumWidth( 350 );
    few->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Maximum );
    few->setLayer( const_cast<QgsVectorLayer*>( vl ) );
    few->setField( entryIt->initialValue );
    mTreeWidget->setItemWidget( item, 1, few );

    //help text
    item->setText( 2, entryIt->helpText );

    mTreeWidget->addTopLevelItem( item );
    ++i;
  }

  for ( int c = 0; c != mTreeWidget->columnCount() - 1; c++ )
    mTreeWidget->resizeColumnToContents( c );

  QSettings settings;
  restoreGeometry( settings.value( "/Windows/QgsDataDefinedSymbolDialog/geometry" ).toByteArray() );
}