24 #include <QAbstractTextDocumentLayout> 25 #include <QHeaderView> 28 #include <QToolButton> 29 #include <QFileDialog> 30 #include <QPlainTextDocumentLayout> 31 #include <QSortFilterProxyModel> 42 #include "qgsnative.h" 48 #include <QDesktopServices> 50 #include <QDragEnterEvent> 56 QgsBrowserPropertiesWrapLabel::QgsBrowserPropertiesWrapLabel(
const QString &text, QWidget *parent )
57 : QTextEdit( text, parent )
60 setFrameStyle( QFrame::NoFrame );
61 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
62 QPalette
pal = palette();
63 pal.setColor( QPalette::Base, Qt::transparent );
65 setLineWrapMode( QTextEdit::WidgetWidth );
66 setWordWrapMode( QTextOption::WrapAnywhere );
67 connect( document()->documentLayout(), &QAbstractTextDocumentLayout::documentSizeChanged,
68 this, &QgsBrowserPropertiesWrapLabel::adjustHeight );
69 setMaximumHeight( 20 );
72 void QgsBrowserPropertiesWrapLabel::adjustHeight( QSizeF size )
74 int height = size.height() + 2 * frameWidth();
75 setMinimumHeight( height );
76 setMaximumHeight( height );
79 QgsBrowserPropertiesWidget::QgsBrowserPropertiesWidget( QWidget *parent )
84 void QgsBrowserPropertiesWidget::setWidget( QWidget *paramWidget )
86 QVBoxLayout *layout =
new QVBoxLayout(
this );
87 paramWidget->setParent(
this );
88 layout->addWidget( paramWidget );
91 QgsBrowserPropertiesWidget *QgsBrowserPropertiesWidget::createWidget(
QgsDataItem *item, QWidget *parent )
93 QgsBrowserPropertiesWidget *propertiesWidget =
nullptr;
98 propertiesWidget =
new QgsBrowserDirectoryProperties( parent );
99 propertiesWidget->setItem( item );
107 propertiesWidget =
new QgsBrowserPropertiesWidget( parent );
108 propertiesWidget->setWidget( paramWidget );
112 propertiesWidget =
new QgsBrowserLayerProperties( parent );
113 propertiesWidget->setItem( item );
116 return propertiesWidget;
119 QgsBrowserLayerProperties::QgsBrowserLayerProperties( QWidget *parent )
120 : QgsBrowserPropertiesWidget( parent )
125 mMetadataTextBrowser->setOpenLinks(
false );
126 connect( mMetadataTextBrowser, &QTextBrowser::anchorClicked,
this, &QgsBrowserLayerProperties::urlClicked );
128 mMapCanvas->setProperty(
"browser_canvas",
true );
129 mMapCanvas->setLayers( QList< QgsMapLayer * >() );
131 mMapCanvas->freeze(
true );
133 connect( mTabWidget, &QTabWidget::currentChanged,
this, [ = ]
135 if ( mTabWidget->currentWidget() == mPreviewTab && mMapCanvas->isFrozen() )
137 mMapCanvas->freeze(
false );
138 mMapCanvas->refresh();
140 else if ( mTabWidget->currentWidget() == mAttributesTab )
142 if ( ! mAttributeTableFilterModel )
143 loadAttributeTable();
148 class ProjectionSettingRestorer
152 ProjectionSettingRestorer()
155 previousSetting = settings.
value( QStringLiteral(
"/Projections/defaultBehavior" ) ).toString();
156 settings.
setValue( QStringLiteral(
"/Projections/defaultBehavior" ), QStringLiteral(
"useProject" ) );
159 ~ProjectionSettingRestorer()
162 settings.
setValue( QStringLiteral(
"/Projections/defaultBehavior" ), previousSetting );
165 QString previousSetting;
168 void QgsBrowserLayerProperties::setItem(
QgsDataItem *item )
174 mNoticeLabel->clear();
177 QString layerMetadata = tr(
"Error" );
180 QString defaultProjectionOption =
QgsSettings().
value( QStringLiteral(
"Projections/defaultBehavior" ),
"prompt" ).toString();
183 ProjectionSettingRestorer restorer;
191 QgsDebugMsg( QStringLiteral(
"creating temporary layer using path %1" ).arg( layerItem->
path() ) );
196 QgsDebugMsg( QStringLiteral(
"creating raster layer" ) );
198 mLayer = qgis::make_unique< QgsRasterLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey() );
204 QgsDebugMsg( QStringLiteral(
"creating mesh layer" ) );
206 mLayer = qgis::make_unique < QgsMeshLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
212 QgsDebugMsg( QStringLiteral(
"creating vector layer" ) );
214 mLayer = qgis::make_unique < QgsVectorLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
225 mAttributeTable->setModel(
nullptr );
226 if ( mAttributeTableFilterModel )
229 mAttributeTableFilterModel->deleteLater();
230 mAttributeTableFilterModel =
nullptr;
232 if ( mLayer && mLayer->isValid() )
235 mLayer->loadDefaultMetadata( ok );
236 layerCrs = mLayer->crs();
237 layerMetadata = mLayer->htmlMetadata();
239 mMapCanvas->setDestinationCrs( mLayer->crs() );
240 mMapCanvas->setLayers( QList< QgsMapLayer * >() << mLayer.get() );
241 mMapCanvas->zoomToFullExtent();
245 mTabWidget->removeTab( mTabWidget->indexOf( mAttributesTab ) );
246 mAttributesTab =
nullptr;
251 mMetadataTextBrowser->document()->setDefaultStyleSheet( myStyle );
252 mMetadataTextBrowser->setHtml( layerMetadata );
255 if ( defaultProjectionOption == QLatin1String(
"prompt" ) )
259 if ( layerCrs == defaultCrs )
260 mNoticeLabel->setText(
"NOTICE: Layer CRS set from project (" + defaultCrs.
authid() +
')' );
263 if ( mNoticeLabel->text().isEmpty() )
265 mNoticeLabel->hide();
269 void QgsBrowserLayerProperties::setCondensedMode(
bool )
274 void QgsBrowserLayerProperties::urlClicked(
const QUrl &url )
276 QFileInfo file( url.toLocalFile() );
277 if ( file.exists() && !file.isDir() )
280 QDesktopServices::openUrl( url );
283 void QgsBrowserLayerProperties::loadAttributeTable()
294 layerCache->setParent( tableModel );
295 tableModel->setParent( mAttributeTableFilterModel );
297 mAttributeTable->setModel( mAttributeTableFilterModel );
299 QFont font = mAttributeTable->font();
300 int fontSize = font.pointSize();
302 fontSize = std::max( fontSize - 1, 8 );
304 fontSize = std::max( fontSize - 2, 6 );
306 font.setPointSize( fontSize );
307 mAttributeTable->setFont( font );
310 mAttributeTable->resizeColumnsToContents();
311 mAttributeTable->resizeRowsToContents();
312 mAttributeTable->verticalHeader()->setVisible(
false );
313 mAttributeTable->setAlternatingRowColors(
true );
316 QgsBrowserDirectoryProperties::QgsBrowserDirectoryProperties( QWidget *parent )
317 : QgsBrowserPropertiesWidget( parent )
322 mPathLabel =
new QgsBrowserPropertiesWrapLabel( QString(), mHeaderWidget );
323 mHeaderGridLayout->addItem(
new QWidgetItem( mPathLabel ), 0, 1 );
326 void QgsBrowserDirectoryProperties::setItem(
QgsDataItem *item )
332 mPathLabel->setText( QDir::toNativeSeparators( directoryItem->
dirPath() ) );
334 mLayout->addWidget( mDirectoryWidget );
337 QgsBrowserPropertiesDialog::QgsBrowserPropertiesDialog(
const QString &settingsSection, QWidget *parent )
339 , mSettingsSection( settingsSection )
343 restoreGeometry( settings.
value( mSettingsSection +
"/propertiesDialog/geometry" ).toByteArray() );
346 QgsBrowserPropertiesDialog::~QgsBrowserPropertiesDialog()
352 void QgsBrowserPropertiesDialog::setItem(
QgsDataItem *item )
357 mPropertiesWidget = QgsBrowserPropertiesWidget::createWidget( item,
this );
358 mLayout->addWidget( mPropertiesWidget );
359 setWindowTitle( item->
type() ==
QgsDataItem::Layer ? tr(
"Layer Properties" ) : tr(
"Directory Properties" ) );
367 QgsDockBrowserTreeView::QgsDockBrowserTreeView( QWidget *parent ) :
QgsBrowserTreeView( parent )
369 setDragDropMode( QTreeView::DragDrop );
370 setSelectionMode( QAbstractItemView::ExtendedSelection );
371 setContextMenuPolicy( Qt::CustomContextMenu );
372 setHeaderHidden(
true );
373 setDropIndicatorShown(
true );
377 void QgsDockBrowserTreeView::setAction( QDropEvent *e )
381 if ( e->mimeData()->hasFormat( QStringLiteral(
"application/qgis.layertreemodeldata" ) ) &&
382 e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
384 e->setDropAction( Qt::CopyAction );
388 void QgsDockBrowserTreeView::dragEnterEvent( QDragEnterEvent *e )
397 void QgsDockBrowserTreeView::dragMoveEvent( QDragMoveEvent *e )
408 QTreeView::dragMoveEvent( e );
412 if ( !e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
419 void QgsDockBrowserTreeView::dropEvent( QDropEvent *e )
422 QTreeView::dropEvent( e );
void setRequest(const QgsFeatureRequest &request)
Set a request that will be used to fill this attribute table model.
virtual void loadLayer()
Loads the layer into the model Preferably to be called, before using this model as source for any oth...
The QgsBrowserTreeView class extends QTreeView with save/restore tree state functionality.
QString providerKey() const
Returns provider key.
QString name() const
Returns the name of the item (the displayed text for the item).
This class is a composition of two QSettings instances:
static QgsNative * nativePlatformInterface()
Returns the global native interface, which offers abstraction to the host OS's underlying public inte...
Setting options for loading vector layers.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
QgsMapLayerType mapLayerType() const
Returns QgsMapLayerType.
Setting options for loading mesh layers.
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
static QString reportStyleSheet()
Returns a standard css style sheet for reports.
static QgsGui * instance()
Returns a pointer to the singleton instance.
virtual QWidget * paramWidget()
void saveGeometry(QWidget *widget, const QString &keyName)
Save the wigget geometry into settings.
bool restoreGeometry(QWidget *widget, const QString &keyName)
Restore the wigget geometry from settings.
QgsCoordinateReferenceSystem crs
This class wraps a request for features to a vector layer (or directly its vector data provider)...
A directory: contains subdirectories and layers.
Base class for all items in the model.
This class caches features of a given QgsVectorLayer.
QgsCoordinateTransformContext transformContext
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
void setCacheGeometry(bool cacheGeometry)
Enable or disable the caching of geometries.
static QgsProject * instance()
Returns the QgsProject singleton instance.
This class represents a coordinate reference system (CRS).
QString uri() const
Returns layer uri or empty string if layer cannot be created.
QString dirPath() const
Returns the full path to the directory the item represents.
Item that represents a layer that can be opened with one of the providers.
QgsMapLayerType
Types of layers that can be added to a map.
Geometry is not required. It may still be returned if e.g. required for a filter condition.
QString authid() const
Returns the authority identifier for the CRS.