MCPcopy Create free account
hub / github.com/KDE/labplot / testLinkSpreadsheetSaveLoad

Method testLinkSpreadsheetSaveLoad

tests/spreadsheet/SpreadsheetTest.cpp:3035–3097  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3033}
3034
3035void SpreadsheetTest::testLinkSpreadsheetSaveLoad() {
3036#ifdef __FreeBSD__
3037 return;
3038#endif
3039 QString savePath;
3040 {
3041 Project project;
3042 auto model = new AspectTreeModel(&project, this);
3043 ProjectExplorer pe; // Needed otherwise the state key is missing in the file and then no restorePointers will be called
3044 pe.setProject(&project);
3045 pe.setModel(model);
3046 auto* sheetData = new Spreadsheet(QStringLiteral("data"), false);
3047 project.addChild(sheetData);
3048 sheetData->setColumnCount(3);
3049 sheetData->setRowCount(10);
3050
3051 auto* sheetCalculations = new Spreadsheet(QStringLiteral("calculations"), false);
3052 project.addChild(sheetCalculations);
3053 sheetCalculations->setColumnCount(3);
3054 sheetCalculations->setRowCount(2);
3055
3056 SpreadsheetDock dock(nullptr);
3057 dock.setSpreadsheets({sheetCalculations});
3058
3059 QCOMPARE(dock.ui.cbLinkingEnabled->isChecked(), false);
3060 QCOMPARE(dock.ui.cbLinkedSpreadsheet->isVisible(), false);
3061 QCOMPARE(dock.ui.sbRowCount->isEnabled(), true);
3062 QCOMPARE(sheetCalculations->linking(), false);
3063
3064 Q_EMIT dock.ui.cbLinkingEnabled->toggled(true);
3065
3066 sheetCalculations->setLinkedSpreadsheet(sheetData);
3067
3068 QCOMPARE(sheetCalculations->linking(), true);
3069 QCOMPARE(sheetCalculations->linkedSpreadsheet(), sheetData);
3070 QCOMPARE(sheetCalculations->linkedSpreadsheetPath(), sheetData->path());
3071 QCOMPARE(sheetCalculations->rowCount(), 10);
3072
3073 SAVE_PROJECT("testLinkSpreadsheetSaveLoad");
3074 }
3075
3076 {
3077 Project project;
3078 QCOMPARE(project.load(savePath), true);
3079
3080 auto sheetData = project.child<Spreadsheet>(0);
3081 QVERIFY(sheetData);
3082 auto sheetCalculations = project.child<Spreadsheet>(1);
3083 QVERIFY(sheetCalculations);
3084
3085 QCOMPARE(sheetCalculations->linking(), true);
3086 QCOMPARE(sheetCalculations->linkedSpreadsheetPath(), sheetData->path());
3087 QCOMPARE(sheetCalculations->linkedSpreadsheet(), sheetData);
3088 QCOMPARE(sheetCalculations->rowCount(), 10);
3089
3090 sheetData->setRowCount(11); // Changing shall also update sheetCalculations also after loading
3091
3092 QCOMPARE(sheetCalculations->linking(), true);

Callers

nothing calls this directly

Calls 12

setLinkedSpreadsheetMethod · 0.80
linkedSpreadsheetPathMethod · 0.80
setProjectMethod · 0.45
setModelMethod · 0.45
addChildMethod · 0.45
setColumnCountMethod · 0.45
setRowCountMethod · 0.45
setSpreadsheetsMethod · 0.45
isVisibleMethod · 0.45
pathMethod · 0.45
rowCountMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected