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 )
91void QgsBrowserPropertiesWidget::setWidget( QWidget *paramWidget )
93 QVBoxLayout *layout =
new QVBoxLayout(
this );
94 layout->setContentsMargins( 0, 0, 0, 0 );
95 paramWidget->setParent(
this );
96 layout->addWidget( paramWidget );
101 QgsBrowserPropertiesWidget *propertiesWidget =
nullptr;
106 propertiesWidget =
new QgsBrowserDirectoryProperties( parent );
107 propertiesWidget->setItem( item );
112 QWidget *paramWidget =
nullptr;
116 paramWidget = provider->createParamWidget( item, context );
131 propertiesWidget =
new QgsBrowserPropertiesWidget( parent );
132 propertiesWidget->setWidget( paramWidget );
136 propertiesWidget =
new QgsBrowserLayerProperties( parent );
137 propertiesWidget->setItem( item );
140 return propertiesWidget;
143QgsBrowserLayerProperties::QgsBrowserLayerProperties( QWidget *parent )
144 : QgsBrowserPropertiesWidget( parent )
149 mMetadataTextBrowser->setOpenLinks(
false );
150 connect( mMetadataTextBrowser, &QTextBrowser::anchorClicked,
this, &QgsBrowserLayerProperties::urlClicked );
152 mMapCanvas->setProperty(
"browser_canvas",
true );
153 mMapCanvas->setLayers( QList<QgsMapLayer *>() );
155 mMapCanvas->freeze(
true );
157 connect( mTabWidget, &QTabWidget::currentChanged,
this, [
this] {
158 if ( mTabWidget->currentWidget() == mPreviewTab && mMapCanvas->isFrozen() )
160 mMapCanvas->freeze(
false );
161 mMapCanvas->refresh();
163 else if ( mTabWidget->currentWidget() == mAttributesTab )
165 if ( !mAttributeTableFilterModel )
166 loadAttributeTable();
171void QgsBrowserLayerProperties::setItem(
QgsDataItem *item )
173 QgsLayerItem *layerItem = qobject_cast<QgsLayerItem *>( item );
177 mNoticeLabel->clear();
180 QString layerMetadata = tr(
"Error" );
196 mLayer = std::make_unique<QgsRasterLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
205 mLayer = std::make_unique<QgsMeshLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
214 mLayer = std::make_unique<QgsVectorLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
221 mLayer = std::make_unique<QgsVectorTileLayer>( layerItem->
uri(), layerItem->
name() );
230 mLayer = std::make_unique<QgsPointCloudLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
239 mLayer = std::make_unique<QgsTiledSceneLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
252 mAttributeTable->setModel(
nullptr );
253 if ( mAttributeTableFilterModel )
256 mAttributeTableFilterModel->deleteLater();
257 mAttributeTableFilterModel =
nullptr;
259 if ( mLayer && mLayer->isValid() )
262 mLayer->loadDefaultMetadata( ok );
263 layerMetadata = mLayer->htmlMetadata();
265 mMapCanvas->setDestinationCrs( mLayer->crs() );
266 mMapCanvas->setLayers( QList<QgsMapLayer *>() << mLayer.get() );
267 mMapCanvas->zoomToFullExtent();
271 mTabWidget->removeTab( mTabWidget->indexOf( mAttributesTab ) );
272 mAttributesTab =
nullptr;
276 if (
QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( mLayer.get() ) )
280 mTabWidget->removeTab( mTabWidget->indexOf( mPreviewTab ) );
281 mPreviewTab =
nullptr;
287 mMetadataTextBrowser->document()->setDefaultStyleSheet( myStyle );
288 mMetadataTextBrowser->setHtml( layerMetadata );
290 if ( mNoticeLabel->text().isEmpty() )
292 mNoticeLabel->hide();
296void QgsBrowserLayerProperties::setCondensedMode(
bool )
299void QgsBrowserLayerProperties::urlClicked(
const QUrl &url )
301 if ( !url.fragment().isEmpty() && url.toString().startsWith(
'#'_L1 ) )
303 mMetadataTextBrowser->scrollToAnchor( url.fragment() );
306 const QFileInfo file( url.toLocalFile() );
307 if ( file.exists() && !file.isDir() )
310 QDesktopServices::openUrl( url );
313void QgsBrowserLayerProperties::loadAttributeTable()
324 layerCache->setParent( tableModel );
325 tableModel->setParent( mAttributeTableFilterModel );
327 mAttributeTable->setModel( mAttributeTableFilterModel );
329 QFont font = mAttributeTable->font();
330 int fontSize = font.pointSize();
332 fontSize = std::max( fontSize - 1, 8 );
334 fontSize = std::max( fontSize - 2, 6 );
336 font.setPointSize( fontSize );
337 mAttributeTable->setFont( font );
340 mAttributeTable->resizeColumnsToContents();
341 mAttributeTable->resizeRowsToContents();
342 mAttributeTable->verticalHeader()->setVisible(
false );
343 mAttributeTable->setAlternatingRowColors(
true );
346QgsBrowserDirectoryProperties::QgsBrowserDirectoryProperties( QWidget *parent )
347 : QgsBrowserPropertiesWidget( parent )
352 mPathLabel =
new QgsBrowserPropertiesWrapLabel( QString(), mHeaderWidget );
353 mHeaderGridLayout->addItem(
new QWidgetItem( mPathLabel ), 0, 1 );
356void QgsBrowserDirectoryProperties::setItem(
QgsDataItem *item )
362 mPathLabel->setText( QDir::toNativeSeparators( directoryItem->
dirPath() ) );
364 mLayout->addWidget( mDirectoryWidget );
367QgsBrowserPropertiesDialog::QgsBrowserPropertiesDialog(
const QString &settingsSection, QWidget *parent )
369 , mSettingsSection( settingsSection )
380 mPropertiesWidget = QgsBrowserPropertiesWidget::createWidget( item, context,
this );
381 mLayout->addWidget( mPropertiesWidget );
390QgsDockBrowserTreeView::QgsDockBrowserTreeView( QWidget *parent )
393 setDragDropMode( QTreeView::DragDrop );
394 setSelectionMode( QAbstractItemView::ExtendedSelection );
395 setContextMenuPolicy( Qt::CustomContextMenu );
396 setHeaderHidden(
true );
397 setDropIndicatorShown(
true );
400void QgsDockBrowserTreeView::setAction( QDropEvent *e )
404 if ( e->mimeData()->hasFormat( u
"application/qgis.layertreemodeldata"_s ) && e->mimeData()->hasFormat( u
"application/x-vnd.qgis.qgis.uri"_s ) )
406 e->setDropAction( Qt::CopyAction );
410void QgsDockBrowserTreeView::dragEnterEvent( QDragEnterEvent *e )
419void QgsDockBrowserTreeView::dragMoveEvent( QDragMoveEvent *e )
430 QTreeView::dragMoveEvent( e );
434 if ( !e->mimeData()->hasFormat( u
"application/x-vnd.qgis.qgis.uri"_s ) )
441void QgsDockBrowserTreeView::dropEvent( QDropEvent *e )
444 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.