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

« back to all changes in this revision

Viewing changes to kspread/part/Doc.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:
11
11
   Copyright 1999-2000 Simon Hausmann <hausmann@kde.org>
12
12
   Copyright 1999 David Faure <faure@kde.org>
13
13
   Copyright 1998-2000 Torben Weis <weis@kde.org>
14
 
 
 
14
   
15
15
   This library is free software; you can redistribute it and/or
16
16
   modify it under the terms of the GNU Library General Public
17
17
   License as published by the Free Software Foundation; either
30
30
 
31
31
// Local
32
32
#include "Doc.h"
 
33
#include "../DocBase_p.h"
33
34
 
34
35
#include <unistd.h>
35
36
#include <assert.h>
44
45
//Added by qt3to4:
45
46
#include <QList>
46
47
#include <QPainter>
 
48
#include <QGraphicsItem>
47
49
 
48
 
#include <kcompletion.h>
49
50
#include <kstandarddirs.h>
50
51
#include <kdebug.h>
51
52
#include <kconfig.h>
61
62
#include <KoOdfStylesReader.h>
62
63
#include <KoOdfReadStore.h>
63
64
#include <KoOdfWriteStore.h>
 
65
#include <KoResourceManager.h>
64
66
#include <KoShapeConfigFactoryBase.h>
65
67
#include <KoShapeFactoryBase.h>
66
68
#include <KoShapeManager.h>
71
73
#include <KoXmlWriter.h>
72
74
#include <KoZoomHandler.h>
73
75
#include <KoShapeSavingContext.h>
 
76
#include <KoUpdater.h>
 
77
#include <KoProgressUpdater.h>
74
78
 
75
79
#include "BindingManager.h"
76
80
#include "CalculationSettings.h"
77
81
#include "Canvas.h"
 
82
#include "CanvasItem.h"
78
83
#include "DependencyManager.h"
79
84
#include "Factory.h"
80
85
#include "Formula.h"
 
86
#include "Function.h"
81
87
#include "FunctionModuleRegistry.h"
82
 
#include "Functions.h"
 
88
#include "HeaderFooter.h"
83
89
#include "LoadingInfo.h"
84
90
#include "Localization.h"
85
91
#include "Map.h"
86
92
#include "NamedAreaManager.h"
 
93
#include "PrintSettings.h"
87
94
#include "RecalcManager.h"
88
 
#include "Selection.h"
89
95
#include "Sheet.h"
90
96
#include "SheetPrint.h"
91
 
#include "SheetView.h"
92
97
#include "StyleManager.h"
93
98
#include "Util.h"
94
99
#include "View.h"
95
100
#include "SheetAccessModel.h"
 
101
#include "BindingModel.h"
 
102
 
 
103
// D-Bus
 
104
#include "interfaces/MapAdaptor.h"
 
105
#include "interfaces/SheetAdaptor.h"
 
106
#include <QtDBus/QtDBus>
96
107
 
97
108
// chart shape
98
 
#include "kchart/shape/ChartShape.h"
 
109
#include "plugins/chartshape/ChartShape.h"
99
110
#include "chart/ChartDialog.h"
100
111
 
 
112
// ui
 
113
#include "ui/Selection.h"
 
114
#include "ui/SheetView.h"
 
115
 
101
116
using namespace std;
102
117
using namespace KSpread;
103
118
 
104
 
static const int CURRENT_SYNTAX_VERSION = 1;
105
 
// Make sure an appropriate DTD is available in www/koffice/DTD if changing this value
106
 
static const char * CURRENT_DTD_VERSION = "1.2";
107
 
 
108
 
typedef QMap<QString, QDomElement> SavedDocParts;
109
 
 
110
119
class Doc::Private
111
120
{
112
121
public:
114
123
    static QList<Doc*> s_docs;
115
124
    static int s_docId;
116
125
 
117
 
    // true if loading is in process, otherwise false.
118
 
    // This flag is used to avoid updates etc. during loading.
119
 
    bool isLoading;
120
 
 
121
 
    KCompletion listCompletion;
122
 
 
123
126
    // document properties
124
 
    int syntaxVersion;
125
 
    bool configLoadFromFile : 1;
 
127
    bool configLoadFromFile       : 1;
126
128
    QStringList spellListIgnoreAll;
127
129
    SavedDocParts savedDocParts;
128
130
    SheetAccessModel *sheetAccessModel;
 
131
    KoResourceManager *resourceManager;
129
132
};
130
133
 
 
134
// Make sure an appropriate DTD is available in www/koffice/DTD if changing this value
 
