24#include <QAbstractTextDocumentLayout>
30#include <QPlainTextDocumentLayout>
31#include <QSortFilterProxyModel>
32#include <QDesktopServices>
33#include <QDragEnterEvent>
61QgsBrowserPropertiesWrapLabel::QgsBrowserPropertiesWrapLabel(
const QString &text, QWidget *parent )
62 : QTextEdit( text, parent )
65 setFrameStyle( QFrame::NoFrame );
66 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
67 QPalette
pal = palette();
68 pal.setColor( QPalette::Base, Qt::transparent );
70 setLineWrapMode( QTextEdit::WidgetWidth );
71 setWordWrapMode( QTextOption::WrapAnywhere );
72 connect( document()->documentLayout(), &QAbstractTextDocumentLayout::documentSizeChanged,
73 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, [ = ]
160 if ( mTabWidget->currentWidget() == mPreviewTab && mMapCanvas->isFrozen() )
162 mMapCanvas->freeze( false );
163 mMapCanvas->refresh();
165 else if ( mTabWidget->currentWidget() == mAttributesTab )
167 if ( ! mAttributeTableFilterModel )
168 loadAttributeTable();
173void QgsBrowserLayerProperties::setItem(
QgsDataItem *item )
175 QgsLayerItem *layerItem = qobject_cast<QgsLayerItem *>( item );
179 mNoticeLabel->clear();
182 QString layerMetadata = tr(
"Error" );
189 QgsDebugMsgLevel( QStringLiteral(
"creating temporary layer using path %1" ).arg( layerItem->
path() ), 2 );
198 mLayer = std::make_unique< QgsRasterLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
206 options.skipCrsValidation =
true;
207 mLayer = std::make_unique < QgsMeshLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
215 options.skipCrsValidation =
true;
216 mLayer = std::make_unique < QgsVectorLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
223 mLayer = std::make_unique< QgsVectorTileLayer >( layerItem->
uri(), layerItem->
name() );
231 options.skipCrsValidation =
true;
232 mLayer = std::make_unique< QgsPointCloudLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
240 options.skipCrsValidation =
true;
241 mLayer = std::make_unique< QgsTiledSceneLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
254 mAttributeTable->setModel(
nullptr );
255 if ( mAttributeTableFilterModel )
258 mAttributeTableFilterModel->deleteLater();
259 mAttributeTableFilterModel =
nullptr;
261 if ( mLayer && mLayer->isValid() )
264 mLayer->loadDefaultMetadata( ok );
265 layerMetadata = mLayer->htmlMetadata();
267 mMapCanvas->setDestinationCrs( mLayer->crs() );
268 mMapCanvas->setLayers( QList< QgsMapLayer * >() << mLayer.get() );
269 mMapCanvas->zoomToFullExtent();
273 mTabWidget->removeTab( mTabWidget->indexOf( mAttributesTab ) );
274 mAttributesTab =
nullptr;
279 mMetadataTextBrowser->document()->setDefaultStyleSheet( myStyle );
280 mMetadataTextBrowser->setHtml( layerMetadata );
282 if ( mNoticeLabel->text().isEmpty() )
284 mNoticeLabel->hide();
288void QgsBrowserLayerProperties::setCondensedMode(
bool )
293void QgsBrowserLayerProperties::urlClicked(
const QUrl &url )
295 const QFileInfo file( url.toLocalFile() );
296 if ( file.exists() && !file.isDir() )
299 QDesktopServices::openUrl( url );
302void QgsBrowserLayerProperties::loadAttributeTable()
313 layerCache->setParent( tableModel );
314 tableModel->setParent( mAttributeTableFilterModel );
316 mAttributeTable->setModel( mAttributeTableFilterModel );
318 QFont font = mAttributeTable->font();
319 int fontSize = font.pointSize();
321 fontSize = std::max( fontSize - 1, 8 );
323 fontSize = std::max( fontSize - 2, 6 );
325 font.setPointSize( fontSize );
326 mAttributeTable->setFont( font );
329 mAttributeTable->resizeColumnsToContents();
330 mAttributeTable->resizeRowsToContents();
331 mAttributeTable->verticalHeader()->setVisible(
false );
332 mAttributeTable->setAlternatingRowColors(
true );
335QgsBrowserDirectoryProperties::QgsBrowserDirectoryProperties( QWidget *parent )
336 : QgsBrowserPropertiesWidget( parent )
341 mPathLabel =
new QgsBrowserPropertiesWrapLabel( QString(), mHeaderWidget );
342 mHeaderGridLayout->addItem(
new QWidgetItem( mPathLabel ), 0, 1 );
345void QgsBrowserDirectoryProperties::setItem(
QgsDataItem *item )
351 mPathLabel->setText( QDir::toNativeSeparators( directoryItem->
dirPath() ) );
353 mLayout->addWidget( mDirectoryWidget );
356QgsBrowserPropertiesDialog::QgsBrowserPropertiesDialog(
const QString &settingsSection, QWidget *parent )
358 , mSettingsSection( settingsSection )
369 mPropertiesWidget = QgsBrowserPropertiesWidget::createWidget( item, context,
this );
370 mLayout->addWidget( mPropertiesWidget );
379QgsDockBrowserTreeView::QgsDockBrowserTreeView( QWidget *parent ) :
QgsBrowserTreeView( parent )
381 setDragDropMode( QTreeView::DragDrop );
382 setSelectionMode( QAbstractItemView::ExtendedSelection );
383 setContextMenuPolicy( Qt::CustomContextMenu );
384 setHeaderHidden(
true );
385 setDropIndicatorShown(
true );
389void QgsDockBrowserTreeView::setAction( QDropEvent *e )
393 if ( e->mimeData()->hasFormat( QStringLiteral(
"application/qgis.layertreemodeldata" ) ) &&
394 e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
396 e->setDropAction( Qt::CopyAction );
400void QgsDockBrowserTreeView::dragEnterEvent( QDragEnterEvent *e )
409void QgsDockBrowserTreeView::dragMoveEvent( QDragMoveEvent *e )
420 QTreeView::dragMoveEvent( e );
424 if ( !e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
431void QgsDockBrowserTreeView::dropEvent( QDropEvent *e )
434 QTreeView::dropEvent( e );
@ 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).
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
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.