KD Chart 2  [rev.2.5.1]
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
KDChartAttributesModel.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2013 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Chart library.
5 **
6 ** Licensees holding valid commercial KD Chart licenses may use this file in
7 ** accordance with the KD Chart Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 
23 #include "KDChartAttributesModel.h"
24 #include "KDChartPalette.h"
25 #include "KDChartGlobal.h"
26 
27 #include <QDebug>
28 #include <QPen>
29 #include <QPointer>
30 
31 #include <KDChartTextAttributes.h>
32 #include <KDChartFrameAttributes.h>
36 #include <KDChartBarAttributes.h>
38 #include <KDChartLineAttributes.h>
39 #include <KDChartPieAttributes.h>
44 #include <KDChartGridAttributes.h>
46 
47 #include <KDABLibFakes>
48 
49 
50 using namespace KDChart;
51 
52 
53 class AttributesModel::Private
54 {
55 public:
56  Private();
57 
59  QMap< int, QMap< int, QVariant > > horizontalHeaderDataMap;
60  QMap< int, QMap< int, QVariant > > verticalHeaderDataMap;
61  QMap< int, QVariant > modelDataMap;
62  QMap< int, QVariant > defaultsMap;
63  int dataDimension;
65  Palette palette;
66 };
67 
68 AttributesModel::Private::Private()
69  : dataDimension( 1 ),
70  paletteType( AttributesModel::PaletteTypeDefault ),
71  palette( Palette::defaultPalette() )
72 {
73 }
74 
75 #define d d_func()
76 
77 AttributesModel::AttributesModel( QAbstractItemModel* model, QObject * parent/* = 0 */ )
78  : AbstractProxyModel( parent ),
79  _d( new Private )
80 {
81  setSourceModel( model );
84 }
85 
87 {
88  delete _d;
89  _d = 0;
90 }
91 
93 {
94  *d = *other->d;
95 }
96 
97 bool AttributesModel::compareHeaderDataMaps( const QMap< int, QMap< int, QVariant > >& mapA,
98  const QMap< int, QMap< int, QVariant > >& mapB ) const
99 {
100  if ( mapA.count() != mapB.count() ) {
101  return false;
102  }
103  QMap< int, QMap< int, QVariant > >::const_iterator itA = mapA.constBegin();
104  QMap< int, QMap< int, QVariant > >::const_iterator itB = mapB.constBegin();
105  for ( ; itA != mapA.constEnd(); ++itA, ++itB ) {
106  if ( itA->count() != itB->count() ) {
107  return false;
108  }
109  QMap< int, QVariant >::const_iterator it2A = itA->constBegin();
110  QMap< int, QVariant >::const_iterator it2B = itB->constBegin();
111  for ( ; it2A != itA->constEnd(); ++it2A, ++it2B ) {
112  if ( it2A.key() != it2B.key() ) {
113  return false;
114  }
115  if ( !compareAttributes( it2A.key(), it2A.value(), it2B.value() ) ) {
116  return false;
117  }
118  }
119  }
120  return true;
121 }
122 
123 bool AttributesModel::compare( const AttributesModel* other ) const
124 {
125  if ( other == this ) {
126  return true;
127  }
128  if ( !other || d->paletteType != other->d->paletteType ) {
129  return false;
130  }
131 
132  {
133  if ( d->dataMap.count() != other->d->dataMap.count() ) {
134  return false;
135  }
136  QMap< int, QMap< int, QMap<int, QVariant > > >::const_iterator itA = d->dataMap.constBegin();
137  QMap< int, QMap< int, QMap<int, QVariant > > >::const_iterator itB = other->d->dataMap.constBegin();
138  for ( ; itA != d->dataMap.constEnd(); ++itA, ++itB ) {
139  if ( itA->count() != itB->count() ) {
140  return false;
141  }
142  QMap< int, QMap< int, QVariant > >::const_iterator it2A = itA->constBegin();
143  QMap< int, QMap< int, QVariant > >::const_iterator it2B = itB->constBegin();
144  for ( ; it2A != itA->constEnd(); ++it2A, ++it2B ) {
145  if ( it2A->count() != it2B->count() ) {
146  return false;
147  }
148  QMap< int, QVariant >::const_iterator it3A = it2A->constBegin();
149  QMap< int, QVariant >::const_iterator it3B = it2B->constBegin();
150  for ( ; it3A != it2A->constEnd(); ++it3A, ++it3B ) {
151  if ( it3A.key() != it3B.key() ) {
152  return false;
153  }
154  if ( !compareAttributes( it3A.key(), it3A.value(), it3B.value() ) ) {
155  return false;
156  }
157  }
158  }
159  }
160  }
161 
162  if ( !compareHeaderDataMaps( d->horizontalHeaderDataMap, other->d->horizontalHeaderDataMap ) ||
163  !compareHeaderDataMaps( d->verticalHeaderDataMap, other->d->verticalHeaderDataMap ) ) {
164  return false;
165  }
166 
167  {
168  if ( d->modelDataMap.count() != other->d->modelDataMap.count() ) {
169  return false;
170  }
171  QMap< int, QVariant >::const_iterator itA = d->modelDataMap.constBegin();
172  QMap< int, QVariant >::const_iterator itB = other->d->modelDataMap.constBegin();
173  for ( ; itA != d->modelDataMap.constEnd(); ++itA, ++itB ) {
174  if ( itA.key() != itB.key() ) {
175  return false;
176  }
177  if ( !compareAttributes( itA.key(), itA.value(), itB.value() ) ) {
178  return false;
179  }
180  }
181  }
182  return true;
183 }
184 
186  int role, const QVariant& a, const QVariant& b ) const
187 {
188  if ( isKnownAttributesRole( role ) ) {
189  switch ( role ) {
191  return (a.value<DataValueAttributes>() ==
192  b.value<DataValueAttributes>());
193  case DatasetBrushRole:
194  return (a.value<QBrush>() ==
195  b.value<QBrush>());
196  case DatasetPenRole:
197  return (a.value<QPen>() ==
198  b.value<QPen>());
200  // As of yet there is no ThreeDAttributes class,
201  // and the AbstractThreeDAttributes class is pure virtual,
202  // so we ignore this role for now.
203  // (khz, 04.04.2007)
204  /*
205  return (qVariantValue<ThreeDAttributes>( a ) ==
206  qVariantValue<ThreeDAttributes>( b ));
207  */
208  break;
209  case LineAttributesRole:
210  return (a.value<LineAttributes>() ==
211  b.value<LineAttributes>());
213  return (a.value<ThreeDLineAttributes>() ==
214  b.value<ThreeDLineAttributes>());
215  case BarAttributesRole:
216  return (a.value<BarAttributes>() ==
217  b.value<BarAttributes>());
219  return (a.value<StockBarAttributes>() ==
220  b.value<StockBarAttributes>());
222  return (a.value<ThreeDBarAttributes>() ==
223  b.value<ThreeDBarAttributes>());
224  case PieAttributesRole:
225  return (a.value<PieAttributes>() ==
226  b.value<PieAttributes>());
228  return (a.value<ThreeDPieAttributes>() ==
229  b.value<ThreeDPieAttributes>());
231  return (a.value<ValueTrackerAttributes>() ==
232  b.value<ValueTrackerAttributes>());
233  case DataHiddenRole:
234  return (a.value<bool>() ==
235  b.value<bool>());
236  default:
237  Q_ASSERT( false ); // all of our own roles need to be handled
238  break;
239  }
240  } else {
241  return (a == b);
242  }
243  return true;
244 }
245 
246 
247 QVariant AttributesModel::headerData( int section, Qt::Orientation orientation,
248  int role/* = Qt::DisplayRole */ ) const
249 {
250  if ( sourceModel() ) {
251  const QVariant sourceData = sourceModel()->headerData( section, orientation, role );
252  if ( sourceData.isValid() ) {
253  return sourceData;
254  }
255  }
256 
257  // the source model didn't have data set, let's use our stored values
258  const QMap< int, QMap< int, QVariant> >& map = orientation == Qt::Horizontal ?
259  d->horizontalHeaderDataMap : d->verticalHeaderDataMap;
260  QMap< int, QMap< int, QVariant > >::const_iterator mapIt = map.find( section );
261  if ( mapIt != map.constEnd() ) {
262  const QMap< int, QVariant >& dataMap = mapIt.value();
263  QMap< int, QVariant >::const_iterator dataMapIt = dataMap.find( role );
264  if ( dataMapIt != dataMap.constEnd() ) {
265  return dataMapIt.value();
266  }
267  }
268 
269  return defaultHeaderData( section, orientation, role );
270 }
271 
272 
273 QVariant AttributesModel::defaultHeaderData( int section, Qt::Orientation orientation, int role ) const
274 {
275  // Default values if nothing else matches
276 
277  const int dataset = section / d->dataDimension;
278 
279  switch ( role ) {
280  case Qt::DisplayRole:
281  //TODO for KDChart 3.0: return QString::number( dataset + 1 );
282  return QLatin1String( orientation == Qt::Vertical ? "Series " : "Item " ) + QString::number( dataset ) ;
284  return d->palette.getBrush( dataset );
286  // if no per model override was set, use the (possibly default) color set for the brush
287  if ( !modelData( role ).isValid() ) {
288  QBrush brush = headerData( section, orientation, DatasetBrushRole ).value< QBrush >();
289  return QPen( brush.color() );
290  }
291  default:
292  break;
293  }
294 
295  return QVariant();
296 }
297 
298 // Note: Our users NEED this method - even if
299 // we do not need it at drawing time!
300 // (khz, 2006-07-28)
301 QVariant AttributesModel::data( int role ) const
302 {
303  if ( isKnownAttributesRole( role ) ) {
304  // check if there is something set at global level
305  QVariant v = modelData( role );
306 
307  // else return the default setting, if any
308  if ( !v.isValid() )
309  v = defaultsForRole( role );
310  return v;
311  }
312  return QVariant();
313 }
314 
315 
316 // Note: Our users NEED this method - even if
317 // we do not need it at drawing time!
318 // (khz, 2006-07-28)
319 QVariant AttributesModel::data( int column, int role ) const
320 {
321  if ( isKnownAttributesRole( role ) ) {
322  // check if there is something set for the column (dataset)
323  QVariant v;
324  v = headerData( column, Qt::Horizontal, role );
325 
326  // check if there is something set at global level
327  if ( !v.isValid() )
328  v = data( role ); // includes automatic fallback to default
329  return v;
330  }
331  return QVariant();
332 }
333 
334 
335 QVariant AttributesModel::data( const QModelIndex& index, int role ) const
336 {
337  if ( index.isValid() ) {
338  Q_ASSERT( index.model() == this );
339  }
340  if ( !sourceModel() ) {
341  return QVariant();
342  }
343 
344  if ( index.isValid() ) {
345  const QVariant sourceData = sourceModel()->data( mapToSource( index ), role );
346  if ( sourceData.isValid() ) {
347  return sourceData;
348  }
349  }
350 
351  // check if we are storing a value for this role at this cell index
352  if ( d->dataMap.contains( index.column() ) ) {
353  const QMap< int, QMap< int, QVariant > >& colDataMap = d->dataMap[ index.column() ];
354  if ( colDataMap.contains( index.row() ) ) {
355  const QMap< int, QVariant >& dataMap = colDataMap[ index.row() ];
356  if ( dataMap.contains( role ) ) {
357  const QVariant v = dataMap[ role ];
358  if ( v.isValid() ) {
359  return v;
360  }
361  }
362  }
363  }
364  // check if there is something set for the column (dataset), or at global level
365  if ( index.isValid() ) {
366  return data( index.column(), role ); // includes automatic fallback to default
367  }
368 
369  return QVariant();
370 }
371 
372 
374 {
375  switch ( role ) {
376  // fallthrough intended
378  case DatasetBrushRole:
379  case DatasetPenRole:
381  case LineAttributesRole:
383  case BarAttributesRole:
386  case PieAttributesRole:
389  case DataHiddenRole:
390  return true;
391  default:
392  return false;
393  }
394 }
395 
396 QVariant AttributesModel::defaultsForRole( int role ) const
397 {
398  // returns default-constructed QVariant if not found
399  return d->defaultsMap.value( role );
400 }
401 
402 bool AttributesModel::setData ( const QModelIndex & index, const QVariant & value, int role )
403 {
404  if ( !isKnownAttributesRole( role ) ) {
405  return sourceModel()->setData( mapToSource(index), value, role );
406  } else {
407  QMap< int, QMap< int, QVariant> > &colDataMap = d->dataMap[ index.column() ];
408  QMap< int, QVariant > &dataMap = colDataMap[ index.row() ];
409  dataMap.insert( role, value );
410  emit attributesChanged( index, index );
411  return true;
412  }
413 }
414 
415 bool AttributesModel::resetData ( const QModelIndex & index, int role )
416 {
417  return setData( index, QVariant(), role );
418 }
419 
420 bool AttributesModel::setHeaderData ( int section, Qt::Orientation orientation,
421  const QVariant & value, int role )
422 {
423  if ( sourceModel() && headerData( section, orientation, role ) == value ) {
424  return true;
425  }
426 
427  if ( !isKnownAttributesRole( role ) ) {
428  return sourceModel()->setHeaderData( section, orientation, value, role );
429  } else {
430  QMap< int, QMap<int, QVariant > > &sectionDataMap
431  = orientation == Qt::Horizontal ? d->horizontalHeaderDataMap : d->verticalHeaderDataMap;
432 
433  QMap< int, QVariant > &dataMap = sectionDataMap[ section ];
434  dataMap.insert( role, value );
435  if ( sourceModel() ) {
436  int numRows = rowCount( QModelIndex() );
437  int numCols = columnCount( QModelIndex() );
438  if ( orientation == Qt::Horizontal && numRows > 0 )
439  emit attributesChanged( index( 0, section, QModelIndex() ),
440  index( numRows - 1, section, QModelIndex() ) );
441  else if ( orientation == Qt::Vertical && numCols > 0 )
442  emit attributesChanged( index( section, 0, QModelIndex() ),
443  index( section, numCols - 1, QModelIndex() ) );
444  emit headerDataChanged( orientation, section, section );
445 
446  // FIXME: This only makes sense for orientation == Qt::Horizontal,
447  // but what if orientation == Qt::Vertical?
448  if ( section != -1 && numRows > 0 )
449  emit dataChanged( index( 0, section, QModelIndex() ),
450  index( numRows - 1, section, QModelIndex() ) );
451  }
452  return true;
453  }
454 }
455 
456 bool AttributesModel::resetHeaderData ( int section, Qt::Orientation orientation, int role )
457 {
458  return setHeaderData ( section, orientation, QVariant(), role );
459 }
460 
462 {
463  if ( d->paletteType == type ) {
464  return;
465  }
466  d->paletteType = type;
467  switch ( type ) {
468  case PaletteTypeDefault:
469  d->palette = Palette::defaultPalette();
470  break;
471  case PaletteTypeSubdued:
472  d->palette = Palette::subduedPalette();
473  break;
474  case PaletteTypeRainbow:
475  d->palette = Palette::rainbowPalette();
476  break;
477  default:
478  qWarning( "Unknown palette type!" );
479  }
480 }
481 
483 {
484  return d->paletteType;
485 }
486 
487 bool KDChart::AttributesModel::setModelData( const QVariant value, int role )
488 {
489  d->modelDataMap.insert( role, value );
490  int numRows = rowCount( QModelIndex() );
491  int numCols = columnCount( QModelIndex() );
492  if ( sourceModel() && numRows > 0 && numCols > 0 ) {
493  emit attributesChanged( index( 0, 0, QModelIndex() ),
494  index( numRows - 1, numCols - 1, QModelIndex() ) );
495  beginResetModel();
496  endResetModel();
497  }
498  return true;
499 }
500 
501 QVariant KDChart::AttributesModel::modelData( int role ) const
502 {
503  return d->modelDataMap.value( role, QVariant() );
504 }
505 
506 int AttributesModel::rowCount( const QModelIndex& index ) const
507 {
508  if ( sourceModel() ) {
509  return sourceModel()->rowCount( mapToSource(index) );
510  } else {
511  return 0;
512  }
513 }
514 
515 int AttributesModel::columnCount( const QModelIndex& index ) const
516 {
517  if ( sourceModel() ) {
518  return sourceModel()->columnCount( mapToSource(index) );
519  } else {
520  return 0;
521  }
522 }
523 
524 void AttributesModel::setSourceModel( QAbstractItemModel* sourceModel )
525 {
526  if ( this->sourceModel() != 0 )
527  {
528  disconnect( this->sourceModel(), SIGNAL( dataChanged( const QModelIndex&, const QModelIndex&)),
529  this, SLOT( slotDataChanged( const QModelIndex&, const QModelIndex&)));
530  disconnect( this->sourceModel(), SIGNAL( rowsInserted( const QModelIndex&, int, int ) ),
531  this, SLOT( slotRowsInserted( const QModelIndex&, int, int ) ) );
532  disconnect( this->sourceModel(), SIGNAL( rowsRemoved( const QModelIndex&, int, int ) ),
533  this, SLOT( slotRowsRemoved( const QModelIndex&, int, int ) ) );
534  disconnect( this->sourceModel(), SIGNAL( rowsAboutToBeInserted( const QModelIndex&, int, int ) ),
535  this, SLOT( slotRowsAboutToBeInserted( const QModelIndex&, int, int ) ) );
536  disconnect( this->sourceModel(), SIGNAL( rowsAboutToBeRemoved( const QModelIndex&, int, int ) ),
537  this, SLOT( slotRowsAboutToBeRemoved( const QModelIndex&, int, int ) ) );
538  disconnect( this->sourceModel(), SIGNAL( columnsInserted( const QModelIndex&, int, int ) ),
539  this, SLOT( slotColumnsInserted( const QModelIndex&, int, int ) ) );
540  disconnect( this->sourceModel(), SIGNAL( columnsRemoved( const QModelIndex&, int, int ) ),
541  this, SLOT( slotColumnsRemoved( const QModelIndex&, int, int ) ) );
542  disconnect( this->sourceModel(), SIGNAL( columnsAboutToBeInserted( const QModelIndex&, int, int ) ),
543  this, SLOT( slotColumnsAboutToBeInserted( const QModelIndex&, int, int ) ) );
544  disconnect( this->sourceModel(), SIGNAL( columnsAboutToBeRemoved( const QModelIndex&, int, int ) ),
545  this, SLOT( slotColumnsAboutToBeRemoved( const QModelIndex&, int, int ) ) );
546  disconnect( this->sourceModel(), SIGNAL( modelReset() ),
547  this, SIGNAL( modelReset() ) );
548  disconnect( this->sourceModel(), SIGNAL( layoutChanged() ),
549  this, SIGNAL( layoutChanged() ) );
550  }
551  QAbstractProxyModel::setSourceModel( sourceModel );
552  if ( this->sourceModel() != NULL )
553  {
554  connect( this->sourceModel(), SIGNAL( dataChanged( const QModelIndex&, const QModelIndex&)),
555  this, SLOT( slotDataChanged( const QModelIndex&, const QModelIndex&)));
556  connect( this->sourceModel(), SIGNAL( rowsInserted( const QModelIndex&, int, int ) ),
557  this, SLOT( slotRowsInserted( const QModelIndex&, int, int ) ) );
558  connect( this->sourceModel(), SIGNAL( rowsRemoved( const QModelIndex&, int, int ) ),
559  this, SLOT( slotRowsRemoved( const QModelIndex&, int, int ) ) );
560  connect( this->sourceModel(), SIGNAL( rowsAboutToBeInserted( const QModelIndex&, int, int ) ),
561  this, SLOT( slotRowsAboutToBeInserted( const QModelIndex&, int, int ) ) );
562  connect( this->sourceModel(), SIGNAL( rowsAboutToBeRemoved( const QModelIndex&, int, int ) ),
563  this, SLOT( slotRowsAboutToBeRemoved( const QModelIndex&, int, int ) ) );
564  connect( this->sourceModel(), SIGNAL( columnsInserted( const QModelIndex&, int, int ) ),
565  this, SLOT( slotColumnsInserted( const QModelIndex&, int, int ) ) );
566  connect( this->sourceModel(), SIGNAL( columnsRemoved( const QModelIndex&, int, int ) ),
567  this, SLOT( slotColumnsRemoved( const QModelIndex&, int, int ) ) );
568  connect( this->sourceModel(), SIGNAL( columnsAboutToBeInserted( const QModelIndex&, int, int ) ),
569  this, SLOT( slotColumnsAboutToBeInserted( const QModelIndex&, int, int ) ) );
570  connect( this->sourceModel(), SIGNAL( columnsAboutToBeRemoved( const QModelIndex&, int, int ) ),
571  this, SLOT( slotColumnsAboutToBeRemoved( const QModelIndex&, int, int ) ) );
572  connect( this->sourceModel(), SIGNAL( modelReset() ),
573  this, SIGNAL( modelReset() ) );
574  connect( this->sourceModel(), SIGNAL( layoutChanged() ),
575  this, SIGNAL( layoutChanged() ) );
576  }
577 }
578 
579 void AttributesModel::slotRowsAboutToBeInserted( const QModelIndex& parent, int start, int end )
580 {
581  beginInsertRows( mapFromSource( parent ), start, end );
582 }
583 
584 void AttributesModel::slotColumnsAboutToBeInserted( const QModelIndex& parent, int start, int end )
585 {
586  beginInsertColumns( mapFromSource( parent ), start, end );
587 }
588 
589 void AttributesModel::slotRowsInserted( const QModelIndex& parent, int start, int end )
590 {
591  Q_UNUSED( parent );
592  Q_UNUSED( start );
593  Q_UNUSED( end );
594  endInsertRows();
595 }
596 
597 void AttributesModel::slotColumnsInserted( const QModelIndex& parent, int start, int end )
598 {
599  Q_UNUSED( parent );
600  Q_UNUSED( start );
601  Q_UNUSED( end );
602  endInsertColumns();
603 }
604 
605 void AttributesModel::slotRowsAboutToBeRemoved( const QModelIndex& parent, int start, int end )
606 {
607  beginRemoveRows( mapFromSource( parent ), start, end );
608 }
609 
610 void AttributesModel::slotColumnsAboutToBeRemoved( const QModelIndex& parent, int start, int end )
611 {
612  beginRemoveColumns( mapFromSource( parent ), start, end );
613 }
614 
615 void AttributesModel::slotRowsRemoved( const QModelIndex& parent, int start, int end )
616 {
617  Q_UNUSED( parent );
618  Q_UNUSED( start );
619  Q_UNUSED( end );
620  endRemoveRows();
621 }
622 
623 void AttributesModel::removeEntriesFromDataMap( int start, int end )
624 {
625  QMap< int, QMap< int, QMap< int, QVariant > > >::iterator it = d->dataMap.find( end );
626  // check that the element was found
627  if ( it != d->dataMap.end() ) {
628  ++it;
629  QVector< int > indexesToDel;
630  for ( int i = start; i < end && it != d->dataMap.end(); ++i ) {
631  d->dataMap[ i ] = it.value();
632  indexesToDel << it.key();
633  ++it;
634  }
635  if ( indexesToDel.isEmpty() ) {
636  for ( int i = start; i < end; ++i ) {
637  indexesToDel << i;
638  }
639  }
640  for ( int i = 0; i < indexesToDel.count(); ++i ) {
641  d->dataMap.remove( indexesToDel[ i ] );
642  }
643  }
644 }
645 
646 void AttributesModel::removeEntriesFromDirectionDataMaps( Qt::Orientation dir, int start, int end )
647 {
648  QMap<int, QMap<int, QVariant> > &sectionDataMap
649  = dir == Qt::Horizontal ? d->horizontalHeaderDataMap : d->verticalHeaderDataMap;
650  QMap<int, QMap<int, QVariant> >::iterator it = sectionDataMap.upperBound( end );
651  // check that the element was found
652  if ( it != sectionDataMap.end() )
653  {
654  QVector< int > indexesToDel;
655  for ( int i = start; i < end && it != sectionDataMap.end(); ++i )
656  {
657  sectionDataMap[ i ] = it.value();
658  indexesToDel << it.key();
659  ++it;
660  }
661  if ( indexesToDel.isEmpty() )
662  {
663  for ( int i = start; i < end; ++i )
664  {
665  indexesToDel << i;
666  }
667  }
668  for ( int i = 0; i < indexesToDel.count(); ++i )
669  {
670  sectionDataMap.remove( indexesToDel[ i ] );
671  }
672  }
673 }
674 
675 void AttributesModel::slotColumnsRemoved( const QModelIndex& parent, int start, int end )
676 {
677  Q_UNUSED( parent );
678  Q_UNUSED( start );
679  Q_UNUSED( end );
680  Q_ASSERT_X( sourceModel(), "removeColumn", "This should only be triggered if a valid source Model exists!" );
681  for ( int i = start; i <= end; ++i ) {
682  d->verticalHeaderDataMap.remove( start );
683  }
684  removeEntriesFromDataMap( start, end );
685  removeEntriesFromDirectionDataMaps( Qt::Horizontal, start, end );
686  removeEntriesFromDirectionDataMaps( Qt::Vertical, start, end );
687 
688  endRemoveColumns();
689 }
690 
691 void AttributesModel::slotDataChanged( const QModelIndex& topLeft, const QModelIndex& bottomRight )
692 {
693  emit dataChanged( mapFromSource( topLeft ), mapFromSource( bottomRight ) );
694 }
695 
696 void AttributesModel::setDefaultForRole( int role, const QVariant& value )
697 {
698  if ( value.isValid() ) {
699  d->defaultsMap.insert( role, value );
700  } else {
701  // erase the possibily existing value to not let the map grow:
702  QMap<int, QVariant>::iterator it = d->defaultsMap.find( role );
703  if ( it != d->defaultsMap.end() ) {
704  d->defaultsMap.erase( it );
705  }
706  }
707 
708  Q_ASSERT( defaultsForRole( role ).value<KDChart::DataValueAttributes>() == value.value<KDChart::DataValueAttributes>() );
709 }
710 
712 {
713  //### need to "reformat" or throw away internal data?
714  d->dataDimension = dimension;
715 }
716 
718 {
719  return d->dataDimension;
720 }

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
http://www.kdab.com/
http://www.kdab.com/products/kd-chart/