~ubuntu-branches/ubuntu/oneiric/koffice/oneiric-updates

« back to all changes in this revision

Viewing changes to kspread/StyleStorage.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* This file is part of the KDE project
 
2
   Copyright 2010 Marijn Kruisselbrink <m.kruisselbrink@student.tue.nl>
2
3
   Copyright 2006,2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
3
4
 
4
5
   This library is free software; you can redistribute it and/or
87
88
    }
88
89
    // not found, lookup in the tree
89
90
    QList<SharedSubStyle> subStyles = d->tree.contains(point);
 
91
 
90
92
    if (subStyles.isEmpty())
91
93
        return *styleManager()->defaultStyle();
92
94
    Style* style = new Style();
93
95
    (*style) = composeStyle(subStyles);
 
96
 
94
97
    // insert style into the cache
95
98
    d->cache.insert(point, style);
96
99
    d->cachedArea += QRect(point, point);
120
123
            // trim the rects
121
124
            pairs[i].first = pairs[i].first.intersected(rect);
122
125
        }
123
 
        result << pairs;
 
126
        // Always a default subStyle first, even if there are no pairs.
 
127
        result << qMakePair(QRectF(rect), SharedSubStyle()) << pairs;
124
128
    }
125
129
    return result;
126
130
}
211
215
//     kDebug(36006) <<"StyleStorage: inserting" << SubStyle::name(subStyle->type()) <<" into" << rect;
212
216
    // keep track of the used area
213
217
    const bool isDefault = subStyle->type() == Style::DefaultStyleKey;
214
 
    if (rect.top() == 1 && rect.bottom() == KS_colMax) {
 
218
    if (rect.top() == 1 && rect.bottom() >= KS_rowMax) {
215
219
        for (int i = rect.left(); i <= rect.right(); ++i) {
216
220
            if (isDefault)
217
221
                d->usedColumns.remove(i);
220
224
        }
221
225
        if (isDefault)
222
226
            d->usedArea -= rect;
223
 
    } else if (rect.left() == 1 && rect.right() == KS_rowMax) {
 
227
    } else if (rect.left() == 1 && rect.right() >= KS_colMax) {
224
228
        for (int i = rect.top(); i <= rect.bottom(); ++i) {
225
229
            if (isDefault)
226
230
                d->usedRows.remove(i);
268
272
    }
269
273
}
270
274
 
 
275
void StyleStorage::load(const QList<QPair<QRegion, Style> >& styles)
 
276
{
 
277
    QList<QPair<QRegion, SharedSubStyle> > subStyles;
 
278
 
 
279
    d->usedArea = QRegion();
 
280
    d->usedColumns.clear();
 
281
    d->usedRows.clear();
 
282
    d->cachedArea = QRegion();
 
283
    d->cache.clear();
 
284
    typedef QPair<QRegion, Style> StyleRegion;
 
285
    foreach (const StyleRegion& styleArea, styles) {
 
286
        const QRegion& reg = styleArea.first;
 
287
        const Style& style = styleArea.second;
 
288
        if (style.isEmpty()) continue;
 
289
 
 
290
        // update used areas
 
291
        QRect bound = reg.boundingRect();
 
292
        if ((bound.top() == 1 && bound.bottom() >= KS_rowMax) || (bound.left() == 1 && bound.right() >= KS_colMax)) {
 
293
            foreach (const QRect& rect, reg.rects()) {
 
294
                if (rect.top() == 1 && rect.bottom() >= KS_rowMax) {
 
295
                    for (int i = rect.left(); i <= rect.right(); ++i) {
 
296
                        d->usedColumns.insert(i, true);
 
297
                    }
 
298
                } else if (rect.left() == 1 && rect.right() >= KS_colMax) {
 
299
                    for (int i = rect.top(); i <= rect.bottom(); ++i) {
 
300
                        d->usedRows.insert(i, true);
 
301
                    }
 
302
                } else {
 
303
                    d->usedArea += rect;
 
304
                }
 
305
            }
 
306
        } else {
 
307
            d->usedArea += reg;
 
308
        }
 
309
 
 
310
        // find substyles
 
311
        foreach(const SharedSubStyle& subStyle, style.subStyles()) {
 
312
            bool foundShared = false;
 
313
            typedef const QList< SharedSubStyle> StoredSubStyleList;
 
314
            StoredSubStyleList& storedSubStyles(d->subStyles.value(subStyle->type()));
 
315
            StoredSubStyleList::ConstIterator end(storedSubStyles.end());
 
316
            for (StoredSubStyleList::ConstIterator it(storedSubStyles.begin()); it != end; ++it) {
 
317
                if (Style::compare(subStyle.data(), (*it).data())) {
 
318
        //             kDebug(36006) <<"[REUSING EXISTING SUBSTYLE]";
 
319
                    subStyles.append(qMakePair(reg, *it));
 
320
                    foundShared = true;
 
321
                    break;
 
322
                }
 
323
            }
 
324
            if (!foundShared) {
 
325
                // insert substyle and add to the used substyle list
 
326
                subStyles.append(qMakePair(reg, subStyle));
 
327
            }
 
328
        }
 
329
    }
 
330
    d->tree.load(subStyles);
 
331
}
 
332
 
271
333
QList< QPair<QRectF, SharedSubStyle> > StyleStorage::insertRows(int position, int number)
272
334
{
273
335
    const QRect invalidRect(1, position, KS_colMax, KS_rowMax);
292
354
        d->usedRows.remove(it.key());
293
355
    d->usedRows.unite(map);
294
356
    // process the tree
295
 
    QList< QPair<QRectF, SharedSubStyle> > undoData = d->tree.insertRows(position, number);
 
357
    QList< QPair<QRectF, SharedSubStyle> > undoData;
 
358
    undoData << qMakePair(QRectF(1, KS_rowMax - number + 1, KS_colMax, number), SharedSubStyle());
 
359
    undoData << d->tree.insertRows(position, number);
296
360
    return undoData;
297
361
}
298
362
 
320
384
        d->usedColumns.remove(it.key());
321
385
    d->usedColumns.unite(map);
322
386
    // process the tree
323
 
    QList< QPair<QRectF, SharedSubStyle> > undoData = d->tree.insertColumns(position, number);
 
387
    QList< QPair<QRectF, SharedSubStyle> > undoData;
 
388
    undoData << qMakePair(QRectF(KS_colMax - number + 1, 1, number, KS_rowMax), SharedSubStyle());
 
389
    undoData << d->tree.insertColumns(position, number);
324
390
    return undoData;
325
391
}
326
392
 
345
411
        d->usedRows.remove(it.key());
346
412
    d->usedRows.unite(map);
347
413
    // process the tree
348
 
    QList< QPair<QRectF, SharedSubStyle> > undoData = d->tree.removeRows(position, number);
 
414
    QList< QPair<QRectF, SharedSubStyle> > undoData;
 
415
    undoData << qMakePair(QRectF(1, position, KS_colMax, number), SharedSubStyle());
 
416
    undoData << d->tree.removeRows(position, number);
349
417
    return undoData;
350
418
}
351
419
 
370
438
        d->usedColumns.remove(it.key());
371
439
    d->usedColumns.unite(map);
372
440
    // process the tree
373
 
    QList< QPair<QRectF, SharedSubStyle> > undoData = d->tree.removeColumns(position, number);
 
441
    QList< QPair<QRectF, SharedSubStyle> > undoData;
 
442
    undoData << qMakePair(QRectF(position, 1, number, KS_rowMax), SharedSubStyle());
 
443
    undoData << d->tree.removeColumns(position, number);
374
444
    return undoData;
375
445
}
376
446
 
377
447
QList< QPair<QRectF, SharedSubStyle> > StyleStorage::insertShiftRight(const QRect& rect)
378
448
{
379
449
    const QRect invalidRect(rect.topLeft(), QPoint(KS_colMax, rect.bottom()));
380
 
    QList< QPair<QRectF, SharedSubStyle> > undoData = d->tree.insertShiftRight(rect);
 
450
    QList< QPair<QRectF, SharedSubStyle> > undoData;
 
451
    undoData << qMakePair(QRectF(rect), SharedSubStyle());
 
452
    undoData << d->tree.insertShiftRight(rect);
381
453
    regionChanged(invalidRect);
382
454
    // update the used area
383
455
    const QRegion usedArea = d->usedArea & invalidRect;
401
473
QList< QPair<QRectF, SharedSubStyle> > StyleStorage::insertShiftDown(const QRect& rect)
402
474
{
403
475
    const QRect invalidRect(rect.topLeft(), QPoint(rect.right(), KS_rowMax));
404
 
    QList< QPair<QRectF, SharedSubStyle> > undoData = d->tree.insertShiftDown(rect);
 
476
    QList< QPair<QRectF, SharedSubStyle> > undoData;
 
477
    undoData << qMakePair(QRectF(rect), SharedSubStyle());
 
478
    undoData << d->tree.insertShiftDown(rect);
405
479
    regionChanged(invalidRect);
406
480
    // update the used area
407
481
    const QRegion usedArea = d->usedArea & invalidRect;
425
499
QList< QPair<QRectF, SharedSubStyle> > StyleStorage::removeShiftLeft(const QRect& rect)
426
500
{
427
501
    const QRect invalidRect(rect.topLeft(), QPoint(KS_colMax, rect.bottom()));
428
 
    QList< QPair<QRectF, SharedSubStyle> > undoData = d->tree.removeShiftLeft(rect);
 
502
    QList< QPair<QRectF, SharedSubStyle> > undoData;
 
503
    undoData << qMakePair(QRectF(rect), SharedSubStyle());
 
504
    undoData << d->tree.removeShiftLeft(rect);
429
505
    regionChanged(invalidRect);
430
506
    // update the used area
431
507
    const QRegion usedArea = d->usedArea & QRect(rect.right() + 1, rect.top(), KS_colMax, rect.height());
444
520
QList< QPair<QRectF, SharedSubStyle> > StyleStorage::removeShiftUp(const QRect& rect)
445
521
{
446
522
    const QRect invalidRect(rect.topLeft(), QPoint(rect.right(), KS_rowMax));
447
 
    QList< QPair<QRectF, SharedSubStyle> > undoData = d->tree.removeShiftUp(rect);
 
523
    QList< QPair<QRectF, SharedSubStyle> > undoData;
 
524
    undoData << qMakePair(QRectF(rect), SharedSubStyle());
 
525
    undoData << d->tree.removeShiftUp(rect);
448
526
    regionChanged(invalidRect);
449
527
    // update the used area
450
528
    const QRegion usedArea = d->usedArea & QRect(rect.left(), rect.bottom() + 1, rect.width(), KS_rowMax);
577
655
            kDebug(36006) << "removing" << currentPair.second->debugData()
578
656
            << "at" << Region(currentPair.first.toRect()).name()
579
657
            << "used" << currentPair.second->ref << "times" << endl;
580
 
            d->tree.remove(currentPair.first.toRect(), currentPair.second);
 
658
            d->tree.remove(currentPair.first.toRect(), currentPair.second, currentZIndex);
581
659
#if 0
582
660
            kDebug(36006) << "StyleStorage: usage of" << currentPair.second->debugData() << " is" << currentPair.second->ref;
583
661
            // FIXME Stefan: The usage of substyles used once should be