135
static const char * CURRENT_DTD_VERSION = "1.2";
 
136
 
131
137
/*****************************************************************************
132
138
 *
133
139
 * Doc
138
144
int Doc::Private::s_docId = 0;
139
145
 
140
146
Doc::Doc(QWidget *parentWidget, QObject* parent, bool singleViewMode)
141
 
        : KoDocument(parentWidget, parent, singleViewMode)
142
 
        , d(new Private)
 
147
        : DocBase(parentWidget, parent, singleViewMode)
 
148
        , dd(new Private)
143
149
{
144
 
    d->map = new Map(this, "Map");
145
 
 
146
 
    d->configLoadFromFile = false;
147
 
 
148
 
    documents().append(this);
149
 
 
150
 
    setComponentData(Factory::global(), false);
151
 
    setTemplateType("kspread_template");
152
 
 
153
 
    d->isLoading = false;
154
 
 
155
 
    // default document properties
156
 
    d->syntaxVersion = CURRENT_SYNTAX_VERSION;
157
 
 
158
 
    d->sheetAccessModel = new SheetAccessModel(d->map);
 
150
    connect(d->map, SIGNAL(sheetAdded(Sheet*)), this, SLOT(sheetAdded(Sheet*)));
 
151
    new MapAdaptor(d->map);
 
152
    QDBusConnection::sessionBus().registerObject('/' + objectName() + '/' + d->map->objectName(), d->map);
 
153
 
159
154
 
160
155
    // Init chart shape factory with KSpread's specific configuration panels.
161
156
    KoShapeFactoryBase *chartShape = KoShapeRegistry::instance()->value(ChartShapeId);
162
157
    if (chartShape) {
163
 
        QList<KoShapeConfigFactoryBase*> panels = ChartDialog::panels(this);
 
158
        QList<KoShapeConfigFactoryBase*> panels = ChartDialog::panels(d->map);
164
159
        chartShape->setOptionPanels(panels);
165
160
    }
166
161
 
 
162
    connect(d->map, SIGNAL(commandAdded(QUndoCommand *)),
 
163
            this, SLOT(addCommand(QUndoCommand *)));
 
164
 
 
165
    setComponentData(Factory::global(), false);
 
166
    setTemplateType("kspread_template");
 
167
 
167
168
    // Load the function modules.
168
 
    FunctionModuleRegistry::instance();
 
169
    FunctionModuleRegistry::instance()->loadFunctionModules();
169
170
}
170
171
 
171
172
Doc::~Doc()
174
175
    if (isReadWrite())
175
176
        saveConfig();
176
177
 
177
 
    delete d->map;
178
 
    delete d->sheetAccessModel;
179
 
    delete d;
180
 
}
181
 
 
182
 
QList<Doc*> Doc::documents()
183
 
{
184
 
    return Private::s_docs;
185
 
}
186
 
 
187
 
void Doc::setReadWrite(bool readwrite)
188
 
{
189
 
    map()->setReadWrite(readwrite);
190
 
    KoDocument::setReadWrite(readwrite);
 
178
    delete dd;
191
179
}
192
180
 
193
181
void Doc::openTemplate(const KUrl& url)
213
201
    KoDocument::initEmpty();
214
202
}
215
203
 
216
 
Map *Doc::map() const
217
 
{
218
 
    return d->map;
219
 
}
220
 
 
221
204
void Doc::saveConfig()
222
205
{
223
206
    if (isEmbedded() || !isReadWrite())
224
207
        return;
225
208
    KSharedConfigPtr config = Factory::global().config();
226
 
#ifdef KSPREAD_DOC_ZOOM
227
 
    config->group("Parameters").writeEntry("Zoom", zoomInPercent());
228
 
#endif // KSPREAD_DOC_ZOOM
229
209
}
230
210
 
231
211
void Doc::initConfig()
234
214
 
235
215
    const int page = config->group("KSpread Page Layout").readEntry("Default unit page", 0);
236
216
    setUnit(KoUnit((KoUnit::Unit) page));
237
 
 
238
 
#if 0 // UNDOREDOLIMIT
239
 
    const int undo = config->group("Misc").readEntry("UndoRedo", 30);
240
 
    setUndoRedoLimit(undo);
241
 
#endif
242
 
 
243
 
#ifdef KSPREAD_DOC_ZOOM
244
 
    const int zoom = config->group("Parameters").readEntry("Zoom", 100);
245
 
    setZoomAndResolution(zoom, KoGlobal::dpiX(), KoGlobal::dpiY());
246
 
#endif // KSPREAD_DOC_ZOOM
247
 
}
248
 
 
249
 
int Doc::syntaxVersion() const
250
 
{
251
 
    return d->syntaxVersion;
252
 
}
253
 
 
254
 
bool Doc::isLoading() const
255
 
{
256
 
    // The KoDocument state is necessary to avoid damages while importing a file (through a filter).
257
 
    return d->isLoading || KoDocument::isLoading();
258
 
}
259
 
 
260
 
KCompletion& Doc::completion()
261
 
{
262
 
    return d->listCompletion;
263
217
}
264
218
 
265
219
KoView* Doc::createViewInstance(QWidget* parent)
267
221
    return new View(parent, this);
268
222
}
269
223
 
 
224
QGraphicsItem *Doc::createCanvasItem()
 
225
{
 
226
    return new CanvasItem(this);
 
227
}
 
228
 
270
229
bool Doc::saveChildren(KoStore* _store)
271
230
{
272
231
    return map()->saveChildren(_store);
318
277
    }
319
278
 
320
279
    QDomElement e = map()->save(doc);
 
280
    if (!views().isEmpty()) { // no view if embedded document
 
281
        // Save visual info for the first view, such as active sheet and active cell
 
282
        // It looks like a hack, but reopening a document creates only one view anyway (David)
 
283
        View *const view = static_cast<View*>(views().first());
 
284
        Canvas *const canvas = view->canvasWidget();
 
285
        e.setAttribute("activeTable",  canvas->activeSheet()->sheetName());
 
286
        e.setAttribute("markerColumn", view->selection()->marker().x());
 
287
        e.setAttribute("markerRow",    view->selection()->marker().y());
 
288
        e.setAttribute("xOffset",      canvas->xOffset());
 
289
        e.setAttribute("yOffset",      canvas->yOffset());
 
290
    }
321
291
    spread.appendChild(e);
322
292
 
323
293
    setModified(false);
330
300
    return map()->loadChildren(_store);
331
301
}
332
302
 
333
 
bool Doc::saveOdf(SavingContext &documentContext)
334
 
{
335
 
    ElapsedTime et("OpenDocument Saving", ElapsedTime::PrintOnlyTime);
336
 
    return saveOdfHelper(documentContext, SaveAll);
337
 
}
338
 
 
339
 
bool Doc::saveOdfHelper(SavingContext & documentContext, SaveFlag saveFlag,
340
 
                        QString* /*plainText*/)
341
 
{
342
 
    Q_UNUSED(saveFlag);
343
 
    KoStore * store = documentContext.odfStore.store();
344
 
    KoXmlWriter * manifestWriter = documentContext.odfStore.manifestWriter();
345
 
 
346
 
    /* don't pull focus away from the editor if this is just a background
347
 
       autosave */
348
 
    if (!isAutosaving()) {
349
 
        foreach(KoView* view, views())
350
 
        static_cast<View *>(view)->selection()->emitCloseEditor(true);
351
 
    }
352
 
 
353
 
    KoStoreDevice dev(store);
354
 
    KoGenStyles mainStyles;//for compile
355
 
 
356
 
    KoXmlWriter* contentWriter = documentContext.odfStore.contentWriter();
357
 
 
358
 
    KoXmlWriter* bodyWriter = documentContext.odfStore.bodyWriter();
359
 
    KoShapeSavingContext savingContext(*bodyWriter, mainStyles, documentContext.embeddedSaver);
360
 
 
361
 
    //todo fixme just add a element for testing saving content.xml
362
 
    bodyWriter->startElement("office:body");
363
 
    bodyWriter->startElement("office:spreadsheet");
364
 
 
365
 
    // Saving the map.
366
 
    map()->saveOdf(*contentWriter, savingContext);
367
 
 
368
 
    bodyWriter->endElement(); ////office:spreadsheet
369
 
    bodyWriter->endElement(); ////office:body
370
 
 
371
 
    // Done with writing out the contents to the tempfile, we can now write out the automatic styles
372
 
    mainStyles.saveOdfStyles(KoGenStyles::DocumentAutomaticStyles, contentWriter);
373
 
 
374
 
    documentContext.odfStore.closeContentWriter();
375
 
 
376
 
    //add manifest line for content.xml
377
 
    manifestWriter->addManifestEntry("content.xml",  "text/xml");
378
 
 
379
 
    mainStyles.saveOdfStylesDotXml(store, manifestWriter);
380
 
 
381
 
    if (!store->open("settings.xml"))
382
 
        return false;
383
 
 
384
 
    KoXmlWriter* settingsWriter = KoOdfWriteStore::createOasisXmlWriter(&dev, "office:document-settings");
385
 
    settingsWriter->startElement("office:settings");
386
 
    settingsWriter->startElement("config:config-item-set");
387
 
    settingsWriter->addAttribute("config:name", "view-settings");
388
 
 
389
 
    saveUnitOdf(settingsWriter);
390
 
 
391
 
    saveOdfSettings(*settingsWriter);
392
 
 
393
 
    settingsWriter->endElement(); // config:config-item-set
394
 
 
395
 
    settingsWriter->startElement("config:config-item-set");
396
 
    settingsWriter->addAttribute("config:name", "configuration-settings");
397
 
    settingsWriter->addConfigItem("SpellCheckerIgnoreList", d->spellListIgnoreAll.join(","));
398
 
    settingsWriter->endElement(); // config:config-item-set
399
 
    settingsWriter->endElement(); // office:settings
400
 
    settingsWriter->endElement(); // Root:element
401
 
    settingsWriter->endDocument();
402
 
    delete settingsWriter;
403
 
 
404
 
    if (!store->close())
405
 
        return false;
406
 
 
407
 
    if (!savingContext.saveDataCenter(store, manifestWriter)) {
408
 
        return false;
409
 
    }
410
 
 
411
 
    manifestWriter->addManifestEntry("settings.xml", "text/xml");
412
 
 
413
 
    setModified(false);
414
 
 
415
 
    return true;
416
 
}
417
 
 
418
 
void Doc::loadOdfSettings(const KoXmlDocument&settingsDoc)
419
 
{
420
 
    KoOasisSettings settings(settingsDoc);
421
 
    KoOasisSettings::Items viewSettings = settings.itemSet("view-settings");
422
 
    if (!viewSettings.isNull()) {
423
 
        setUnit(KoUnit::unit(viewSettings.parseConfigItemString("unit")));
424
 
    }
425
 
    map()->loadOdfSettings(settings);
426
 
    loadOdfIgnoreList(settings);
427
 
}
428
 
 
429
 
void Doc::saveOdfSettings(KoXmlWriter &settingsWriter)
430
 
{
431
 
    settingsWriter.startElement("config:config-item-map-indexed");
432
 
    settingsWriter.addAttribute("config:name", "Views");
433
 
    settingsWriter.startElement("config:config-item-map-entry");
434
 
    map()->saveOdfSettings(settingsWriter);
435
 
    settingsWriter.endElement();
436
 
    settingsWriter.endElement();
437
 
}
438
 
 
439
 
 
440
 
void Doc::loadOdfIgnoreList(const KoOasisSettings& settings)
441
 
{
442
 
    KoOasisSettings::Items configurationSettings = settings.itemSet("configuration-settings");
443
 
    if (!configurationSettings.isNull()) {
444
 
        const QString ignorelist = configurationSettings.parseConfigItemString("SpellCheckerIgnoreList");
445
 
        //kDebug()<<" ignorelist :"<<ignorelist;
446
 
        d->spellListIgnoreAll = ignorelist.split(',', QString::SkipEmptyParts);
447
 
    }
448
 
}
449
 
 
450
 
 
451
 
bool Doc::loadOdf(KoOdfReadStore & odfStore)
452
 
{
453
 
    QTime dt;
454
 
    dt.start();
455
 
 
456
 
    emit sigProgress(0);
457
 
    d->isLoading = true;
458
 
    d->spellListIgnoreAll.clear();
459
 
 
460
 
    KoXmlElement content = odfStore.contentDoc().documentElement();
461
 
    KoXmlElement realBody(KoXml::namedItemNS(content, KoXmlNS::office, "body"));
462
 
    if (realBody.isNull()) {
463
 
        setErrorMessage(i18n("Invalid OASIS OpenDocument file. No office:body tag found."));
464
 
        map()->deleteLoadingInfo();
465
 
        return false;
466
 
    }
467
 
    KoXmlElement body = KoXml::namedItemNS(realBody, KoXmlNS::office, "spreadsheet");
468
 
 
469
 
    if (body.isNull()) {
470
 
        kError(32001) << "No office:spreadsheet found!" << endl;
471
 
        KoXmlElement childElem;
472
 
        QString localName;
473
 
        forEachElement(childElem, realBody) {
474
 
            localName = childElem.localName();
475
 
        }
476
 
        if (localName.isEmpty())
477
 
            setErrorMessage(i18n("Invalid OASIS OpenDocument file. No tag found inside office:body."));
478
 
        else
479
 
            setErrorMessage(i18n("This document is not a spreadsheet, but %1. Please try opening it with the appropriate application." , KoDocument::tagNameToDocumentType(localName)));
480
 
        map()->deleteLoadingInfo();
481
 
        return false;
482
 
    }
483
 
 
484
 
    KoOdfLoadingContext context(odfStore.styles(), odfStore.store());
485
 
 
486
 
    // TODO check versions and mimetypes etc.
487
 
 
488
 
    // all <sheet:sheet> goes to workbook
489
 
    if (!map()->loadOdf(body, context)) {
490
 
        d->isLoading = false;
491
 
        map()->deleteLoadingInfo();
492
 
        return false;
493
 
    }
494
 
 
495
 
    if (!odfStore.settingsDoc().isNull()) {
496
 
        loadOdfSettings(odfStore.settingsDoc());
497
 
    }
498
 
    initConfig();
499
 
    emit sigProgress(-1);
500
 
 
501
 
    //display loading time
502
 
    kDebug(36001) << "Loading took" << (float)(dt.elapsed()) / 1000.0 << " seconds";
503
 
 
504
 
    return true;
505
 
}
506
303
 
507
304
bool Doc::loadXML(const KoXmlDocument& doc, KoStore*)
508
305
{
509
 
    QTime dt;
510
 
    dt.start();
 
306
    QPointer<KoUpdater> updater;
 
307
    if (progressUpdater()) {
 
308
        updater = progressUpdater()->startSubtask(1, "KSpread::Doc::loadXML");
 
309
        updater->setProgress(0);
 
310
    }
511
311
 
512
 
    emit sigProgress(0);
513
 
    d->isLoading = true;
514
312
    d->spellListIgnoreAll.clear();
515
313
    // <spreadsheet>
516
314
    KoXmlElement spread = doc.documentElement();
517
315
 
518
316
    if (spread.attribute("mime") != "application/x-kspread" && spread.attribute("mime") != "application/vnd.kde.kspread") {
519
 
        d->isLoading = false;
520
317
        setErrorMessage(i18n("Invalid document. Expected mimetype application/x-kspread or application/vnd.kde.kspread, got %1" , spread.attribute("mime")));
521
318
        return false;
522
319
    }
523
320
 
524
321
    bool ok = false;
525
322
    int version = spread.attribute("syntaxVersion").toInt(&ok);
526
 
    d->syntaxVersion = ok ? version : 0;
527
 
    if (d->syntaxVersion > CURRENT_SYNTAX_VERSION) {
 
323
    map()->setSyntaxVersion(ok ? version : 0);
 
324
    if (map()->syntaxVersion() > CURRENT_SYNTAX_VERSION) {
528
325
        int ret = KMessageBox::warningContinueCancel(
529
326
                      0, i18n("This document was created with a newer version of KSpread (syntax version: %1)\n"
530
 
                              "When you open it with this version of KSpread, some information may be lost.", d->syntaxVersion),
 
327
                              "When you open it with this version of KSpread, some information may be lost.", map()->syntaxVersion()),
531
328
                      i18n("File Format Mismatch"), KStandardGuiItem::cont());
532
329
        if (ret == KMessageBox::Cancel) {
533
330
            setErrorMessage("USER_CANCELED");
540
337
    if (!loc.isNull())
541
338
        static_cast<Localization*>(map()->calculationSettings()->locale())->load(loc);
542
339
 
543
 
    emit sigProgress(5);
 
340
    if (updater) updater->setProgress(5);
544
341
 
545
342
    KoXmlElement defaults = spread.namedItem("defaults").toElement();
546
343
    if (!defaults.isNull()) {
570
367
        }
571
368
    }
572
369
 
573
 
    emit sigProgress(40);
 
370
    if (updater) updater->setProgress(40);
574
371
    // In case of reload (e.g. from konqueror)
575
372
    qDeleteAll(map()->sheetList());
576
373
    map()->sheetList().clear();
579
376
    if (!styles.isNull()) {
580
377
        if (!map()->styleManager()->loadXML(styles)) {
581
378
            setErrorMessage(i18n("Styles cannot be loaded."));
582
 
            d->isLoading = false;
583
379
            return false;
584
380
        }
585
381
    }
588
384
    KoXmlElement mymap = spread.namedItem("map").toElement();
589
385
    if (mymap.isNull()) {
590
386
        setErrorMessage(i18n("Invalid document. No map tag."));
591
 
        d->isLoading = false;
592
387
        return false;
593
388
    }
594
389
    if (!map()->loadXML(mymap)) {
595
 
        d->isLoading = false;
596
390
        return false;
597
391
    }
598
392
 
602
396
        map()->namedAreaManager()->loadXML(areaname);
603
397
 
604
398
    //Backwards compatibility with older versions for paper layout
605
 
    if (d->syntaxVersion < 1) {
 
399
    if (map()->syntaxVersion() < 1) {
606
400
        KoXmlElement paper = spread.namedItem("paper").toElement();
607
401
        if (!paper.isNull()) {
608
402
            loadPaper(paper);
609
403
        }
610
404
    }
611
405
 
612
 
    emit sigProgress(85);
 
406
    if (updater) updater->setProgress(85);
613
407
 
614
408
    KoXmlElement element(spread.firstChild().toElement());
615
409
    while (!element.isNull()) {
625
419
        element = element.nextSibling().toElement();
626
420
    }
627
421
 
628
 
    emit sigProgress(90);
 
422
    if (updater) updater->setProgress(90);
629
423
    initConfig();
630
 
    emit sigProgress(-1);
631
 
 
632
 
    kDebug(36001) << "Loading took" << (float)(dt.elapsed()) / 1000.0 << " seconds";
633
 
 
634
 
    emit sig_refreshView();
 
424
    if (updater) updater->setProgress(100);
635
425
 
636
426
    return true;
637
427
}
694
484
    fright  = fright.replace("<table>", "<sheet>");
695
485
 
696
486
    foreach(Sheet* sheet, map()->sheetList()) {
697
 
        sheet->print()->setHeadFootLine(hleft, hcenter, hright,
698
 
                                        fleft, fcenter, fright);
 
487
        sheet->print()->headerFooter()->setHeadFootLine(hleft, hcenter, hright,
 
488
                fleft, fcenter, fright);
699
489
    }
700
490
}
701
491
 
703
493
{
704
494
    kDebug(36001) << "------------------------ COMPLETING --------------------";
705
495
 
706
 
    d->isLoading = false;
707
 
 
708
 
    foreach(KoView* view, views())
709
 
    static_cast<View *>(view)->initialPosition();
 
496
    setModified(false);
 
497
    bool ok = map()->completeLoading(store);
710
498
 
711
499
    kDebug(36001) << "------------------------ COMPLETION DONE --------------------";
712
 
 
713
 
    setModified(false);
714
 
    bool ok = map()->completeLoading(store);
715
500
    return ok;
716
501
}
717
502
 
736
521
    return d->spellListIgnoreAll;
737
522
}
738
523
 
739
 
void Doc::newZoomAndResolution(bool updateViews, bool /*forPrint*/)
740
 
{
741
 
    /*    layout();
742
 
        updateAllFrames();*/
743
 
    if (updateViews) {
744
 
        emit sig_refreshView();
745
 
    }
746
 
}
747
 
 
748
524
void Doc::paintContent(QPainter& painter, const QRect& rect)
749
525
{
750
 
    paintContent(painter, rect, map()->sheet(0), false);
751
 
}
752
 
 
753
 
void Doc::paintContent(QPainter& painter, const QRect& rect, Sheet* sheet, bool drawCursor)
754
 
{
755
 
    Q_UNUSED(drawCursor);
756
 
 
757
 
    QPixmap thumbnail = sheet->generateThumbnail(rect.size());
758
 
    painter.drawPixmap(rect, thumbnail);
759
 
}
760
 
 
761
 
void Doc::paintUpdates()
762
 
{
763
 
    foreach(KoView* view, views()) {
764
 
        static_cast<View *>(view)->paintUpdates();
765
 
    }
766
 
}
767
 
 
768
 
void Doc::paintRegion(QPainter &painter, const QRectF &viewRegion,
769
 
                      View* view, const QRect &cellRegion, const Sheet* sheet)
770
 
{
771
 
    // cellRegion has cell coordinates (col,row) while viewRegion has
772
 
    // world coordinates.  cellRegion is the cells to update and
773
 
    // viewRegion is the area actually onscreen.
774
 
 
775
 
    if (cellRegion.left() <= 0 || cellRegion.top() <= 0)
 
526
    paintContent(painter, rect, 0);
 
527
}
 
528
 
 
529
void Doc::paintContent(QPainter& painter, const QRect& rect, Sheet* _sheet)
 
530
{
 
531
    if (rect.isEmpty()) {
776
532
        return;
777
 
 
778
 
    const QRectF viewRegionF(viewRegion.left(), viewRegion.right(), viewRegion.width(), viewRegion.height());
779
 
 
780
 
    // Get the world coordinates of the upper left corner of the
781
 
    // cellRegion The view is 0, when cellRegion is called from
782
 
    // paintContent, which itself is only called, when we should paint
783
 
    // the output for INACTIVE embedded view.  If inactive embedded,
784
 
    // then there is no view and we alwas start at top/left, so the
785
 
    // offset is 0.
786
 
    //
787
 
    QPointF topLeft;
788
 
    if (view == 0)   //Most propably we are embedded and inactive, so no offset
789
 
        topLeft = QPointF(sheet->columnPosition(cellRegion.left()),
790
 
                          sheet->rowPosition(cellRegion.top()));
791
 
    else
792
 
        topLeft = QPointF(sheet->columnPosition(cellRegion.left()) - view->canvasWidget()->xOffset(),
793
 
                          sheet->rowPosition(cellRegion.top()) - view->canvasWidget()->yOffset());
794
 
 
795
 
    SheetView sheetView(sheet);   // FIXME Stefan: make member, otherwise cache lost
796
 
    if (view) {
797
 
        sheetView.setPaintDevice(view->canvasWidget());
798
 
        sheetView.setViewConverter(view->zoomHandler());
799
533
    }
800
 
    sheetView.setPaintCellRange(cellRegion);
801
 
    sheetView.paintCells(view ? view->canvasWidget() : 0, painter, viewRegionF, topLeft);
802
 
}
803
 
 
804
 
void Doc::addStringCompletion(const QString &stringCompletion)
805
 
{
806
 
    if (d->listCompletion.items().contains(stringCompletion) == 0)
807
 
        d->listCompletion.addItem(stringCompletion);
808
 
}
809
 
 
810
 
void Doc::refreshInterface()
811
 
{
812
 
    emit sig_refreshView();
 
534
    Sheet *const sheet = _sheet ? _sheet : d->map->sheet(0);
 
535
 
 
536
    const KoPageLayout pageLayout = sheet->printSettings()->pageLayout();
 
537
    QPixmap thumbnail(pageLayout.width, pageLayout.height);
 
538
    thumbnail.fill(Qt::white);
 
539
 
 
540
    SheetView sheetView(sheet);
 
541
 
 
542
    const qreal zoom = sheet->printSettings()->zoom();
 
543
    KoZoomHandler zoomHandler;
 
544
    zoomHandler.setZoom(zoom);
 
545
    sheetView.setViewConverter(&zoomHandler);
 
546
 
 
547
    sheetView.setPaintCellRange(sheet->print()->cellRange(1)); // first page
 
548
 
 
549
    QPainter pixmapPainter(&thumbnail);
 
550
    pixmapPainter.setClipRect(QRect(QPoint(0, 0), thumbnail.size()));
 
551
    sheetView.paintCells(pixmapPainter, QRect(0, 0, pageLayout.width, pageLayout.height), QPointF(0,0));
 
552
 
 
553
    // The pixmap gets scaled to fit the rectangle.
 
554
    painter.drawPixmap(rect & QRect(0, 0, 100, 100), thumbnail);
 
555
}
 
556
 
 
557
void Doc::updateAllViews()
 
558
{
 
559
    emit updateView();
813
560
}
814
561
 
815
562
void Doc::updateBorderButton()
846
593
    return d->configLoadFromFile;
847
594
}
848
595
 
849
 
void Doc::repaint(const QRectF& rect)
850
 
{
851
 
    QRectF r;
852
 
    foreach(KoView* koview, views()) {
853
 
        const View* view = static_cast<View*>(koview);
854
 
        Canvas* canvas = view->canvasWidget();
855
 
 
856
 
        r = view->zoomHandler()->documentToView(rect);
857
 
        r.translate(-canvas->xOffset() * view->zoomHandler()->zoomedResolutionX(),
858
 
                    -canvas->yOffset() * view->zoomHandler()->zoomedResolutionY());
859
 
        canvas->update(r.toRect());
860
 
    }
861
 
}
862
 
 
863
 
SheetAccessModel *Doc::sheetAccessModel() const
864
 
{
865
 
    return d->sheetAccessModel;
866
 
}
867
 
 
868
 
#if 0 // UNDOREDOLIMIT
869
 
int Doc::undoRedoLimit() const
870
 
{
871
 
    return d->commandHistory->undoLimit();
872
 
}
873
 
 
874
 
void Doc::setUndoRedoLimit(int val)
875
 
{
876
 
    d->commandHistory->setUndoLimit(val);
877
 
    d->commandHistory->setRedoLimit(val);
878
 
}
879
 
#endif
 
596
void Doc::sheetAdded(Sheet* sheet)
 
597
{
 
598
    new SheetAdaptor(sheet);
 
599
    QString dbusPath('/' + sheet->map()->objectName() + '/' + objectName());
 
600
    if (sheet->parent()) {
 
601
        dbusPath.prepend('/' + sheet->parent()->objectName());
 
602
    }
 
603
    QDBusConnection::sessionBus().registerObject(dbusPath, sheet);
 
604
 
 
605
}
 
606
 
 
607
void Doc::saveOdfViewSettings(KoXmlWriter& settingsWriter)
 
608
{
 
609
    if (!views().isEmpty()) { // no view if embedded document
 
610
        // Save visual info for the first view, such as active sheet and active cell
 
611
        // It looks like a hack, but reopening a document creates only one view anyway (David)
 
612
        View *const view = static_cast<View*>(views().first());
 
613
        // save current sheet selection before to save marker, otherwise current pos is not saved
 
614
        view->saveCurrentSheetSelection();
 
615
        //<config:config-item config:name="ActiveTable" config:type="string">Feuille1</config:config-item>
 
616
        if (Sheet *sheet = view->activeSheet()) {
 
617
            settingsWriter.addConfigItem("ActiveTable", sheet->sheetName());
 
618
        }
 
619
    }
 
620
}
 
621
 
 
622
void Doc::saveOdfViewSheetSettings(Sheet *sheet, KoXmlWriter &settingsWriter)
 
623
{
 
624
    if (!views().isEmpty()) {
 
625
        View *const view = static_cast<View*>(views().first());
 
626
        QPoint marker = view->markerFromSheet(sheet);
 
627
        QPointF offset = view->offsetFromSheet(sheet);
 
628
        settingsWriter.addConfigItem("CursorPositionX", marker.x() - 1);
 
629
        settingsWriter.addConfigItem("CursorPositionY", marker.y() - 1);
 
630
        settingsWriter.addConfigItem("xOffset", offset.x());
 
631
        settingsWriter.addConfigItem("yOffset", offset.y());
 
632
    }
 
633
}
 
634
 
 
635
bool Doc::saveOdfHelper(SavingContext &documentContext, SaveFlag saveFlag, QString *plainText)
 
636
{
 
637
    /* don't pull focus away from the editor if this is just a background
 
638
       autosave */
 
639
    if (!isAutosaving()) {
 
640
        foreach(KoView* view, views())
 
641
            static_cast<View *>(view)->selection()->emitCloseEditor(true);
 
642
    }
 
643
 
 
644
    return DocBase::saveOdfHelper(documentContext, saveFlag, plainText);
 
645
}
880
646
 
881
647
#include "Doc.moc"
882