46#include <QAbstractTextDocumentLayout>
47#include <QDesktopServices>
48#include <QDragEnterEvent>
52#include <QPlainTextDocumentLayout>
53#include <QSortFilterProxyModel>
58#include "moc_qgsbrowserdockwidget_p.cpp"
60using namespace Qt::StringLiterals;
65QgsBrowserPropertiesWrapLabel::QgsBrowserPropertiesWrapLabel(
const QString &text, QWidget *parent )
66 : QTextEdit( text, parent )
69 setFrameStyle( QFrame::NoFrame );
70 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
71 QPalette
pal = palette();
72 pal.setColor( QPalette::Base, Qt::transparent );
74 setLineWrapMode( QTextEdit::WidgetWidth );
75 setWordWrapMode( QTextOption::WrapAnywhere );
76 connect( document()->documentLayout(), &QAbstractTextDocumentLayout::documentSizeChanged,
this, &QgsBrowserPropertiesWrapLabel::adjustHeight );
77 setMaximumHeight( 20 );
80void QgsBrowserPropertiesWrapLabel::adjustHeight( QSizeF size )
82 const int height =
static_cast<int>( size.height() ) + 2 * frameWidth();
83 setMinimumHeight( height );
84 setMaximumHeight( height );
87QgsBrowserPropertiesWidget::QgsBrowserPropertiesWidget( QWidget *parent )
92void QgsBrowserPropertiesWidget::setWidget( QWidget *paramWidget )
94 QVBoxLayout *layout =
new QVBoxLayout(
this );
95 layout->setContentsMargins( 0, 0, 0, 0 );
96 paramWidget->setParent(
this );
97 layout->addWidget( paramWidget );
102 QgsBrowserPropertiesWidget *propertiesWidget =
nullptr;
107 propertiesWidget =
new QgsBrowserDirectoryProperties( parent );
108 propertiesWidget->setItem( item );
116 QWidget *paramWidget =
nullptr;
120 paramWidget = provider->createParamWidget( item, context );
135 propertiesWidget =
new QgsBrowserPropertiesWidget( parent );
136 propertiesWidget->setWidget( paramWidget );
140 propertiesWidget =
new QgsBrowserLayerProperties( parent );
141 propertiesWidget->setItem( item );
144 return propertiesWidget;
147QgsBrowserLayerProperties::QgsBrowserLayerProperties( QWidget *parent )
148 : QgsBrowserPropertiesWidget( parent )
153 mMetadataTextBrowser->setOpenLinks(
false );
154 connect( mMetadataTextBrowser, &QTextBrowser::anchorClicked,
this, &QgsBrowserLayerProperties::urlClicked );
156 mMapCanvas->setProperty(
"browser_canvas",
true );
157 mMapCanvas->setLayers( QList<QgsMapLayer *>() );
159 mMapCanvas->freeze(
true );
161 connect( mTabWidget, &QTabWidget::currentChanged,
this, [
this] {
162 if ( mTabWidget->currentWidget() == mPreviewTab && mMapCanvas->isFrozen() )
164 mMapCanvas->freeze(
false );
165 mMapCanvas->refresh();
167 else if ( mTabWidget->currentWidget() == mAttributesTab )
169 if ( !mAttributeTableFilterModel )
170 loadAttributeTable();
175void QgsBrowserLayerProperties::setItem(
QgsDataItem *item )
177 QgsLayerItem *layerItem = qobject_cast<QgsLayerItem *>( item );
181 mNoticeLabel->clear();
184 QString layerMetadata = tr(
"Error" );
200 mLayer = std::make_unique<QgsRasterLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
209 mLayer = std::make_unique<QgsMeshLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
218 mLayer = std::make_unique<QgsVectorLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
225 mLayer = std::make_unique<QgsVectorTileLayer>( layerItem->
uri(), layerItem->
name() );
234 mLayer = std::make_unique<QgsPointCloudLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
243 mLayer = std::make_unique<QgsTiledSceneLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
256 mAttributeTable->setModel(
nullptr );
257 if ( mAttributeTableFilterModel )
260 mAttributeTableFilterModel->deleteLater();
261 mAttributeTableFilterModel =
nullptr;
263 if ( mLayer && mLayer->isValid() )
266 mLayer->loadDefaultMetadata( ok );
267 layerMetadata = mLayer->htmlMetadata();
269 mMapCanvas->setDestinationCrs( mLayer->crs() );
270 mMapCanvas->setLayers( QList<QgsMapLayer *>() << mLayer.get() );
271 mMapCanvas->zoomToFullExtent();
275 mTabWidget->removeTab( mTabWidget->indexOf( mAttributesTab ) );
276 mAttributesTab =
nullptr;
280 if (
QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( mLayer.get() ) )
284 mTabWidget->removeTab( mTabWidget->indexOf( mPreviewTab ) );
285 mPreviewTab =
nullptr;
291 mMetadataTextBrowser->document()->setDefaultStyleSheet( myStyle );
292 mMetadataTextBrowser->setHtml( layerMetadata );
294 if ( mNoticeLabel->text().isEmpty() )
296 mNoticeLabel->hide();
300void QgsBrowserLayerProperties::setCondensedMode(
bool )
304void QgsBrowserLayerProperties::urlClicked(
const QUrl &url )
306 if ( !url.fragment().isEmpty() && url.toString().startsWith(
'#'_L1 ) )
308 mMetadataTextBrowser->scrollToAnchor( url.fragment() );
311 const QFileInfo file( url.toLocalFile() );
312 if ( file.exists() && !file.isDir() )
315 QDesktopServices::openUrl( url );
318void QgsBrowserLayerProperties::loadAttributeTable()
329 layerCache->setParent( tableModel );
330 tableModel->setParent( mAttributeTableFilterModel );
332 mAttributeTable->setModel( mAttributeTableFilterModel );
334 QFont font = mAttributeTable->font();
335 int fontSize = font.pointSize();
337 fontSize = std::max( fontSize - 1, 8 );
339 fontSize = std::max( fontSize - 2, 6 );
341 font.setPointSize( fontSize );
342 mAttributeTable->setFont( font );
345 mAttributeTable->resizeColumnsToContents();
346 mAttributeTable->resizeRowsToContents();
347 mAttributeTable->verticalHeader()->setVisible(
false );
348 mAttributeTable->setAlternatingRowColors(
true );
351QgsBrowserDirectoryProperties::QgsBrowserDirectoryProperties( QWidget *parent )
352 : QgsBrowserPropertiesWidget( parent )
357 mPathLabel =
new QgsBrowserPropertiesWrapLabel( QString(), mHeaderWidget );
358 mHeaderGridLayout->addItem(
new QWidgetItem( mPathLabel ), 0, 1 );
361void QgsBrowserDirectoryProperties::setItem(
QgsDataItem *item )
367 mPathLabel->setText( QDir::toNativeSeparators( directoryItem->
dirPath() ) );
369 mLayout->addWidget( mDirectoryWidget );
372QgsBrowserPropertiesDialog::QgsBrowserPropertiesDialog(
const QString &settingsSection, QWidget *parent )
374 , mSettingsSection( settingsSection )
385 mPropertiesWidget = QgsBrowserPropertiesWidget::createWidget( item, context,
this );
386 mLayout->addWidget( mPropertiesWidget );
395QgsDockBrowserTreeView::QgsDockBrowserTreeView( QWidget *parent )
398 setDragDropMode( QTreeView::DragDrop );
399 setSelectionMode( QAbstractItemView::ExtendedSelection );
400 setContextMenuPolicy( Qt::CustomContextMenu );
401 setHeaderHidden(
true );
402 setDropIndicatorShown(
true );
405void QgsDockBrowserTreeView::setAction( QDropEvent *e )
409 if ( e->mimeData()->hasFormat( u
"application/qgis.layertreemodeldata"_s ) && e->mimeData()->hasFormat( u
"application/x-vnd.qgis.qgis.uri"_s ) )
411 e->setDropAction( Qt::CopyAction );
415void QgsDockBrowserTreeView::dragEnterEvent( QDragEnterEvent *e )
424void QgsDockBrowserTreeView::dragMoveEvent( QDragMoveEvent *e )
435 QTreeView::dragMoveEvent( e );
439 if ( !e->mimeData()->hasFormat( u
"application/x-vnd.qgis.qgis.uri"_s ) )
446void QgsDockBrowserTreeView::dropEvent( QDropEvent *e )
449 QTreeView::dropEvent( e );
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
@ Layer
Represents a map layer.
@ Field
Vector layer field.
@ Custom
Custom item type.
@ Fields
Collection of fields.
@ Directory
Represents a file directory.
LayerType
Types of layers that can be added to a map.
@ Group
Composite group layer. Added in QGIS 3.24.
@ Plugin
Plugin based layer.
@ TiledScene
Tiled scene layer. Added in QGIS 3.34.
@ Annotation
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
@ Mesh
Mesh layer. Added in QGIS 3.2.
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
static QString reportStyleSheet(QgsApplication::StyleSheetType styleSheetType=QgsApplication::StyleSheetType::Qt)
Returns a css style sheet for reports, the styleSheetType argument determines what type of stylesheet...
A proxy model for filtering an attribute table model.
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
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...
Extends QTreeView with save/restore tree state and other browser-specific functionality.
Encapsulates the context in which a QgsDataItem is shown within the application GUI.
QList< QgsDataItemGuiProvider * > providers() const
Returns the list of available providers.
Abstract base class for providers which affect how QgsDataItem items behave within the application GU...
Base class for all items in the model.
Qgis::BrowserItemType type() const
QString name() const
Returns the name of the item (the displayed text for the item).
virtual Q_DECL_DEPRECATED QWidget * paramWidget()
Returns source widget from data item for QgsBrowserPropertiesWidget.
QString providerKey() const
Returns the provider key that created this item (e.g.
A browser item for directories: contains subdirectories and layers.
QString dirPath() const
Returns the full path to the directory the item represents.
Wraps a request for features to a vector layer (or directly its vector data provider).
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
static QgsNative * nativePlatformInterface()
Returns the global native interface, which offers abstraction to the host OS's underlying public inte...
static QgsDataItemGuiProviderRegistry * dataItemGuiProviderRegistry()
Returns the global data item GUI provider registry, used for tracking providers which affect the brow...
A browser item that represents a layer that can be opened with one of the providers.
QString uri() const
Returns layer uri or empty string if layer cannot be created.
Qgis::LayerType mapLayerType() const
Returns the associated map layer type.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsCoordinateTransformContext transformContext
Caches features for a given QgsVectorLayer.
void setCacheGeometry(bool cacheGeometry)
Enable or disable the caching of geometries.
Represents a vector layer which manages a vector based dataset.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH
#define QgsDebugMsgLevel(str, level)
Setting options for loading mesh layers.
bool skipCrsValidation
Controls whether the layer is allowed to have an invalid/unknown CRS.
Setting options for loading point cloud layers.
bool skipCrsValidation
Controls whether the layer is allowed to have an invalid/unknown CRS.
Setting options for loading raster layers.
bool skipCrsValidation
Controls whether the layer is allowed to have an invalid/unknown CRS.
Setting options for loading tiled scene layers.
bool skipCrsValidation
Controls whether the layer is allowed to have an invalid/unknown CRS.
Setting options for loading vector layers.
bool skipCrsValidation
Controls whether the layer is allowed to have an invalid/unknown CRS.