24#include <QAbstractTextDocumentLayout> 
   30#include <QPlainTextDocumentLayout> 
   31#include <QSortFilterProxyModel> 
   32#include <QDesktopServices> 
   33#include <QDragEnterEvent> 
   60QgsBrowserPropertiesWrapLabel::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 );
 
   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, [ = ]
 
  159    if ( mTabWidget->currentWidget() == mPreviewTab && mMapCanvas->isFrozen() )
 
  161      mMapCanvas->freeze( false );
 
  162      mMapCanvas->refresh();
 
  164    else if ( mTabWidget->currentWidget() == mAttributesTab )
 
  166      if ( ! mAttributeTableFilterModel )
 
  167        loadAttributeTable();
 
  172void QgsBrowserLayerProperties::setItem( 
QgsDataItem *item )
 
  174  QgsLayerItem *layerItem = qobject_cast<QgsLayerItem *>( item );
 
  178  mNoticeLabel->clear();
 
  181  QString layerMetadata = tr( 
"Error" );
 
  188  QgsDebugMsgLevel( QStringLiteral( 
"creating temporary layer using path %1" ).arg( layerItem->
path() ), 2 );
 
  191    case Qgis::LayerType::Raster:
 
  197      mLayer = std::make_unique< QgsRasterLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
 
  201    case Qgis::LayerType::Mesh:
 
  205      options.skipCrsValidation = 
true;
 
  206      mLayer = std::make_unique < QgsMeshLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
 
  210    case Qgis::LayerType::Vector:
 
  214      options.skipCrsValidation = 
true;
 
  215      mLayer = std::make_unique < QgsVectorLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
 
  219    case Qgis::LayerType::VectorTile:
 
  222      mLayer = std::make_unique< QgsVectorTileLayer >( layerItem->
uri(), layerItem->
name() );
 
  226    case Qgis::LayerType::PointCloud:
 
  230      options.skipCrsValidation = 
true;
 
  231      mLayer = std::make_unique< QgsPointCloudLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
 
  235    case Qgis::LayerType::Plugin:
 
  236    case Qgis::LayerType::Annotation:
 
  237    case Qgis::LayerType::Group:
 
  244  mAttributeTable->setModel( 
nullptr );
 
  245  if ( mAttributeTableFilterModel )
 
  248    mAttributeTableFilterModel->deleteLater();
 
  249    mAttributeTableFilterModel = 
nullptr;
 
  251  if ( mLayer && mLayer->isValid() )
 
  254    mLayer->loadDefaultMetadata( ok );
 
  255    layerMetadata = mLayer->htmlMetadata();
 
  257    mMapCanvas->setDestinationCrs( mLayer->crs() );
 
  258    mMapCanvas->setLayers( QList< QgsMapLayer * >() << mLayer.get() );
 
  259    mMapCanvas->zoomToFullExtent();
 
  261    if ( mAttributesTab && mLayer->type() != Qgis::LayerType::Vector )
 
  263      mTabWidget->removeTab( mTabWidget->indexOf( mAttributesTab ) );
 
  264      mAttributesTab = 
nullptr;
 
  269  mMetadataTextBrowser->document()->setDefaultStyleSheet( myStyle );
 
  270  mMetadataTextBrowser->setHtml( layerMetadata );
 
  272  if ( mNoticeLabel->text().isEmpty() )
 
  274    mNoticeLabel->hide();
 
  278void QgsBrowserLayerProperties::setCondensedMode( 
bool )
 
  283void QgsBrowserLayerProperties::urlClicked( 
const QUrl &url )
 
  285  const QFileInfo file( url.toLocalFile() );
 
  286  if ( file.exists() && !file.isDir() )
 
  289    QDesktopServices::openUrl( url );
 
  292void QgsBrowserLayerProperties::loadAttributeTable()
 
  294  if ( !mLayer || !mLayer->isValid() || mLayer->type() != Qgis::LayerType::Vector )
 
  303  layerCache->setParent( tableModel );
 
  304  tableModel->setParent( mAttributeTableFilterModel );
 
  306  mAttributeTable->setModel( mAttributeTableFilterModel );
 
  308  QFont font = mAttributeTable->font();
 
  309  int fontSize = font.pointSize();
 
  311  fontSize = std::max( fontSize - 1, 8 ); 
 
  313  fontSize = std::max( fontSize - 2, 6 );
 
  315  font.setPointSize( fontSize );
 
  316  mAttributeTable->setFont( font );
 
  319  mAttributeTable->resizeColumnsToContents();
 
  320  mAttributeTable->resizeRowsToContents();
 
  321  mAttributeTable->verticalHeader()->setVisible( 
false ); 
 
  322  mAttributeTable->setAlternatingRowColors( 
true );
 
  325QgsBrowserDirectoryProperties::QgsBrowserDirectoryProperties( QWidget *parent )
 
  326  : QgsBrowserPropertiesWidget( parent )
 
  331  mPathLabel = 
new QgsBrowserPropertiesWrapLabel( QString(), mHeaderWidget );
 
  332  mHeaderGridLayout->addItem( 
new QWidgetItem( mPathLabel ), 0, 1 );
 
  335void QgsBrowserDirectoryProperties::setItem( 
QgsDataItem *item )
 
  341  mPathLabel->setText( QDir::toNativeSeparators( directoryItem->
dirPath() ) );
 
  343  mLayout->addWidget( mDirectoryWidget );
 
  346QgsBrowserPropertiesDialog::QgsBrowserPropertiesDialog( 
const QString &settingsSection, QWidget *parent )
 
  348  , mSettingsSection( settingsSection )
 
  359  mPropertiesWidget = QgsBrowserPropertiesWidget::createWidget( item, context, 
this );
 
  360  mLayout->addWidget( mPropertiesWidget );
 
  369QgsDockBrowserTreeView::QgsDockBrowserTreeView( QWidget *parent ) : 
QgsBrowserTreeView( parent )
 
  371  setDragDropMode( QTreeView::DragDrop ); 
 
  372  setSelectionMode( QAbstractItemView::ExtendedSelection );
 
  373  setContextMenuPolicy( Qt::CustomContextMenu );
 
  374  setHeaderHidden( 
true );
 
  375  setDropIndicatorShown( 
true );
 
  379void QgsDockBrowserTreeView::setAction( QDropEvent *e )
 
  383  if ( e->mimeData()->hasFormat( QStringLiteral( 
"application/qgis.layertreemodeldata" ) ) &&
 
  384       e->mimeData()->hasFormat( QStringLiteral( 
"application/x-vnd.qgis.qgis.uri" ) ) )
 
  386    e->setDropAction( Qt::CopyAction );
 
  390void QgsDockBrowserTreeView::dragEnterEvent( QDragEnterEvent *e )
 
  399void QgsDockBrowserTreeView::dragMoveEvent( QDragMoveEvent *e )
 
  410  QTreeView::dragMoveEvent( e );
 
  414  if ( !e->mimeData()->hasFormat( QStringLiteral( 
"application/x-vnd.qgis.qgis.uri" ) ) )
 
  421void QgsDockBrowserTreeView::dropEvent( QDropEvent *e )
 
  424  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.
 
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 vector layers.