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,
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 if ( !url.fragment().isEmpty() && url.toString().startsWith( QLatin1Char(
'#' ) ) )
297 mMetadataTextBrowser->scrollToAnchor( url.fragment() );
300 const QFileInfo file( url.toLocalFile() );
301 if ( file.exists() && !file.isDir() )
304 QDesktopServices::openUrl( url );
307void QgsBrowserLayerProperties::loadAttributeTable()
318 layerCache->setParent( tableModel );
319 tableModel->setParent( mAttributeTableFilterModel );
321 mAttributeTable->setModel( mAttributeTableFilterModel );
323 QFont font = mAttributeTable->font();
324 int fontSize = font.pointSize();
326 fontSize = std::max( fontSize - 1, 8 );
328 fontSize = std::max( fontSize - 2, 6 );
330 font.setPointSize( fontSize );
331 mAttributeTable->setFont( font );
334 mAttributeTable->resizeColumnsToContents();
335 mAttributeTable->resizeRowsToContents();
336 mAttributeTable->verticalHeader()->setVisible(
false );
337 mAttributeTable->setAlternatingRowColors(
true );
340QgsBrowserDirectoryProperties::QgsBrowserDirectoryProperties( QWidget *parent )
341 : QgsBrowserPropertiesWidget( parent )
346 mPathLabel =
new QgsBrowserPropertiesWrapLabel( QString(), mHeaderWidget );
347 mHeaderGridLayout->addItem(
new QWidgetItem( mPathLabel ), 0, 1 );
350void QgsBrowserDirectoryProperties::setItem(
QgsDataItem *item )
356 mPathLabel->setText( QDir::toNativeSeparators( directoryItem->
dirPath() ) );
358 mLayout->addWidget( mDirectoryWidget );
361QgsBrowserPropertiesDialog::QgsBrowserPropertiesDialog(
const QString &settingsSection, QWidget *parent )
363 , mSettingsSection( settingsSection )
374 mPropertiesWidget = QgsBrowserPropertiesWidget::createWidget( item, context,
this );
375 mLayout->addWidget( mPropertiesWidget );
384QgsDockBrowserTreeView::QgsDockBrowserTreeView( QWidget *parent ) :
QgsBrowserTreeView( parent )
386 setDragDropMode( QTreeView::DragDrop );
387 setSelectionMode( QAbstractItemView::ExtendedSelection );
388 setContextMenuPolicy( Qt::CustomContextMenu );
389 setHeaderHidden(
true );
390 setDropIndicatorShown(
true );
394void QgsDockBrowserTreeView::setAction( QDropEvent *e )
398 if ( e->mimeData()->hasFormat( QStringLiteral(
"application/qgis.layertreemodeldata" ) ) &&
399 e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
401 e->setDropAction( Qt::CopyAction );
405void QgsDockBrowserTreeView::dragEnterEvent( QDragEnterEvent *e )
414void QgsDockBrowserTreeView::dragMoveEvent( QDragMoveEvent *e )
425 QTreeView::dragMoveEvent( e );
429 if ( !e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
436void QgsDockBrowserTreeView::dropEvent( QDropEvent *e )
439 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.