29 mGridPen = QPen( QColor( 190, 190, 190, 100 ), 0 );
30 mGridPen.setCosmetic(
true );
41 mLayout->undoStack()->beginCommand(
this, QObject::tr(
"Change Grid Resolution" ), UndoGridResolution );
43 mLayout->undoStack()->endCommand();
48 mLayout->undoStack()->beginCommand(
this, QObject::tr(
"Change Grid Offset" ), UndoGridOffset );
50 mLayout->undoStack()->endCommand();
58 QString gridStyleString;
59 gridStyleString = s.
value( QStringLiteral(
"LayoutDesigner/gridStyle" ),
"Dots",
QgsSettings::Gui ).toString();
61 int gridRed, gridGreen, gridBlue, gridAlpha;
66 QColor gridColor = QColor( gridRed, gridGreen, gridBlue, gridAlpha );
68 mGridPen.setColor( gridColor );
69 mGridPen.setWidthF( 0 );
70 mGridPen.setCosmetic(
true );
72 if ( gridStyleString == QLatin1String(
"Dots" ) )
76 else if ( gridStyleString == QLatin1String(
"Crosses" ) )
93 QDomElement element = document.createElement( QStringLiteral(
"Grid" ) );
95 element.setAttribute( QStringLiteral(
"resolution" ), mGridResolution.
length() );
98 element.setAttribute( QStringLiteral(
"offsetX" ), mGridOffset.
x() );
99 element.setAttribute( QStringLiteral(
"offsetY" ), mGridOffset.
y() );
102 parentElement.appendChild( element );
108 QDomElement element = e;
109 if ( element.nodeName() != QStringLiteral(
"Grid" ) )
111 element = element.firstChildElement( QStringLiteral(
"Grid" ) );
114 if ( element.nodeName() != QStringLiteral(
"Grid" ) )
119 double res = element.attribute( QStringLiteral(
"resolution" ), QStringLiteral(
"10" ) ).toDouble();
123 double offsetX = element.attribute( QStringLiteral(
"offsetX" ) ).toDouble();
124 double offsetY = element.attribute( QStringLiteral(
"offsetY" ) ).toDouble();
128 mLayout->pageCollection()->redraw();
The class is used as a container of context for various read/write operations on other objects...
QgsUnitTypes::LayoutUnit units() const
Returns the units for the measurement.
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.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
QgsLayoutGridSettings(QgsLayout *layout)
Constructor for QgsLayoutGridSettings.
void loadFromSettings()
Loads grid settings from the application layout settings.
void setResolution(const QgsLayoutMeasurement &resolution)
Sets the page/snap grid resolution.
QgsLayout * layout() override
Returns the layout the object belongs to.
This class provides a method of storing points, consisting of an x and y coordinate, for use in QGIS layouts.
QgsUnitTypes::LayoutUnit units() const
Returns the units for the point.
const QgsLayout * layout() const
Returns the layout the object is attached to.
This class provides a method of storing measurements for use in QGIS layouts using a variety of diffe...
static Q_INVOKABLE QgsUnitTypes::LayoutUnit decodeLayoutUnit(const QString &string, bool *ok=nullptr)
Decodes a layout unit from a string.
QgsLayoutMeasurement resolution() const
Returns the page/snap grid resolution.
double y() const
Returns y coordinate of point.
QPointer< QgsLayout > mLayout
double x() const
Returns x coordinate of point.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
QgsLayoutPoint offset() const
Returns the offset of the page/snap grid.
double length() const
Returns the length of the measurement.
LayoutUnit
Layout measurement units.
void setOffset(QgsLayoutPoint offset)
Sets the offset of the page/snap grid.