3nids

Untitled

Jul 19th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. QWidget *QgsAttributesTreeDelegate::createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const
  2. {
  3.   Q_UNUSED( option );
  4.   if ( index.column() == QgsVectorLayerProperties::attrAliasCol )
  5.   {
  6.     QLineEdit *le = new QLineEdit( parent );
  7.     le->setText( index.data( Qt::DisplayRole ).toString() );
  8.     return le;
  9.   }
  10.   return 0;
  11. };
  12.  
  13. void QgsAttributesTreeDelegate::setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const
  14. {
  15.   QgsDebugMsg("***ITEMreleased***");
  16.   QLineEdit *le = qobject_cast<QLineEdit *>( editor );
  17.   if ( le )
  18.   {
  19.     QString data = le->text();
  20.     emit itemChanged( index , data );
  21.     return;
  22.   }
  23. }
  24.  
  25.  
  26. QgsVectorLayerProperties::QgsVectorLayerProperties(
  27.   QgsVectorLayer *lyr,
  28.   QWidget * parent,
  29.   Qt::WFlags fl
  30. )
  31.     : QDialog( parent, fl )
  32.     , layer( lyr )
  33.     , mMetadataFilled( false )
  34.     , mRendererDialog( 0 )
  35. {.....
  36. } // QgsVectorLayerProperties ctor
  37.  
  38. void QgsVectorLayerProperties::loadRows()
  39. {
  40.   const QgsFieldMap &fields = layer->pendingFields();
  41.  
  42.   QgsAttributesTreeDelegate* attributesTreeDelegate = new QgsAttributesTreeDelegate( this );
  43.   connect( attributesTreeDelegate , SIGNAL( itemChanged( const QModelIndex &index , QString data ) ) , this, SLOT( on_mAttributesTree_itemChanged( const QModelIndex &index , QString data ) ) );
  44.  
  45.   mAttributesTree->setModel( &mTreeModel );
  46.   mAttributesTree->setSortingEnabled( true );
  47.   mAttributesTree->setEditTriggers( QAbstractItemView::CurrentChanged );
  48.   mAttributesTree->setItemDelegate( attributesTreeDelegate );
  49.  
  50.   for ( QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); it++ )
  51.     addAttributeRow( it.key(), it.value() );
  52. }
  53.  
  54. void QgsVectorLayerProperties::on_mAttributesTree_itemChanged( const QModelIndex &index , QString data )
  55. {
  56.   QgsDebugMsg("ITEMCHANGED");
  57.   if ( index.column() == attrAliasCol && layer )
  58.   {
  59.     int idx = index.sibling( index.row(), attrIdCol ).data().toInt();
  60.     const QgsFieldMap &fields = layer->pendingFields();
  61.     if ( !fields.contains( idx ) )
  62.       return; // index must be wrong
  63.     layer->addAttributeAlias( idx, data );
  64.     mTreeModel.setData( index , data , Qt::DisplayRole );
  65.   }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment