Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- QWidget *QgsAttributesTreeDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const
- {
- Q_UNUSED( option );
- if ( index.column() == QgsVectorLayerProperties::attrAliasCol )
- {
- QLineEdit *le = new QLineEdit( parent );
- le->setText( index.data( Qt::DisplayRole ).toString() );
- return le;
- }
- return 0;
- };
- void QgsAttributesTreeDelegate::setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const
- {
- QgsDebugMsg("***ITEMreleased***");
- QLineEdit *le = qobject_cast<QLineEdit *>( editor );
- if ( le )
- {
- QString data = le->text();
- emit itemChanged( index , data );
- return;
- }
- }
- QgsVectorLayerProperties::QgsVectorLayerProperties(...)
- : QDialog( parent, fl )
- , layer( lyr )
- , mMetadataFilled( false )
- , mRendererDialog( 0 )
- {.....} // QgsVectorLayerProperties ctor
- void QgsVectorLayerProperties::loadRows()
- {
- const QgsFieldMap &fields = layer->pendingFields();
- QgsAttributesTreeDelegate* attributesTreeDelegate = new QgsAttributesTreeDelegate( this );
- connect( attributesTreeDelegate , SIGNAL( itemChanged( const QModelIndex &index , QString data ) ) , this, SLOT( on_mAttributesTree_itemChanged( const QModelIndex &index , QString data ) ) );
- mAttributesTree->setModel( &mTreeModel );
- mAttributesTree->setSortingEnabled( true );
- mAttributesTree->setEditTriggers( QAbstractItemView::CurrentChanged );
- mAttributesTree->setItemDelegate( attributesTreeDelegate );
- for ( QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); it++ )
- addAttributeRow( it.key(), it.value() );
- }
- void QgsVectorLayerProperties::on_mAttributesTree_itemChanged( const QModelIndex &index , QString data )
- {
- QgsDebugMsg("ITEMCHANGED");
- if ( index.column() == attrAliasCol && layer )
- {
- int idx = index.sibling( index.row(), attrIdCol ).data().toInt();
- const QgsFieldMap &fields = layer->pendingFields();
- if ( !fields.contains( idx ) )
- return; // index must be wrong
- layer->addAttributeAlias( idx, data );
- mTreeModel.setData( index , data , Qt::DisplayRole );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement