/
qgscomposerattributetable.cpp
executable file
·711 lines (616 loc) · 20.3 KB
/
qgscomposerattributetable.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
/***************************************************************************
qgscomposerattributetable.cpp
-----------------------------
begin : April 2010
copyright : (C) 2010 by Marco Hugentobler
email : marco at hugis dot net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgscomposerattributetable.h"
#include "qgscomposertablecolumn.h"
#include "qgscomposermap.h"
#include "qgscomposerutils.h"
#include "qgsmaplayerregistry.h"
#include "qgsvectorlayer.h"
//QgsComposerAttributeTableCompare
QgsComposerAttributeTableCompare::QgsComposerAttributeTableCompare()
: mCurrentSortColumn( 0 ), mAscending( true )
{
}
bool QgsComposerAttributeTableCompare::operator()( const QgsAttributeMap& m1, const QgsAttributeMap& m2 )
{
QVariant v1 = m1[mCurrentSortColumn];
QVariant v2 = m2[mCurrentSortColumn];
bool less = false;
//sort null values first
if ( v1.isNull() && v2.isNull() )
{
less = false;
}
else if ( v1.isNull() )
{
less = true;
}
else if ( v2.isNull() )
{
less = false;
}
else
{
//otherwise sort by converting to corresponding type and comparing
switch ( v1.type() )
{
case QVariant::Int:
case QVariant::UInt:
case QVariant::LongLong:
case QVariant::ULongLong:
less = v1.toLongLong() < v2.toLongLong();
break;
case QVariant::Double:
less = v1.toDouble() < v2.toDouble();
break;
case QVariant::Date:
less = v1.toDate() < v2.toDate();
break;
case QVariant::DateTime:
less = v1.toDateTime() < v2.toDateTime();
break;
case QVariant::Time:
less = v1.toTime() < v2.toTime();
break;
default:
//use locale aware compare for strings
less = v1.toString().localeAwareCompare( v2.toString() ) < 0;
break;
}
}
return ( mAscending ? less : !less );
}
//QgsComposerAttributeTable
QgsComposerAttributeTable::QgsComposerAttributeTable( QgsComposition* composition )
: QgsComposerTable( composition )
, mVectorLayer( 0 )
, mComposerMap( 0 )
, mMaximumNumberOfFeatures( 5 )
, mShowOnlyVisibleFeatures( false )
, mFilterFeatures( false )
, mFeatureFilter( "" )
{
//set first vector layer from layer registry as default one
QMap<QString, QgsMapLayer*> layerMap = QgsMapLayerRegistry::instance()->mapLayers();
QMap<QString, QgsMapLayer*>::const_iterator mapIt = layerMap.constBegin();
for ( ; mapIt != layerMap.constEnd(); ++mapIt )
{
QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( mapIt.value() );
if ( vl )
{
mVectorLayer = vl;
break;
}
}
if ( mVectorLayer )
{
resetColumns();
}
connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( removeLayer( const QString& ) ) );
if ( mComposition )
{
//refresh table attributes when composition is refreshed
connect( mComposition, SIGNAL( refreshItemsTriggered() ), this, SLOT( refreshAttributes() ) );
//connect to atlas feature changes to update table rows
connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( refreshAttributes() ) );
}
}
QgsComposerAttributeTable::~QgsComposerAttributeTable()
{
}
void QgsComposerAttributeTable::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
{
if ( mComposerMap && mComposerMap->isDrawing() )
{
return;
}
QgsComposerTable::paint( painter, itemStyle, pWidget );
}
void QgsComposerAttributeTable::setVectorLayer( QgsVectorLayer* layer )
{
if ( layer == mVectorLayer )
{
//no change
return;
}
if ( mVectorLayer )
{
//disconnect from previous layer
QObject::disconnect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
}
mVectorLayer = layer;
//rebuild column list to match all columns from layer
resetColumns();
refreshAttributes();
//listen for modifications to layer and refresh table when they occur
QObject::connect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
}
void QgsComposerAttributeTable::resetColumns()
{
if ( !mVectorLayer )
{
return;
}
//remove existing columns
qDeleteAll( mColumns );
mColumns.clear();
//rebuild columns list from vector layer fields
const QgsFields& fields = mVectorLayer->pendingFields();
for ( int idx = 0; idx < fields.count(); ++idx )
{
QString currentAlias = mVectorLayer->attributeDisplayName( idx );
QgsComposerTableColumn* col = new QgsComposerTableColumn;
col->setAttribute( fields[idx].name() );
col->setHeading( currentAlias );
mColumns.append( col );
}
}
void QgsComposerAttributeTable::setComposerMap( const QgsComposerMap* map )
{
if ( map == mComposerMap )
{
//no change
return;
}
if ( mComposerMap )
{
//disconnect from previous map
QObject::disconnect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
}
mComposerMap = map;
if ( mComposerMap )
{
//listen out for extent changes in linked map
QObject::connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
}
refreshAttributes();
}
void QgsComposerAttributeTable::setMaximumNumberOfFeatures( int features )
{
if ( features == mMaximumNumberOfFeatures )
{
return;
}
mMaximumNumberOfFeatures = features;
refreshAttributes();
}
void QgsComposerAttributeTable::setDisplayOnlyVisibleFeatures( bool visibleOnly )
{
if ( visibleOnly == mShowOnlyVisibleFeatures )
{
return;
}
mShowOnlyVisibleFeatures = visibleOnly;
refreshAttributes();
}
void QgsComposerAttributeTable::setFilterFeatures( bool filter )
{
if ( filter == mFilterFeatures )
{
return;
}
mFilterFeatures = filter;
refreshAttributes();
}
void QgsComposerAttributeTable::setFeatureFilter( const QString& expression )
{
if ( expression == mFeatureFilter )
{
return;
}
mFeatureFilter = expression;
refreshAttributes();
}
QSet<int> QgsComposerAttributeTable::displayAttributes() const
{
return fieldsToDisplay().toSet();
}
void QgsComposerAttributeTable::setDisplayAttributes( const QSet<int>& attr, bool refresh )
{
if ( !mVectorLayer )
{
return;
}
//rebuild columns list, taking only attributes with index in supplied QSet
qDeleteAll( mColumns );
mColumns.clear();
const QgsFields& fields = mVectorLayer->pendingFields();
if ( !attr.empty() )
{
QSet<int>::const_iterator attIt = attr.constBegin();
for ( ; attIt != attr.constEnd(); ++attIt )
{
int attrIdx = ( *attIt );
if ( !fields.exists( attrIdx ) )
{
continue;
}
QString currentAlias = mVectorLayer->attributeDisplayName( attrIdx );
QgsComposerTableColumn* col = new QgsComposerTableColumn;
col->setAttribute( fields[attrIdx].name() );
col->setHeading( currentAlias );
mColumns.append( col );
}
}
else
{
//resetting, so add all attributes to columns
for ( int idx = 0; idx < fields.count(); ++idx )
{
QString currentAlias = mVectorLayer->attributeDisplayName( idx );
QgsComposerTableColumn* col = new QgsComposerTableColumn;
col->setAttribute( fields[idx].name() );
col->setHeading( currentAlias );
mColumns.append( col );
}
}
if ( refresh )
{
refreshAttributes();
}
}
QMap<int, QString> QgsComposerAttributeTable::fieldAliasMap() const
{
QMap<int, QString> fieldAliasMap;
QList<QgsComposerTableColumn*>::const_iterator columnIt = mColumns.constBegin();
for ( ; columnIt != mColumns.constEnd(); ++columnIt )
{
int attrIdx = mVectorLayer->fieldNameIndex(( *columnIt )->attribute() );
fieldAliasMap.insert( attrIdx, ( *columnIt )->heading() );
}
return fieldAliasMap;
}
void QgsComposerAttributeTable::restoreFieldAliasMap( const QMap<int, QString>& map )
{
if ( !mVectorLayer )
{
return;
}
QList<QgsComposerTableColumn*>::const_iterator columnIt = mColumns.constBegin();
for ( ; columnIt != mColumns.constEnd(); ++columnIt )
{
int attrIdx = mVectorLayer->fieldNameIndex(( *columnIt )->attribute() );
if ( map.contains( attrIdx ) )
{
( *columnIt )->setHeading( map.value( attrIdx ) );
}
else
{
( *columnIt )->setHeading( mVectorLayer->attributeDisplayName( attrIdx ) );
}
}
}
void QgsComposerAttributeTable::setFieldAliasMap( const QMap<int, QString>& map )
{
restoreFieldAliasMap( map );
refreshAttributes();
}
QList<int> QgsComposerAttributeTable::fieldsToDisplay() const
{
//kept for api compatibility with 2.0 only, can be removed after next api break
QList<int> fields;
QList<QgsComposerTableColumn*>::const_iterator columnIt = mColumns.constBegin();
for ( ; columnIt != mColumns.constEnd(); ++columnIt )
{
int idx = mVectorLayer->fieldNameIndex(( *columnIt )->attribute() );
fields.append( idx );
}
return fields;
}
bool QgsComposerAttributeTable::getFeatureAttributes( QList<QgsAttributeMap> &attributeMaps )
{
if ( !mVectorLayer )
{
return false;
}
attributeMaps.clear();
//prepare filter expression
std::auto_ptr<QgsExpression> filterExpression;
bool activeFilter = false;
if ( mFilterFeatures && !mFeatureFilter.isEmpty() )
{
filterExpression = std::auto_ptr<QgsExpression>( new QgsExpression( mFeatureFilter ) );
if ( !filterExpression->hasParserError() )
{
activeFilter = true;
}
}
QgsRectangle selectionRect;
if ( mComposerMap && mShowOnlyVisibleFeatures )
{
selectionRect = *mComposerMap->currentMapExtent();
if ( mVectorLayer && mComposition->mapSettings().hasCrsTransformEnabled() )
{
//transform back to layer CRS
QgsCoordinateTransform coordTransform( mVectorLayer->crs(), mComposition->mapSettings().destinationCrs() );
try
{
selectionRect = coordTransform.transformBoundingBox( selectionRect, QgsCoordinateTransform::ReverseTransform );
}
catch ( QgsCsException &cse )
{
Q_UNUSED( cse );
return false;
}
}
}
QgsFeatureRequest req;
if ( !selectionRect.isEmpty() )
req.setFilterRect( selectionRect );
req.setFlags( mShowOnlyVisibleFeatures ? QgsFeatureRequest::ExactIntersect : QgsFeatureRequest::NoFlags );
QgsFeature f;
int counter = 0;
QgsFeatureIterator fit = mVectorLayer->getFeatures( req );
while ( fit.nextFeature( f ) && counter < mMaximumNumberOfFeatures )
{
//check feature against filter
if ( activeFilter )
{
QVariant result = filterExpression->evaluate( &f, mVectorLayer->pendingFields() );
// skip this feature if the filter evaluation is false
if ( !result.toBool() )
{
continue;
}
}
attributeMaps.push_back( QgsAttributeMap() );
QList<QgsComposerTableColumn*>::const_iterator columnIt = mColumns.constBegin();
int i = 0;
for ( ; columnIt != mColumns.constEnd(); ++columnIt )
{
int idx = mVectorLayer->fieldNameIndex(( *columnIt )->attribute() );
if ( idx != -1 )
{
attributeMaps.last().insert( i, f.attributes()[idx] );
}
else
{
// Lets assume it's an expression
QgsExpression* expression = new QgsExpression(( *columnIt )->attribute() );
expression->setCurrentRowNumber( counter + 1 );
expression->prepare( mVectorLayer->pendingFields() );
QVariant value = expression->evaluate( f ) ;
attributeMaps.last().insert( i, value.toString() );
}
i++;
}
++counter;
}
//sort the list, starting with the last attribute
QgsComposerAttributeTableCompare c;
QList< QPair<int, bool> > sortColumns = sortAttributes();
for ( int i = sortColumns.size() - 1; i >= 0; --i )
{
c.setSortColumn( sortColumns.at( i ).first );
c.setAscending( sortColumns.at( i ).second );
qStableSort( attributeMaps.begin(), attributeMaps.end(), c );
}
adjustFrameToSize();
return true;
}
void QgsComposerAttributeTable::removeLayer( QString layerId )
{
if ( mVectorLayer )
{
if ( layerId == mVectorLayer->id() )
{
mVectorLayer = 0;
//remove existing columns
qDeleteAll( mColumns );
mColumns.clear();
}
}
}
void QgsComposerAttributeTable::setSceneRect( const QRectF& rectangle )
{
//update rect for data defined size and position
QRectF evaluatedRect = evalItemRect( rectangle );
QgsComposerItem::setSceneRect( evaluatedRect );
//refresh table attributes, since number of features has likely changed
refreshAttributes();
}
void QgsComposerAttributeTable::setSortAttributes( const QList<QPair<int, bool> > att )
{
//first, clear existing sort by ranks
QList<QgsComposerTableColumn*>::iterator columnIt = mColumns.begin();
for ( ; columnIt != mColumns.end(); ++columnIt )
{
( *columnIt )->setSortByRank( 0 );
}
//now, update sort rank of specified columns
QList< QPair<int, bool > >::const_iterator sortedColumnIt = att.constBegin();
int rank = 1;
for ( ; sortedColumnIt != att.constEnd(); ++sortedColumnIt )
{
if (( *sortedColumnIt ).first >= mColumns.length() )
{
continue;
}
mColumns[( *sortedColumnIt ).first ]->setSortByRank( rank );
mColumns[( *sortedColumnIt ).first ]->setSortOrder(( *sortedColumnIt ).second ? Qt::AscendingOrder : Qt::DescendingOrder );
rank++;
}
refreshAttributes();
}
static bool columnsBySortRank( QPair<int, QgsComposerTableColumn* > a, QPair<int, QgsComposerTableColumn* > b )
{
return a.second->sortByRank() < b.second->sortByRank();
}
QList<QPair<int, bool> > QgsComposerAttributeTable::sortAttributes() const
{
//generate list of all sorted columns
QList< QPair<int, QgsComposerTableColumn* > > sortedColumns;
QList<QgsComposerTableColumn*>::const_iterator columnIt = mColumns.constBegin();
int idx = 0;
for ( ; columnIt != mColumns.constEnd(); ++columnIt )
{
if (( *columnIt )->sortByRank() > 0 )
{
sortedColumns.append( qMakePair( idx, *columnIt ) );
}
idx++;
}
//sort columns by rank
qSort( sortedColumns.begin(), sortedColumns.end(), columnsBySortRank );
//generate list of column index, bool for sort direction (to match 2.0 api)
QList<QPair<int, bool> > attributesBySortRank;
QList< QPair<int, QgsComposerTableColumn* > >::const_iterator sortedColumnIt = sortedColumns.constBegin();
for ( ; sortedColumnIt != sortedColumns.constEnd(); ++sortedColumnIt )
{
attributesBySortRank.append( qMakePair(( *sortedColumnIt ).first,
( *sortedColumnIt ).second->sortOrder() == Qt::AscendingOrder ) );
}
return attributesBySortRank;
}
bool QgsComposerAttributeTable::writeXML( QDomElement& elem, QDomDocument & doc ) const
{
QDomElement composerTableElem = doc.createElement( "ComposerAttributeTable" );
composerTableElem.setAttribute( "showOnlyVisibleFeatures", mShowOnlyVisibleFeatures );
composerTableElem.setAttribute( "maxFeatures", mMaximumNumberOfFeatures );
composerTableElem.setAttribute( "filterFeatures", mFilterFeatures ? "true" : "false" );
composerTableElem.setAttribute( "featureFilter", mFeatureFilter );
if ( mComposerMap )
{
composerTableElem.setAttribute( "composerMap", mComposerMap->id() );
}
else
{
composerTableElem.setAttribute( "composerMap", -1 );
}
if ( mVectorLayer )
{
composerTableElem.setAttribute( "vectorLayer", mVectorLayer->id() );
}
elem.appendChild( composerTableElem );
bool ok = tableWriteXML( composerTableElem, doc );
return ok;
}
bool QgsComposerAttributeTable::readXML( const QDomElement& itemElem, const QDomDocument& doc )
{
if ( itemElem.isNull() )
{
return false;
}
//read general table properties
if ( !tableReadXML( itemElem, doc ) )
{
return false;
}
mShowOnlyVisibleFeatures = itemElem.attribute( "showOnlyVisibleFeatures", "1" ).toInt();
mFilterFeatures = itemElem.attribute( "filterFeatures", "false" ) == "true" ? true : false;
mFeatureFilter = itemElem.attribute( "featureFilter", "" );
//composer map
int composerMapId = itemElem.attribute( "composerMap", "-1" ).toInt();
if ( composerMapId == -1 )
{
mComposerMap = 0;
}
if ( composition() )
{
mComposerMap = composition()->getComposerMapById( composerMapId );
}
else
{
mComposerMap = 0;
}
if ( mComposerMap )
{
//if we have found a valid map item, listen out to extent changes on it and refresh the table
QObject::connect( mComposerMap, SIGNAL( extentChanged() ), this, SLOT( refreshAttributes() ) );
}
//vector layer
QString layerId = itemElem.attribute( "vectorLayer", "not_existing" );
if ( layerId == "not_existing" )
{
mVectorLayer = 0;
}
else
{
QgsMapLayer* ml = QgsMapLayerRegistry::instance()->mapLayer( layerId );
if ( ml )
{
mVectorLayer = dynamic_cast<QgsVectorLayer*>( ml );
if ( mVectorLayer )
{
//if we have found a valid vector layer, listen for modifications on it and refresh the table
QObject::connect( mVectorLayer, SIGNAL( layerModified() ), this, SLOT( refreshAttributes() ) );
}
}
}
//restore display attribute map. This is required to upgrade pre 2.4 projects.
QSet<int> displayAttributes;
QDomNodeList displayAttributeList = itemElem.elementsByTagName( "displayAttributes" );
if ( displayAttributeList.size() > 0 )
{
QDomElement displayAttributesElem = displayAttributeList.at( 0 ).toElement();
QDomNodeList attributeEntryList = displayAttributesElem.elementsByTagName( "attributeEntry" );
for ( int i = 0; i < attributeEntryList.size(); ++i )
{
QDomElement attributeEntryElem = attributeEntryList.at( i ).toElement();
int index = attributeEntryElem.attribute( "index", "-1" ).toInt();
if ( index != -1 )
{
displayAttributes.insert( index );
}
}
setDisplayAttributes( displayAttributes, false );
}
//restore alias map. This is required to upgrade pre 2.4 projects.
QMap<int, QString> fieldAliasMap;
QDomNodeList aliasMapNodeList = itemElem.elementsByTagName( "attributeAliasMap" );
if ( aliasMapNodeList.size() > 0 )
{
QDomElement attributeAliasMapElem = aliasMapNodeList.at( 0 ).toElement();
QDomNodeList aliasMepEntryList = attributeAliasMapElem.elementsByTagName( "aliasEntry" );
for ( int i = 0; i < aliasMepEntryList.size(); ++i )
{
QDomElement aliasEntryElem = aliasMepEntryList.at( i ).toElement();
int key = aliasEntryElem.attribute( "key", "-1" ).toInt();
QString value = aliasEntryElem.attribute( "value", "" );
fieldAliasMap.insert( key, value );
}
restoreFieldAliasMap( fieldAliasMap );
}
//restore sort columns. This is required to upgrade pre 2.4 projects.
QDomElement sortColumnsElem = itemElem.firstChildElement( "sortColumns" );
if ( !sortColumnsElem.isNull() && mVectorLayer )
{
QDomNodeList columns = sortColumnsElem.elementsByTagName( "column" );
const QgsFields& fields = mVectorLayer->pendingFields();
for ( int i = 0; i < columns.size(); ++i )
{
QDomElement columnElem = columns.at( i ).toElement();
int attribute = columnElem.attribute( "index" ).toInt();
Qt::SortOrder order = columnElem.attribute( "ascending" ) == "true" ? Qt::AscendingOrder : Qt::DescendingOrder;
//find corresponding column
QList<QgsComposerTableColumn*>::iterator columnIt = mColumns.begin();
for ( ; columnIt != mColumns.end(); ++columnIt )
{
if (( *columnIt )->attribute() == fields[attribute].name() )
{
( *columnIt )->setSortByRank( i + 1 );
( *columnIt )->setSortOrder( order );
break;
}
}
}
}
//must be done here because tableReadXML->setSceneRect changes mMaximumNumberOfFeatures
mMaximumNumberOfFeatures = itemElem.attribute( "maxFeatures", "5" ).toInt();
refreshAttributes();
emit itemChanged();
return true;
}