24 #include <QAbstractTextDocumentLayout> 
   25 #include <QHeaderView> 
   28 #include <QToolButton> 
   29 #include <QFileDialog> 
   30 #include <QPlainTextDocumentLayout> 
   31 #include <QSortFilterProxyModel> 
   32 #include <QDesktopServices> 
   33 #include <QDragEnterEvent> 
   44 #include "qgsnative.h" 
   60 QgsBrowserPropertiesWrapLabel::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 );
 
   76 void QgsBrowserPropertiesWrapLabel::adjustHeight( QSizeF size )
 
   78   const int height = 
static_cast<int>( size.height() ) + 2 * frameWidth();
 
   79   setMinimumHeight( height );
 
   80   setMaximumHeight( height );
 
   83 QgsBrowserPropertiesWidget::QgsBrowserPropertiesWidget( QWidget *parent )
 
   88 void 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 );
 
  109     QWidget *paramWidget = 
nullptr;
 
  113       paramWidget = provider->createParamWidget( item, context );
 
  128       propertiesWidget = 
new QgsBrowserPropertiesWidget( parent );
 
  129       propertiesWidget->setWidget( paramWidget );
 
  133       propertiesWidget = 
new QgsBrowserLayerProperties( parent );
 
  134       propertiesWidget->setItem( item );
 
  137   return propertiesWidget;
 
  140 QgsBrowserLayerProperties::QgsBrowserLayerProperties( QWidget *parent )
 
  141   : QgsBrowserPropertiesWidget( parent )
 
  146   mMetadataTextBrowser->setOpenLinks( 
false );
 
  147   connect( mMetadataTextBrowser, &QTextBrowser::anchorClicked, 
this, &QgsBrowserLayerProperties::urlClicked );
 
  149   mMapCanvas->setProperty( 
"browser_canvas", 
true );
 
  150   mMapCanvas->setLayers( QList< QgsMapLayer * >() );
 
  152   mMapCanvas->freeze( 
true );
 
  154   connect( mTabWidget, &QTabWidget::currentChanged, 
this, [ = ]
 
  156     if ( mTabWidget->currentWidget() == mPreviewTab && mMapCanvas->isFrozen() )
 
  158       mMapCanvas->freeze( false );
 
  159       mMapCanvas->refresh();
 
  161     else if ( mTabWidget->currentWidget() == mAttributesTab )
 
  163       if ( ! mAttributeTableFilterModel )
 
  164         loadAttributeTable();
 
  169 void QgsBrowserLayerProperties::setItem( 
QgsDataItem *item )
 
  171   QgsLayerItem *layerItem = qobject_cast<QgsLayerItem *>( item );
 
  175   mNoticeLabel->clear();
 
  178   QString layerMetadata = tr( 
"Error" );
 
  185   QgsDebugMsg( QStringLiteral( 
"creating temporary layer using path %1" ).arg( layerItem->
path() ) );
 
  190       QgsDebugMsg( QStringLiteral( 
"creating raster layer" ) );
 
  194       mLayer = std::make_unique< QgsRasterLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
 
  200       QgsDebugMsg( QStringLiteral( 
"creating mesh layer" ) );
 
  202       options.skipCrsValidation = 
true;
 
  203       mLayer = std::make_unique < QgsMeshLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
 
  209       QgsDebugMsg( QStringLiteral( 
"creating vector layer" ) );
 
  211       options.skipCrsValidation = 
true;
 
  212       mLayer = std::make_unique < QgsVectorLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
 
  219       mLayer = std::make_unique< QgsVectorTileLayer >( layerItem->
uri(), layerItem->
name() );
 
  227       options.skipCrsValidation = 
true;
 
  228       mLayer = std::make_unique< QgsPointCloudLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
 
  241   mAttributeTable->setModel( 
nullptr );
 
  242   if ( mAttributeTableFilterModel )
 
  245     mAttributeTableFilterModel->deleteLater();
 
  246     mAttributeTableFilterModel = 
nullptr;
 
  248   if ( mLayer && mLayer->isValid() )
 
  251     mLayer->loadDefaultMetadata( ok );
 
  252     layerMetadata = mLayer->htmlMetadata();
 
  254     mMapCanvas->setDestinationCrs( mLayer->crs() );
 
  255     mMapCanvas->setLayers( QList< QgsMapLayer * >() << mLayer.get() );
 
  256     mMapCanvas->zoomToFullExtent();
 
  260       mTabWidget->removeTab( mTabWidget->indexOf( mAttributesTab ) );
 
  261       mAttributesTab = 
nullptr;
 
  266   mMetadataTextBrowser->document()->setDefaultStyleSheet( myStyle );
 
  267   mMetadataTextBrowser->setHtml( layerMetadata );
 
  269   if ( mNoticeLabel->text().isEmpty() )
 
  271     mNoticeLabel->hide();
 
  275 void QgsBrowserLayerProperties::setCondensedMode( 
bool )
 
  280 void QgsBrowserLayerProperties::urlClicked( 
const QUrl &url )
 
  282   const QFileInfo file( url.toLocalFile() );
 
  283   if ( file.exists() && !file.isDir() )
 
  286     QDesktopServices::openUrl( url );
 
  289 void QgsBrowserLayerProperties::loadAttributeTable()
 
  300   layerCache->setParent( tableModel );
 
  301   tableModel->setParent( mAttributeTableFilterModel );
 
  303   mAttributeTable->setModel( mAttributeTableFilterModel );
 
  305   QFont font = mAttributeTable->font();
 
  306   int fontSize = font.pointSize();
 
  308   fontSize = std::max( fontSize - 1, 8 ); 
 
  310   fontSize = std::max( fontSize - 2, 6 );
 
  312   font.setPointSize( fontSize );
 
  313   mAttributeTable->setFont( font );
 
  316   mAttributeTable->resizeColumnsToContents();
 
  317   mAttributeTable->resizeRowsToContents();
 
  318   mAttributeTable->verticalHeader()->setVisible( 
false ); 
 
  319   mAttributeTable->setAlternatingRowColors( 
true );
 
  322 QgsBrowserDirectoryProperties::QgsBrowserDirectoryProperties( QWidget *parent )
 
  323   : QgsBrowserPropertiesWidget( parent )
 
  328   mPathLabel = 
new QgsBrowserPropertiesWrapLabel( QString(), mHeaderWidget );
 
  329   mHeaderGridLayout->addItem( 
new QWidgetItem( mPathLabel ), 0, 1 );
 
  332 void QgsBrowserDirectoryProperties::setItem( 
QgsDataItem *item )
 
  338   mPathLabel->setText( QDir::toNativeSeparators( directoryItem->
dirPath() ) );
 
  340   mLayout->addWidget( mDirectoryWidget );
 
  343 QgsBrowserPropertiesDialog::QgsBrowserPropertiesDialog( 
const QString &settingsSection, QWidget *parent )
 
  345   , mSettingsSection( settingsSection )
 
  356   mPropertiesWidget = QgsBrowserPropertiesWidget::createWidget( item, context, 
this );
 
  357   mLayout->addWidget( mPropertiesWidget );
 
  366 QgsDockBrowserTreeView::QgsDockBrowserTreeView( QWidget *parent ) : 
QgsBrowserTreeView( parent )
 
  368   setDragDropMode( QTreeView::DragDrop ); 
 
  369   setSelectionMode( QAbstractItemView::ExtendedSelection );
 
  370   setContextMenuPolicy( Qt::CustomContextMenu );
 
  371   setHeaderHidden( 
true );
 
  372   setDropIndicatorShown( 
true );
 
  376 void QgsDockBrowserTreeView::setAction( QDropEvent *e )
 
  380   if ( e->mimeData()->hasFormat( QStringLiteral( 
"application/qgis.layertreemodeldata" ) ) &&
 
  381        e->mimeData()->hasFormat( QStringLiteral( 
"application/x-vnd.qgis.qgis.uri" ) ) )
 
  383     e->setDropAction( Qt::CopyAction );
 
  387 void QgsDockBrowserTreeView::dragEnterEvent( QDragEnterEvent *e )
 
  396 void QgsDockBrowserTreeView::dragMoveEvent( QDragMoveEvent *e )
 
  407   QTreeView::dragMoveEvent( e );
 
  411   if ( !e->mimeData()->hasFormat( QStringLiteral( 
"application/x-vnd.qgis.qgis.uri" ) ) )
 
  418 void QgsDockBrowserTreeView::dropEvent( QDropEvent *e )
 
  421   QTreeView::dropEvent( e );
 
@ Layer
Represents a map layer.
 
@ Custom
Custom item type.
 
@ Directory
Represents a file directory.
 
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.
 
QgsMapLayerType mapLayerType() const
Returns QgsMapLayerType.
 
QString providerKey() const
Returns provider key.
 
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.
 
QgsMapLayerType
Types of layers that can be added to a map.
 
@ PointCloudLayer
Point cloud layer. Added in QGIS 3.18.
 
@ MeshLayer
Mesh layer. Added in QGIS 3.2.
 
@ VectorLayer
Vector layer.
 
@ RasterLayer
Raster layer.
 
@ GroupLayer
Composite group layer. Added in QGIS 3.24.
 
@ VectorTileLayer
Vector tile layer. Added in QGIS 3.14.
 
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
 
@ PluginLayer
Plugin based layer.
 
#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 vector layers.