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, [
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;
 
  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 )
 
  300void QgsBrowserLayerProperties::urlClicked( 
const QUrl &url )
 
  302  if ( !url.fragment().isEmpty() && url.toString().startsWith( QLatin1Char( 
'#' ) ) )
 
  304    mMetadataTextBrowser->scrollToAnchor( url.fragment() );
 
  307  const QFileInfo file( url.toLocalFile() );
 
  308  if ( file.exists() && !file.isDir() )
 
  311    QDesktopServices::openUrl( url );
 
  314void QgsBrowserLayerProperties::loadAttributeTable()
 
  325  layerCache->setParent( tableModel );
 
  326  tableModel->setParent( mAttributeTableFilterModel );
 
  328  mAttributeTable->setModel( mAttributeTableFilterModel );
 
  330  QFont font = mAttributeTable->font();
 
  331  int fontSize = font.pointSize();
 
  333  fontSize = std::max( fontSize - 1, 8 ); 
 
  335  fontSize = std::max( fontSize - 2, 6 );
 
  337  font.setPointSize( fontSize );
 
  338  mAttributeTable->setFont( font );
 
  341  mAttributeTable->resizeColumnsToContents();
 
  342  mAttributeTable->resizeRowsToContents();
 
  343  mAttributeTable->verticalHeader()->setVisible( 
false ); 
 
  344  mAttributeTable->setAlternatingRowColors( 
true );
 
  347QgsBrowserDirectoryProperties::QgsBrowserDirectoryProperties( QWidget *parent )
 
  348  : QgsBrowserPropertiesWidget( parent )
 
  353  mPathLabel = 
new QgsBrowserPropertiesWrapLabel( QString(), mHeaderWidget );
 
  354  mHeaderGridLayout->addItem( 
new QWidgetItem( mPathLabel ), 0, 1 );
 
  357void QgsBrowserDirectoryProperties::setItem( 
QgsDataItem *item )
 
  363  mPathLabel->setText( QDir::toNativeSeparators( directoryItem->
dirPath() ) );
 
  365  mLayout->addWidget( mDirectoryWidget );
 
  368QgsBrowserPropertiesDialog::QgsBrowserPropertiesDialog( 
const QString &settingsSection, QWidget *parent )
 
  370  , mSettingsSection( settingsSection )
 
  381  mPropertiesWidget = QgsBrowserPropertiesWidget::createWidget( item, context, 
this );
 
  382  mLayout->addWidget( mPropertiesWidget );
 
  391QgsDockBrowserTreeView::QgsDockBrowserTreeView( QWidget *parent )
 
  394  setDragDropMode( QTreeView::DragDrop ); 
 
  395  setSelectionMode( QAbstractItemView::ExtendedSelection );
 
  396  setContextMenuPolicy( Qt::CustomContextMenu );
 
  397  setHeaderHidden( 
true );
 
  398  setDropIndicatorShown( 
true );
 
  401void QgsDockBrowserTreeView::setAction( QDropEvent *e )
 
  405  if ( e->mimeData()->hasFormat( QStringLiteral( 
"application/qgis.layertreemodeldata" ) ) && e->mimeData()->hasFormat( QStringLiteral( 
"application/x-vnd.qgis.qgis.uri" ) ) )
 
  407    e->setDropAction( Qt::CopyAction );
 
  411void QgsDockBrowserTreeView::dragEnterEvent( QDragEnterEvent *e )
 
  420void QgsDockBrowserTreeView::dragMoveEvent( QDragMoveEvent *e )
 
  431  QTreeView::dragMoveEvent( e );
 
  435  if ( !e->mimeData()->hasFormat( QStringLiteral( 
"application/x-vnd.qgis.qgis.uri" ) ) )
 
  442void QgsDockBrowserTreeView::dropEvent( QDropEvent *e )
 
  445  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.
 
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.