Skip to content

Commit ff86f23

Browse files
committed
Fix GitHub Issue #249: Option to include grid on export
- Grid will be exported if set visible - Works for both PNG and SVG exports
1 parent 1d9a495 commit ff86f23

File tree

5 files changed

+43
-6
lines changed

5 files changed

+43
-6
lines changed

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ Release date:
55

66
New features:
77

8+
* Fix GitHub Issue #249: Option to include grid on export
9+
- Grid will be exported if set visible
10+
- Works for both PNG and SVG exports
11+
812
* Fix GitHub Issue #251: Feature request: child has same colors as parent
913
- Change "Copy on Drag" behavior so that only the style will be copied
1014

src/application_service.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "single_instance_container.hpp"
2828

2929
#include "core/progress_manager.hpp"
30+
#include "core/settings.hpp"
3031
#include "core/settings_proxy.hpp"
3132
#include "core/shadow_effect_params.hpp"
3233

@@ -317,14 +318,36 @@ void ApplicationService::enableRedo(bool enable)
317318
m_mainWindow->enableRedo(enable);
318319
}
319320

321+
ApplicationService::GridLineVector ApplicationService::addGridForExport()
322+
{
323+
GridLineVector addedLineItems;
324+
if (Settings::V1::loadGridVisibleState()) {
325+
const auto gridLines = m_editorView->grid().calculateLines(m_editorScene->sceneRect());
326+
const auto gridColor = SIC::instance().applicationService()->mindMapData()->gridColor();
327+
for (auto && gridLine : gridLines) {
328+
addedLineItems.push_back(m_editorScene->addLine(gridLine, gridColor));
329+
}
330+
}
331+
return addedLineItems;
332+
}
333+
334+
void ApplicationService::removeLineItems(const GridLineVector & lines)
335+
{
336+
for (auto && line : lines) {
337+
m_editorScene->removeItem(line);
338+
}
339+
}
340+
320341
void ApplicationService::exportToPng(const ExportParams & exportParams)
321342
{
322343
m_editorView->saveZoom();
323344
zoomForExport();
324345

325346
L().info() << "Exporting a PNG image of size (" << exportParams.imageSize.width() << "x" << exportParams.imageSize.height() << ") to " << exportParams.fileName.toStdString();
347+
const auto lines = addGridForExport();
326348
const auto image = m_editorScene->toImage(exportParams.imageSize, m_editorService->backgroundColor(), exportParams.transparentBackground);
327349
m_editorView->restoreZoom();
350+
removeLineItems(lines);
328351

329352
emit pngExportFinished(image.save(exportParams.fileName));
330353
}
@@ -335,8 +358,10 @@ void ApplicationService::exportToSvg(const ExportParams & exportParams)
335358
zoomForExport();
336359

337360
L().info() << "Exporting an SVG image to " << exportParams.fileName.toStdString();
361+
const auto lines = addGridForExport();
338362
m_editorScene->toSvg(exportParams.fileName, QFileInfo { exportParams.fileName }.fileName());
339363
m_editorView->restoreZoom();
364+
removeLineItems(lines);
340365

341366
emit svgExportFinished(true);
342367
}

src/application_service.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ private slots:
225225
private:
226226
void addExistingGraphToScene(bool zoomToFitAfterNodesLoaded = false);
227227

228+
using GridLineVector = std::vector<QGraphicsLineItem *>;
229+
GridLineVector addGridForExport();
230+
228231
double calculateNodeOverlapScore(NodeCR node1, NodeCR node2) const;
229232

230233
void connectGraphToUndoMechanism();
@@ -237,6 +240,8 @@ private slots:
237240

238241
void paste();
239242

243+
void removeLineItems(const GridLineVector & lines);
244+
240245
void setupMindMapAfterUndoOrRedo();
241246

242247
void updateNodeConnectionActions();

src/core/settings.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,7 @@ Qt::CheckState loadGridVisibleState()
199199
{
200200
QSettings settings;
201201
settings.beginGroup(settingsGroupMainWindow);
202-
const auto gridState = settings.value(gridVisibleStateKey, Qt::Unchecked).toInt();
203-
settings.endGroup();
204-
return static_cast<Qt::CheckState>(gridState);
202+
return static_cast<Qt::CheckState>(settings.value(gridVisibleStateKey, Qt::Unchecked).toInt());
205203
}
206204

207205
void saveGridVisibleState(int state)

src/core/settings_proxy.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@
1616
#ifndef SETTINGS_PROXY_HPP
1717
#define SETTINGS_PROXY_HPP
1818

19-
#include "../constants.hpp"
2019
#include "../scene_items/edge_model.hpp"
2120
#include "shadow_effect_params.hpp"
2221

23-
#include <memory>
24-
2522
#include <QFont>
2623

2724
namespace Core {
2825

26+
//! Some kind of a frond-end or facade for stateless Settings to enable faster value reads (QSettings can be quite slow)
27+
//! and to create more complex settings (e.g. setShadowEffect()) that use the Settings API. However, the situation is a
28+
//! bit of a mess right now as some features still use Settings directly and some features use SettingsProxy.
29+
//!
30+
//! The current policy for new settings is to use the Settings::Generic API and hide it behind SettingsProxy to
31+
//! expose a clean API without visible setting keys or low-level functions.
32+
//!
33+
//! SettingsProxy can be accessed via SingleInstanceContainer throughout the application.
2934
class SettingsProxy
3035
{
3136
public:

0 commit comments

Comments
 (0)