From kde-commits Sat Jul 12 14:42:13 2008 From: Volker Krause Date: Sat, 12 Jul 2008 14:42:13 +0000 To: kde-commits Subject: KDE/kdepim/akonadi/clients/akonadiconsole Message-Id: <1215873733.227896.27966.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=121587374207375 SVN commit 831369 by vkrause: Only write attributes that actually have been changed. This avoids overwriting attribute changes done by other pages. M +20 -2 collectionattributespage.cpp M +4 -0 collectionattributespage.h --- trunk/KDE/kdepim/akonadi/clients/akonadiconsole/collectionattributespage.cpp #831368:831369 @@ -52,20 +52,25 @@ QModelIndex index = mModel->index( i, 0 ); Q_ASSERT( index.isValid() ); mModel->setData( index, QString::fromLatin1( list[i]->type() ) ); + mModel->item( i, 0 )->setEditable( false ); index = mModel->index( i, 1 ); Q_ASSERT( index.isValid() ); mModel->setData( index, QString::fromLatin1( list[i]->serialized() ) ); mModel->itemFromIndex( index )->setFlags( Qt::ItemIsEditable | mModel->flags( index ) ); } ui.attrView->setModel( mModel ); + connect( mModel, SIGNAL(itemChanged(QStandardItem*)), SLOT(attributeChanged(QStandardItem*)) ); } void CollectionAttributePage::save(Collection & col) { - col.clearAttributes(); + foreach ( const QString &del, mDeleted ) + col.removeAttribute( del.toLatin1() ); for ( int i = 0; i < mModel->rowCount(); ++i ) { const QModelIndex typeIndex = mModel->index( i, 0 ); Q_ASSERT( typeIndex.isValid() ); + if ( !mChanged.contains( typeIndex.data().toString() ) ) + continue; const QModelIndex valueIndex = mModel->index( i, 1 ); Q_ASSERT( valueIndex.isValid() ); Attribute* attr = AttributeFactory::createAttribute( mModel->data( typeIndex ).toString().toLatin1() ); @@ -79,11 +84,14 @@ { if ( ui.attrName->text().isEmpty() ) return; + const QString attr = ui.attrName->text(); + mChanged.insert( attr ); + mDeleted.remove( attr ); const int row = mModel->rowCount(); mModel->insertRow( row ); QModelIndex index = mModel->index( row, 0 ); Q_ASSERT( index.isValid() ); - mModel->setData( index, ui.attrName->text() ); + mModel->setData( index, attr ); ui.attrName->clear(); } @@ -92,7 +100,17 @@ QModelIndexList selection = ui.attrView->selectionModel()->selectedRows(); if ( selection.count() != 1 ) return; + const QString attr = selection.first().data().toString(); + mChanged.remove( attr ); + mDeleted.insert( attr ); mModel->removeRow( selection.first().row() ); } +void CollectionAttributePage::attributeChanged( QStandardItem *item ) +{ + const QString attr = mModel->data( mModel->index( item->row(), 0 ) ).toString(); + mDeleted.remove( attr ); + mChanged.insert( attr ); +} + #include "collectionattributespage.moc" --- trunk/KDE/kdepim/akonadi/clients/akonadiconsole/collectionattributespage.h #831368:831369 @@ -24,6 +24,7 @@ #include +class QStandardItem; class QStandardItemModel; class CollectionAttributePage : public Akonadi::CollectionPropertiesPage @@ -38,10 +39,13 @@ private slots: void addAttribute(); void delAttribute(); + void attributeChanged( QStandardItem *item ); private: Ui::CollectionAttributesPage ui; QStandardItemModel *mModel; + QSet mDeleted; + QSet mChanged; }; #endif