24#include <QAbstractTextDocumentLayout>
30#include <QPlainTextDocumentLayout>
31#include <QSortFilterProxyModel>
32#include <QDesktopServices>
33#include <QDragEnterEvent>
60QgsBrowserPropertiesWrapLabel::QgsBrowserPropertiesWrapLabel(
const QString &text, QWidget *parent )
61 : QTextEdit( text, parent )
64 setFrameStyle( QFrame::NoFrame );
65 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
66 QPalette
pal = palette();
67 pal.setColor( QPalette::Base, Qt::transparent );
69 setLineWrapMode( QTextEdit::WidgetWidth );
70 setWordWrapMode( QTextOption::WrapAnywhere );
71 connect( document()->documentLayout(), &QAbstractTextDocumentLayout::documentSizeChanged,
72 this, &QgsBrowserPropertiesWrapLabel::adjustHeight );
73 setMaximumHeight( 20 );
76void QgsBrowserPropertiesWrapLabel::adjustHeight( QSizeF size )
78 const int height =
static_cast<int>( size.height() ) + 2 * frameWidth();
79 setMinimumHeight( height );
80 setMaximumHeight( height );
83QgsBrowserPropertiesWidget::QgsBrowserPropertiesWidget( QWidget *parent )
88void QgsBrowserPropertiesWidget::setWidget( QWidget *paramWidget )
90 QVBoxLayout *layout =
new QVBoxLayout(
this );
91 layout->setContentsMargins( 0, 0, 0, 0 );
92 paramWidget->setParent(
this );
93 layout->addWidget( paramWidget );
98 QgsBrowserPropertiesWidget *propertiesWidget =
nullptr;
103 propertiesWidget =
new QgsBrowserDirectoryProperties( parent );
104 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, [ = ]
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 );
205 options.skipCrsValidation =
true;
206 mLayer = std::make_unique < QgsMeshLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
214 options.skipCrsValidation =
true;
215 mLayer = std::make_unique < QgsVectorLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
222 mLayer = std::make_unique< QgsVectorTileLayer >( layerItem->
uri(), layerItem->
name() );
230 options.skipCrsValidation =
true;
231 mLayer = std::make_unique< QgsPointCloudLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
239 options.skipCrsValidation =
true;
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;
278 mMetadataTextBrowser->document()->setDefaultStyleSheet( myStyle );
279 mMetadataTextBrowser->setHtml( layerMetadata );
281 if ( mNoticeLabel->text().isEmpty() )
283 mNoticeLabel->hide();
287void QgsBrowserLayerProperties::setCondensedMode(
bool )
292void QgsBrowserLayerProperties::urlClicked(
const QUrl &url )
294 const QFileInfo file( url.toLocalFile() );
295 if ( file.exists() && !file.isDir() )
298 QDesktopServices::openUrl( url );
301void QgsBrowserLayerProperties::loadAttributeTable()
312 layerCache->setParent( tableModel );
313 tableModel->setParent( mAttributeTableFilterModel );
315 mAttributeTable->setModel( mAttributeTableFilterModel );
317 QFont font = mAttributeTable->font();
318 int fontSize = font.pointSize();
320 fontSize = std::max( fontSize - 1, 8 );
322 fontSize = std::max( fontSize - 2, 6 );
324 font.setPointSize( fontSize );
325 mAttributeTable->setFont( font );
328 mAttributeTable->resizeColumnsToContents();
329 mAttributeTable->resizeRowsToContents();
330 mAttributeTable->verticalHeader()->setVisible(
false );
331 mAttributeTable->setAlternatingRowColors(
true );
334QgsBrowserDirectoryProperties::QgsBrowserDirectoryProperties( QWidget *parent )
335 : QgsBrowserPropertiesWidget( parent )
340 mPathLabel =
new QgsBrowserPropertiesWrapLabel( QString(), mHeaderWidget );
341 mHeaderGridLayout->addItem(
new QWidgetItem( mPathLabel ), 0, 1 );
344void QgsBrowserDirectoryProperties::setItem(
QgsDataItem *item )
350 mPathLabel->setText( QDir::toNativeSeparators( directoryItem->
dirPath() ) );
352 mLayout->addWidget( mDirectoryWidget );
355QgsBrowserPropertiesDialog::QgsBrowserPropertiesDialog(
const QString &settingsSection, QWidget *parent )
357 , mSettingsSection( settingsSection )
368 mPropertiesWidget = QgsBrowserPropertiesWidget::createWidget( item, context,
this );
369 mLayout->addWidget( mPropertiesWidget );
378QgsDockBrowserTreeView::QgsDockBrowserTreeView( QWidget *parent ) :
QgsBrowserTreeView( parent )
380 setDragDropMode( QTreeView::DragDrop );
381 setSelectionMode( QAbstractItemView::ExtendedSelection );
382 setContextMenuPolicy( Qt::CustomContextMenu );
383 setHeaderHidden(
true );
384 setDropIndicatorShown(
true );
388void QgsDockBrowserTreeView::setAction( QDropEvent *e )
392 if ( e->mimeData()->hasFormat( QStringLiteral(
"application/qgis.layertreemodeldata" ) ) &&
393 e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
395 e->setDropAction( Qt::CopyAction );
399void QgsDockBrowserTreeView::dragEnterEvent( QDragEnterEvent *e )
408void QgsDockBrowserTreeView::dragMoveEvent( QDragMoveEvent *e )
419 QTreeView::dragMoveEvent( e );
423 if ( !e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
430void QgsDockBrowserTreeView::dropEvent( QDropEvent *e )
433 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 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...
The QgsBrowserTreeView class extends QTreeView with save/restore tree state 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.
A directory: contains subdirectories and layers.
QString dirPath() const
Returns the full path to the directory the item represents.
This class 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...
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.
QString providerKey() const
Returns provider key.
Qgis::LayerType mapLayerType() const
Returns the associated map layer type.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsCoordinateTransformContext transformContext
This class caches features of a given QgsVectorLayer.
void setCacheGeometry(bool cacheGeometry)
Enable or disable the caching of geometries.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH
#define QgsDebugMsgLevel(str, level)
Setting options for loading mesh layers.
Setting options for loading point cloud layers.
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.
Setting options for loading vector layers.