29using namespace Qt::StringLiterals;
35 mGridPen = QPen( QColor( 190, 190, 190, 100 ), 0 );
36 mGridPen.setCosmetic(
true );
47 mLayout->
undoStack()->
beginCommand(
this, QObject::tr(
"Change Grid Resolution" ), UndoGridResolution );
49 mLayout->undoStack()->endCommand();
54 mLayout->undoStack()->beginCommand(
this, QObject::tr(
"Change Grid Offset" ), UndoGridOffset );
56 mLayout->undoStack()->endCommand();
76 mGridPen.setColor( gridColor );
77 mGridPen.setWidthF( 0 );
78 mGridPen.setCosmetic(
true );
80 if ( gridStyleString ==
"Dots"_L1 )
84 else if ( gridStyleString ==
"Crosses"_L1 )
99 QDomElement element = document.createElement( u
"Grid"_s );
101 element.setAttribute( u
"resolution"_s, mGridResolution.length() );
104 element.setAttribute( u
"offsetX"_s, mGridOffset.x() );
105 element.setAttribute( u
"offsetY"_s, mGridOffset.y() );
108 parentElement.appendChild( element );
114 QDomElement element = e;
115 if ( element.nodeName() !=
"Grid"_L1 )
117 element = element.firstChildElement( u
"Grid"_s );
120 if ( element.nodeName() !=
"Grid"_L1 )
125 const double res = element.attribute( u
"resolution"_s, u
"10"_s ).toDouble();
129 const double offsetX = element.attribute( u
"offsetX"_s ).toDouble();
130 const double offsetY = element.attribute( u
"offsetY"_s ).toDouble();
134 mLayout->pageCollection()->redraw();
LayoutUnit
Layout measurement units.
@ Millimeters
Millimeters.
QgsLayoutMeasurement resolution() const
Returns the page/snap grid resolution.
static const QgsSettingsEntryDouble * settingsGridOffsetX
QgsLayout * layout() override
Returns the layout the object belongs to.
static const QgsSettingsEntryColor * settingsGridColor
QgsLayoutGridSettings(QgsLayout *layout)
Constructor for QgsLayoutGridSettings.
QgsLayoutPoint offset() const
Returns the offset of the page/snap grid.
void setOffset(const QgsLayoutPoint &offset)
Sets the offset of the page/snap grid.
static const QgsSettingsEntryDouble * settingsGridResolution
static const QgsSettingsEntryDouble * settingsGridOffsetY
bool writeXml(QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context) const override
Stores the grid's state in a DOM element.
bool readXml(const QDomElement &gridElement, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets the grid's state from a DOM element.
static const QgsSettingsEntryString * settingsGridStyle
void loadFromSettings()
Loads grid settings from the application layout settings.
void setResolution(QgsLayoutMeasurement resolution)
Sets the page/snap grid resolution.
Provides a method of storing measurements for use in QGIS layouts using a variety of different measur...
Provides a method of storing points, consisting of an x and y coordinate, for use in QGIS layouts.
void beginCommand(QgsLayoutUndoObjectInterface *object, const QString &commandText, int id=0)
Begins a new undo command for the specified object.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
QgsLayoutUndoStack * undoStack()
Returns a pointer to the layout's undo stack, which manages undo/redo states for the layout and it's ...
A container for the context for various read/write operations on objects.
static QgsSettingsTreeNode * sTreeLayout
static QgsSettingsTreeNode * sTreeLayoutGrid
static Q_INVOKABLE Qgis::LayoutUnit decodeLayoutUnit(const QString &string, bool *ok=nullptr)
Decodes a layout unit from a string.
static Q_INVOKABLE QString encodeUnit(Qgis::DistanceUnit unit)
Encodes a distance unit to a string.