21#include "moc_qgsbrowserdockwidget_p.cpp"
25#include <QAbstractTextDocumentLayout>
31#include <QPlainTextDocumentLayout>
32#include <QSortFilterProxyModel>
33#include <QDesktopServices>
34#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,
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, [=] {
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" );
187 QgsDebugMsgLevel( QStringLiteral(
"creating temporary layer using path %1" ).arg( layerItem->
path() ), 2 );
196 mLayer = std::make_unique<QgsRasterLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
204 options.skipCrsValidation =
true;
205 mLayer = std::make_unique<QgsMeshLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
213 options.skipCrsValidation =
true;
214 mLayer = std::make_unique<QgsVectorLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
221 mLayer = std::make_unique<QgsVectorTileLayer>( layerItem->
uri(), layerItem->
name() );
229 options.skipCrsValidation =
true;
230 mLayer = std::make_unique<QgsPointCloudLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
238 options.skipCrsValidation =
true;
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;
277 mMetadataTextBrowser->document()->setDefaultStyleSheet( myStyle );
278 mMetadataTextBrowser->setHtml( layerMetadata );
280 if ( mNoticeLabel->text().isEmpty() )
282 mNoticeLabel->hide();
286void QgsBrowserLayerProperties::setCondensedMode(
bool )
290void QgsBrowserLayerProperties::urlClicked(
const QUrl &url )
292 if ( !url.fragment().isEmpty() && url.toString().startsWith( QLatin1Char(
'#' ) ) )
294 mMetadataTextBrowser->scrollToAnchor( url.fragment() );
297 const QFileInfo file( url.toLocalFile() );
298 if ( file.exists() && !file.isDir() )
301 QDesktopServices::openUrl( url );
304void QgsBrowserLayerProperties::loadAttributeTable()
315 layerCache->setParent( tableModel );
316 tableModel->setParent( mAttributeTableFilterModel );
318 mAttributeTable->setModel( mAttributeTableFilterModel );
320 QFont font = mAttributeTable->font();
321 int fontSize = font.pointSize();
323 fontSize = std::max( fontSize - 1, 8 );
325 fontSize = std::max( fontSize - 2, 6 );
327 font.setPointSize( fontSize );
328 mAttributeTable->setFont( font );
331 mAttributeTable->resizeColumnsToContents();
332 mAttributeTable->resizeRowsToContents();
333 mAttributeTable->verticalHeader()->setVisible(
false );
334 mAttributeTable->setAlternatingRowColors(
true );
337QgsBrowserDirectoryProperties::QgsBrowserDirectoryProperties( QWidget *parent )
338 : QgsBrowserPropertiesWidget( parent )
343 mPathLabel =
new QgsBrowserPropertiesWrapLabel( QString(), mHeaderWidget );
344 mHeaderGridLayout->addItem(
new QWidgetItem( mPathLabel ), 0, 1 );
347void QgsBrowserDirectoryProperties::setItem(
QgsDataItem *item )
353 mPathLabel->setText( QDir::toNativeSeparators( directoryItem->
dirPath() ) );
355 mLayout->addWidget( mDirectoryWidget );
358QgsBrowserPropertiesDialog::QgsBrowserPropertiesDialog(
const QString &settingsSection, QWidget *parent )
360 , mSettingsSection( settingsSection )
371 mPropertiesWidget = QgsBrowserPropertiesWidget::createWidget( item, context,
this );
372 mLayout->addWidget( mPropertiesWidget );
381QgsDockBrowserTreeView::QgsDockBrowserTreeView( QWidget *parent )
384 setDragDropMode( QTreeView::DragDrop );
385 setSelectionMode( QAbstractItemView::ExtendedSelection );
386 setContextMenuPolicy( Qt::CustomContextMenu );
387 setHeaderHidden(
true );
388 setDropIndicatorShown(
true );
391void QgsDockBrowserTreeView::setAction( QDropEvent *e )
395 if ( e->mimeData()->hasFormat( QStringLiteral(
"application/qgis.layertreemodeldata" ) ) && e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
397 e->setDropAction( Qt::CopyAction );
401void QgsDockBrowserTreeView::dragEnterEvent( QDragEnterEvent *e )
410void QgsDockBrowserTreeView::dragMoveEvent( QDragMoveEvent *e )
421 QTreeView::dragMoveEvent( e );
425 if ( !e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
432void QgsDockBrowserTreeView::dropEvent( QDropEvent *e )
435 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.
QString providerKey() const
Returns the provider key that created this item (e.g.
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.
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.