QGIS API Documentation 3.99.0-Master (7d2ca374f2d)
Loading...
Searching...
No Matches
qgstiledscenelayerproperties.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgstiledscenelayerproperties.cpp
3 --------------------------------------
4 Date : June 2023
5 Copyright : (C) 2023 by Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17
18#include "qgsapplication.h"
20#include "qgsgui.h"
21#include "qgshelp.h"
24#include "qgsmetadatawidget.h"
25#include "qgstiledscenelayer.h"
26
27#include <QDesktopServices>
28#include <QFileDialog>
29#include <QMenu>
30#include <QMessageBox>
31#include <QPushButton>
32#include <QString>
33
34#include "moc_qgstiledscenelayerproperties.cpp"
35
36using namespace Qt::StringLiterals;
37
39 : QgsLayerPropertiesDialog( layer, canvas, u"QgsTiledSceneLayerProperties"_s, parent, flags )
40 , mLayer( layer )
41{
42 setupUi( this );
43
44 connect( this, &QDialog::accepted, this, &QgsTiledSceneLayerProperties::apply );
45 connect( this, &QDialog::rejected, this, &QgsTiledSceneLayerProperties::rollback );
46 connect( buttonBox->button( QDialogButtonBox::Apply ), &QAbstractButton::clicked, this, &QgsTiledSceneLayerProperties::apply );
47 connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsTiledSceneLayerProperties::showHelp );
48
49 connect( mCrsSelector, &QgsProjectionSelectionWidget::crsChanged, this, &QgsTiledSceneLayerProperties::crsChanged );
50
51 mScaleRangeWidget->setMapCanvas( mCanvas );
52 chkUseScaleDependentRendering->setChecked( mLayer->hasScaleBasedVisibility() );
53 mScaleRangeWidget->setScaleRange( mLayer->minimumScale(), mLayer->maximumScale() );
54
55 // QgsOptionsDialogBase handles saving/restoring of geometry, splitter and current tab states,
56 // switching vertical tabs between icon/text to icon-only modes (splitter collapsed to left),
57 // and connecting QDialogButtonBox's accepted/rejected signals to dialog's accept/reject slots
58 initOptionsBase( false );
59
60 mOptsPage_Information->setContentsMargins( 0, 0, 0, 0 );
61
62 QVBoxLayout *layout = new QVBoxLayout( metadataFrame );
63 layout->setContentsMargins( 0, 0, 0, 0 );
64 metadataFrame->setContentsMargins( 0, 0, 0, 0 );
65 mMetadataWidget = new QgsMetadataWidget( this, mLayer );
66 mMetadataWidget->layout()->setContentsMargins( 0, 0, 0, 0 );
67 mMetadataWidget->setMapCanvas( mCanvas );
68 layout->addWidget( mMetadataWidget );
69 metadataFrame->setLayout( layout );
70 mOptsPage_Metadata->setContentsMargins( 0, 0, 0, 0 );
71
72 setMetadataWidget( mMetadataWidget, mOptsPage_Metadata );
73
74 // update based on layer's current state
76
77 QgsSettings settings;
78 if ( !settings.contains( u"/Windows/TiledSceneLayerProperties/tab"_s ) )
79 {
80 settings.setValue( u"Windows/TiledSceneLayerProperties/tab"_s, mOptStackedWidget->indexOf( mOptsPage_Information ) );
81 }
82
83 mBtnStyle = new QPushButton( tr( "Style" ) );
84 QMenu *menuStyle = new QMenu( this );
85 menuStyle->addAction( tr( "Load Style…" ), this, &QgsTiledSceneLayerProperties::loadStyleFromFile );
86 menuStyle->addAction( tr( "Save Style…" ), this, &QgsTiledSceneLayerProperties::saveStyleToFile );
87 menuStyle->addSeparator();
88 menuStyle->addAction( tr( "Save as Default" ), this, &QgsTiledSceneLayerProperties::saveStyleAsDefault );
89 menuStyle->addAction( tr( "Restore Default" ), this, &QgsTiledSceneLayerProperties::loadDefaultStyle );
90 mBtnStyle->setMenu( menuStyle );
91 connect( menuStyle, &QMenu::aboutToShow, this, &QgsTiledSceneLayerProperties::aboutToShowStyleMenu );
92
93 buttonBox->addButton( mBtnStyle, QDialogButtonBox::ResetRole );
94
95 mBtnMetadata = new QPushButton( tr( "Metadata" ), this );
96 QMenu *menuMetadata = new QMenu( this );
97 mActionLoadMetadata = menuMetadata->addAction( tr( "Load Metadata…" ), this, &QgsTiledSceneLayerProperties::loadMetadataFromFile );
98 mActionSaveMetadataAs = menuMetadata->addAction( tr( "Save Metadata…" ), this, &QgsTiledSceneLayerProperties::saveMetadataToFile );
99 menuMetadata->addSeparator();
100 menuMetadata->addAction( tr( "Save as Default" ), this, &QgsTiledSceneLayerProperties::saveMetadataAsDefault );
101 menuMetadata->addAction( tr( "Restore Default" ), this, &QgsTiledSceneLayerProperties::loadDefaultMetadata );
102
103 mBtnMetadata->setMenu( menuMetadata );
104 buttonBox->addButton( mBtnMetadata, QDialogButtonBox::ResetRole );
105
106 //Add help page references
107#if 0 // TODO
108 mOptsPage_Information->setProperty( "helpPage", u"working_with_point_clouds/point_clouds.html#information-properties"_s );
109 mOptsPage_Source->setProperty( "helpPage", u"working_with_point_clouds/point_clouds.html#source-properties"_s );
110 mOptsPage_Rendering->setProperty( "helpPage", u"working_with_point_clouds/point_clouds.html#rendering-properties"_s );
111 mOptsPage_Metadata->setProperty( "helpPage", u"working_with_point_clouds/point_clouds.html#metadata-properties"_s );
112#endif
113
114 mBackupCrs = mLayer->crs();
115
116 initialize();
117}
118
120{
121 mMetadataWidget->acceptMetadata();
122
123 mLayer->setName( mLayerOrigNameLineEdit->text() );
124
125 mLayer->setScaleBasedVisibility( chkUseScaleDependentRendering->isChecked() );
126 mLayer->setMinimumScale( mScaleRangeWidget->minimumScale() );
127 mLayer->setMaximumScale( mScaleRangeWidget->maximumScale() );
128
129 mBackupCrs = mLayer->crs();
130
131 for ( QgsMapLayerConfigWidget *w : std::as_const( mConfigWidgets ) )
132 w->apply();
133
134 mLayer->triggerRepaint();
135}
136
138{
139 if ( mBackupCrs != mLayer->crs() )
140 mLayer->setCrs( mBackupCrs );
141
143}
144
146{
147 // populate the general information
148 mLayerOrigNameLineEdit->setText( mLayer->name() );
149
150 // information Tab
151 QString myStyle = QgsApplication::reportStyleSheet();
152 myStyle.append( u"body { margin: 10px; }\n "_s );
153 mInformationTextBrowser->clear();
154 mInformationTextBrowser->document()->setDefaultStyleSheet( myStyle );
155 mInformationTextBrowser->setHtml( mLayer->htmlMetadata() );
156 mInformationTextBrowser->setOpenLinks( false );
157 connect( mInformationTextBrowser, &QTextBrowser::anchorClicked, this, &QgsTiledSceneLayerProperties::openUrl );
158
159 mCrsSelector->setCrs( mLayer->crs() );
160
161 for ( QgsMapLayerConfigWidget *w : std::as_const( mConfigWidgets ) )
162 w->syncToLayer( mLayer );
163}
164
165void QgsTiledSceneLayerProperties::aboutToShowStyleMenu()
166{
167 QMenu *m = qobject_cast<QMenu *>( sender() );
168
170 // re-add style manager actions!
171 m->addSeparator();
173}
174
175void QgsTiledSceneLayerProperties::showHelp()
176{
177 const QVariant helpPage = mOptionsStackedWidget->currentWidget()->property( "helpPage" );
178
179 if ( helpPage.isValid() )
180 {
181 QgsHelp::openHelp( helpPage.toString() );
182 }
183#if 0 // TODO
184 else
185 {
186 QgsHelp::openHelp( u"working_with_point_clouds/point_clouds.html"_s );
187 }
188#endif
189}
190
191void QgsTiledSceneLayerProperties::crsChanged( const QgsCoordinateReferenceSystem &crs )
192{
193 QgsDatumTransformDialog::run( crs, QgsProject::instance()->crs(), this, mCanvas, tr( "Select transformation for the layer" ) );
194 mLayer->setCrs( crs );
195 mMetadataWidget->crsChanged();
196}
static QString reportStyleSheet(QgsApplication::StyleSheetType styleSheetType=QgsApplication::StyleSheetType::Qt)
Returns a css style sheet for reports, the styleSheetType argument determines what type of stylesheet...
Represents a coordinate reference system (CRS).
static bool run(const QgsCoordinateReferenceSystem &sourceCrs=QgsCoordinateReferenceSystem(), const QgsCoordinateReferenceSystem &destinationCrs=QgsCoordinateReferenceSystem(), QWidget *parent=nullptr, QgsMapCanvas *mapCanvas=nullptr, const QString &windowTitle=QString())
Runs the dialog (if required) prompting for the desired transform to use from sourceCrs to destinatio...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:41
QPushButton * mBtnStyle
Style button.
void saveMetadataToFile()
Allows the user to save the layer's metadata as a file.
virtual void rollback()
Rolls back changes made to the layer.
void saveStyleAsDefault()
Saves the current layer style as the default for the layer.
QList< QgsMapLayerConfigWidget * > mConfigWidgets
Layer config widgets.
void setMetadataWidget(QgsMetadataWidget *widget, QWidget *page)
Sets the metadata widget and page associated with the dialog.
void loadDefaultStyle()
Reloads the default style for the layer.
void saveStyleToFile()
Allows the user to save the layer's style to a file.
QgsMapCanvas * mCanvas
Associated map canvas.
void loadDefaultMetadata()
Reloads the default layer metadata for the layer.
QgsLayerPropertiesDialog(QgsMapLayer *layer, QgsMapCanvas *canvas, const QString &settingsKey, QWidget *parent=nullptr, Qt::WindowFlags fl=Qt::WindowFlags(), QgsSettings *settings=nullptr)
Constructor for QgsLayerPropertiesDialog.
void loadMetadataFromFile()
Allows the user to load layer metadata from a file.
void loadStyleFromFile()
Allows the user to load layer style from a file.
QPushButton * mBtnMetadata
Metadata button.
void initialize()
Initialize the dialog.
void saveMetadataAsDefault()
Saves the current layer metadata as the default for the layer.
void openUrl(const QUrl &url)
Handles opening a url from the dialog.
Map canvas is a class for displaying all GIS data types on a canvas.
A panel widget that can be shown in the map style dock.
void removesExtraMenuSeparators(QMenu *m)
removes extra separators from the menu
void addStyleManagerActions(QMenu *m, QgsMapLayer *layer)
adds actions to the menu in accordance to the layer
static QgsMapLayerStyleGuiUtils * instance()
returns a singleton instance of this class
A bar for displaying non-blocking messages to the user.
A wizard to edit metadata on a map layer.
QStackedWidget * mOptStackedWidget
void initOptionsBase(bool restoreUi=true, const QString &title=QString())
Set up the base ui connections for vertical tabs.
static QgsProject * instance()
Returns the QgsProject singleton instance.
void crsChanged(const QgsCoordinateReferenceSystem &crs)
Emitted when the selected CRS is changed.
Stores settings for use within QGIS.
Definition qgssettings.h:68
bool contains(const QString &key, QgsSettings::Section section=QgsSettings::NoSection) const
Returns true if there exists a setting called key; returns false otherwise.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
QgsTiledSceneLayerProperties(QgsTiledSceneLayer *layer, QgsMapCanvas *canvas, QgsMessageBar *messageBar, QWidget *parent=nullptr, Qt::WindowFlags=QgsGuiUtils::ModalDialogFlags)
Constructor.
Represents a map layer supporting display of tiled scene objects.