46#include <QAbstractTextDocumentLayout>
47#include <QDesktopServices>
48#include <QDragEnterEvent>
52#include <QPlainTextDocumentLayout>
53#include <QSortFilterProxyModel>
57#include "moc_qgsbrowserdockwidget_p.cpp"
62QgsBrowserPropertiesWrapLabel::QgsBrowserPropertiesWrapLabel(
const QString &text, QWidget *parent )
63 : QTextEdit( text, parent )
66 setFrameStyle( QFrame::NoFrame );
67 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
68 QPalette
pal = palette();
69 pal.setColor( QPalette::Base, Qt::transparent );
71 setLineWrapMode( QTextEdit::WidgetWidth );
72 setWordWrapMode( QTextOption::WrapAnywhere );
73 connect( document()->documentLayout(), &QAbstractTextDocumentLayout::documentSizeChanged,
this, &QgsBrowserPropertiesWrapLabel::adjustHeight );
74 setMaximumHeight( 20 );
77void QgsBrowserPropertiesWrapLabel::adjustHeight( QSizeF size )
79 const int height =
static_cast<int>( size.height() ) + 2 * frameWidth();
80 setMinimumHeight( height );
81 setMaximumHeight( height );
84QgsBrowserPropertiesWidget::QgsBrowserPropertiesWidget( QWidget *parent )
89void QgsBrowserPropertiesWidget::setWidget( QWidget *paramWidget )
91 QVBoxLayout *layout =
new QVBoxLayout(
this );
92 layout->setContentsMargins( 0, 0, 0, 0 );
93 paramWidget->setParent(
this );
94 layout->addWidget( paramWidget );
99 QgsBrowserPropertiesWidget *propertiesWidget =
nullptr;
104 propertiesWidget =
new QgsBrowserDirectoryProperties( parent );
105 propertiesWidget->setItem( item );
113 QWidget *paramWidget =
nullptr;
117 paramWidget = provider->createParamWidget( item, context );
132 propertiesWidget =
new QgsBrowserPropertiesWidget( parent );
133 propertiesWidget->setWidget( paramWidget );
137 propertiesWidget =
new QgsBrowserLayerProperties( parent );
138 propertiesWidget->setItem( item );
141 return propertiesWidget;
144QgsBrowserLayerProperties::QgsBrowserLayerProperties( QWidget *parent )
145 : QgsBrowserPropertiesWidget( parent )
150 mMetadataTextBrowser->setOpenLinks(
false );
151 connect( mMetadataTextBrowser, &QTextBrowser::anchorClicked,
this, &QgsBrowserLayerProperties::urlClicked );
153 mMapCanvas->setProperty(
"browser_canvas",
true );
154 mMapCanvas->setLayers( QList<QgsMapLayer *>() );
156 mMapCanvas->freeze(
true );
158 connect( mTabWidget, &QTabWidget::currentChanged,
this, [
this] {
159 if ( mTabWidget->currentWidget() == mPreviewTab && mMapCanvas->isFrozen() )
161 mMapCanvas->freeze(
false );
162 mMapCanvas->refresh();
164 else if ( mTabWidget->currentWidget() == mAttributesTab )
166 if ( !mAttributeTableFilterModel )
167 loadAttributeTable();
172void QgsBrowserLayerProperties::setItem(
QgsDataItem *item )
174 QgsLayerItem *layerItem = qobject_cast<QgsLayerItem *>( item );
178 mNoticeLabel->clear();
181 QString layerMetadata = tr(
"Error" );
188 QgsDebugMsgLevel( QStringLiteral(
"creating temporary layer using path %1" ).arg( layerItem->
path() ), 2 );
197 mLayer = std::make_unique<QgsRasterLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
206 mLayer = std::make_unique<QgsMeshLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
215 mLayer = std::make_unique<QgsVectorLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
222 mLayer = std::make_unique<QgsVectorTileLayer>( layerItem->
uri(), layerItem->
name() );
231 mLayer = std::make_unique<QgsPointCloudLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
240 mLayer = std::make_unique<QgsTiledSceneLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
253 mAttributeTable->setModel(
nullptr );
254 if ( mAttributeTableFilterModel )
257 mAttributeTableFilterModel->deleteLater();
258 mAttributeTableFilterModel =
nullptr;
260 if ( mLayer && mLayer->isValid() )
263 mLayer->loadDefaultMetadata( ok );
264 layerMetadata = mLayer->htmlMetadata();
266 mMapCanvas->setDestinationCrs( mLayer->crs() );
267 mMapCanvas->setLayers( QList<QgsMapLayer *>() << mLayer.get() );
268 mMapCanvas->zoomToFullExtent();
272 mTabWidget->removeTab( mTabWidget->indexOf( mAttributesTab ) );
273 mAttributesTab =
nullptr;
277 if (
QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( mLayer.get() ) )
281 mTabWidget->removeTab( mTabWidget->indexOf( mPreviewTab ) );
282 mPreviewTab =
nullptr;
288 mMetadataTextBrowser->document()->setDefaultStyleSheet( myStyle );
289 mMetadataTextBrowser->setHtml( layerMetadata );
291 if ( mNoticeLabel->text().isEmpty() )
293 mNoticeLabel->hide();
297void QgsBrowserLayerProperties::setCondensedMode(
bool )
301void QgsBrowserLayerProperties::urlClicked(
const QUrl &url )
303 if ( !url.fragment().isEmpty() && url.toString().startsWith( QLatin1Char(
'#' ) ) )
305 mMetadataTextBrowser->scrollToAnchor( url.fragment() );
308 const QFileInfo file( url.toLocalFile() );
309 if ( file.exists() && !file.isDir() )
312 QDesktopServices::openUrl( url );
315void QgsBrowserLayerProperties::loadAttributeTable()
326 layerCache->setParent( tableModel );
327 tableModel->setParent( mAttributeTableFilterModel );
329 mAttributeTable->setModel( mAttributeTableFilterModel );
331 QFont font = mAttributeTable->font();
332 int fontSize = font.pointSize();
334 fontSize = std::max( fontSize - 1, 8 );
336 fontSize = std::max( fontSize - 2, 6 );
338 font.setPointSize( fontSize );
339 mAttributeTable->setFont( font );
342 mAttributeTable->resizeColumnsToContents();
343 mAttributeTable->resizeRowsToContents();
344 mAttributeTable->verticalHeader()->setVisible(
false );
345 mAttributeTable->setAlternatingRowColors(
true );
348QgsBrowserDirectoryProperties::QgsBrowserDirectoryProperties( QWidget *parent )
349 : QgsBrowserPropertiesWidget( parent )
354 mPathLabel =
new QgsBrowserPropertiesWrapLabel( QString(), mHeaderWidget );
355 mHeaderGridLayout->addItem(
new QWidgetItem( mPathLabel ), 0, 1 );
358void QgsBrowserDirectoryProperties::setItem(
QgsDataItem *item )
364 mPathLabel->setText( QDir::toNativeSeparators( directoryItem->
dirPath() ) );
366 mLayout->addWidget( mDirectoryWidget );
369QgsBrowserPropertiesDialog::QgsBrowserPropertiesDialog(
const QString &settingsSection, QWidget *parent )
371 , mSettingsSection( settingsSection )
382 mPropertiesWidget = QgsBrowserPropertiesWidget::createWidget( item, context,
this );
383 mLayout->addWidget( mPropertiesWidget );
392QgsDockBrowserTreeView::QgsDockBrowserTreeView( QWidget *parent )
395 setDragDropMode( QTreeView::DragDrop );
396 setSelectionMode( QAbstractItemView::ExtendedSelection );
397 setContextMenuPolicy( Qt::CustomContextMenu );
398 setHeaderHidden(
true );
399 setDropIndicatorShown(
true );
402void QgsDockBrowserTreeView::setAction( QDropEvent *e )
406 if ( e->mimeData()->hasFormat( QStringLiteral(
"application/qgis.layertreemodeldata" ) ) && e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
408 e->setDropAction( Qt::CopyAction );
412void QgsDockBrowserTreeView::dragEnterEvent( QDragEnterEvent *e )
421void QgsDockBrowserTreeView::dragMoveEvent( QDragMoveEvent *e )
432 QTreeView::dragMoveEvent( e );
436 if ( !e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
443void QgsDockBrowserTreeView::dropEvent( QDropEvent *e )
446 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.