SHOW:
|
|
- or go back to the newest paste.
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( |
26 | + | QgsVectorLayerProperties::QgsVectorLayerProperties(...) |
27 | - | QgsVectorLayer *lyr, |
27 | + | |
28 | - | QWidget * parent, |
28 | + | |
29 | - | Qt::WFlags fl |
29 | + | |
30 | - | ) |
30 | + | |
31 | {.....} // QgsVectorLayerProperties ctor | |
32 | ||
33 | void QgsVectorLayerProperties::loadRows() | |
34 | { | |
35 | - | {..... |
35 | + | |
36 | - | } // QgsVectorLayerProperties ctor |
36 | + | |
37 | QgsAttributesTreeDelegate* attributesTreeDelegate = new QgsAttributesTreeDelegate( this ); | |
38 | connect( attributesTreeDelegate , SIGNAL( itemChanged( const QModelIndex &index , QString data ) ) , this, SLOT( on_mAttributesTree_itemChanged( const QModelIndex &index , QString data ) ) ); | |
39 | ||
40 | mAttributesTree->setModel( &mTreeModel ); | |
41 | mAttributesTree->setSortingEnabled( true ); | |
42 | mAttributesTree->setEditTriggers( QAbstractItemView::CurrentChanged ); | |
43 | mAttributesTree->setItemDelegate( attributesTreeDelegate ); | |
44 | ||
45 | for ( QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); it++ ) | |
46 | addAttributeRow( it.key(), it.value() ); | |
47 | } | |
48 | ||
49 | void QgsVectorLayerProperties::on_mAttributesTree_itemChanged( const QModelIndex &index , QString data ) | |
50 | { | |
51 | QgsDebugMsg("ITEMCHANGED"); | |
52 | if ( index.column() == attrAliasCol && layer ) | |
53 | { | |
54 | int idx = index.sibling( index.row(), attrIdCol ).data().toInt(); | |
55 | const QgsFieldMap &fields = layer->pendingFields(); | |
56 | if ( !fields.contains( idx ) ) | |
57 | return; // index must be wrong | |
58 | layer->addAttributeAlias( idx, data ); | |
59 | mTreeModel.setData( index , data , Qt::DisplayRole ); | |
60 | } | |
61 | } |