30 mGridPen = QPen( QColor( 190, 190, 190, 100 ), 0 );
31 mGridPen.setCosmetic(
true );
42 mLayout->
undoStack()->
beginCommand(
this, QObject::tr(
"Change Grid Resolution" ), UndoGridResolution );
44 mLayout->undoStack()->endCommand();
49 mLayout->undoStack()->beginCommand(
this, QObject::tr(
"Change Grid Offset" ), UndoGridOffset );
51 mLayout->undoStack()->endCommand();
59 QString gridStyleString;
60 gridStyleString = s.
value( QStringLiteral(
"LayoutDesigner/gridStyle" ),
"Dots",
QgsSettings::Gui ).toString();
62 int gridRed, gridGreen, gridBlue, gridAlpha;
67 const QColor gridColor = QColor( gridRed, gridGreen, gridBlue, gridAlpha );
69 mGridPen.setColor( gridColor );
70 mGridPen.setWidthF( 0 );
71 mGridPen.setCosmetic(
true );
73 if ( gridStyleString == QLatin1String(
"Dots" ) )
77 else if ( gridStyleString == QLatin1String(
"Crosses" ) )
94 QDomElement element = document.createElement( QStringLiteral(
"Grid" ) );
96 element.setAttribute( QStringLiteral(
"resolution" ), mGridResolution.length() );
99 element.setAttribute( QStringLiteral(
"offsetX" ), mGridOffset.x() );
100 element.setAttribute( QStringLiteral(
"offsetY" ), mGridOffset.y() );
103 parentElement.appendChild( element );
109 QDomElement element = e;
110 if ( element.nodeName() != QLatin1String(
"Grid" ) )
112 element = element.firstChildElement( QStringLiteral(
"Grid" ) );
115 if ( element.nodeName() != QLatin1String(
"Grid" ) )
120 const double res = element.attribute( QStringLiteral(
"resolution" ), QStringLiteral(
"10" ) ).toDouble();
124 const double offsetX = element.attribute( QStringLiteral(
"offsetX" ) ).toDouble();
125 const double offsetY = element.attribute( QStringLiteral(
"offsetY" ) ).toDouble();
129 mLayout->pageCollection()->redraw();
LayoutUnit
Layout measurement units.
@ Millimeters
Millimeters.
QgsLayoutMeasurement resolution() const
Returns the page/snap grid resolution.
QgsLayout * layout() override
Returns the layout the object belongs to.
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.
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.
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.
Stores settings for use within QGIS.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
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.