24 #include <QAbstractTextDocumentLayout> 
   25 #include <QHeaderView> 
   28 #include <QToolButton> 
   29 #include <QFileDialog> 
   30 #include <QPlainTextDocumentLayout> 
   31 #include <QSortFilterProxyModel> 
   32 #include <QDesktopServices> 
   33 #include <QDragEnterEvent> 
   41 #include "qgssettings.h" 
   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   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 );
 
  240   mAttributeTable->setModel( 
nullptr );
 
  241   if ( mAttributeTableFilterModel )
 
  244     mAttributeTableFilterModel->deleteLater();
 
  245     mAttributeTableFilterModel = 
nullptr;
 
  247   if ( mLayer && mLayer->isValid() )
 
  250     mLayer->loadDefaultMetadata( ok );
 
  251     layerMetadata = mLayer->htmlMetadata();
 
  253     mMapCanvas->setDestinationCrs( mLayer->crs() );
 
  254     mMapCanvas->setLayers( QList< QgsMapLayer * >() << mLayer.get() );
 
  255     mMapCanvas->zoomToFullExtent();
 
  259       mTabWidget->removeTab( mTabWidget->indexOf( mAttributesTab ) );
 
  260       mAttributesTab = 
nullptr;
 
  265   mMetadataTextBrowser->document()->setDefaultStyleSheet( myStyle );
 
  266   mMetadataTextBrowser->setHtml( layerMetadata );
 
  268   if ( mNoticeLabel->text().isEmpty() )
 
  270     mNoticeLabel->hide();
 
  274 void QgsBrowserLayerProperties::setCondensedMode( 
bool )
 
  279 void QgsBrowserLayerProperties::urlClicked( 
const QUrl &url )
 
  281   QFileInfo file( url.toLocalFile() );
 
  282   if ( file.exists() && !file.isDir() )
 
  285     QDesktopServices::openUrl( url );
 
  288 void QgsBrowserLayerProperties::loadAttributeTable()
 
  299   layerCache->setParent( tableModel );
 
  300   tableModel->setParent( mAttributeTableFilterModel );
 
  302   mAttributeTable->setModel( mAttributeTableFilterModel );
 
  304   QFont font = mAttributeTable->font();
 
  305   int fontSize = font.pointSize();
 
  307   fontSize = std::max( fontSize - 1, 8 ); 
 
  309   fontSize = std::max( fontSize - 2, 6 );
 
  311   font.setPointSize( fontSize );
 
  312   mAttributeTable->setFont( font );
 
  315   mAttributeTable->resizeColumnsToContents();
 
  316   mAttributeTable->resizeRowsToContents();
 
  317   mAttributeTable->verticalHeader()->setVisible( 
false ); 
 
  318   mAttributeTable->setAlternatingRowColors( 
true );
 
  321 QgsBrowserDirectoryProperties::QgsBrowserDirectoryProperties( QWidget *parent )
 
  322   : QgsBrowserPropertiesWidget( parent )
 
  327   mPathLabel = 
new QgsBrowserPropertiesWrapLabel( QString(), mHeaderWidget );
 
  328   mHeaderGridLayout->addItem( 
new QWidgetItem( mPathLabel ), 0, 1 );
 
  331 void QgsBrowserDirectoryProperties::setItem( 
QgsDataItem *item )
 
  337   mPathLabel->setText( QDir::toNativeSeparators( directoryItem->
dirPath() ) );
 
  339   mLayout->addWidget( mDirectoryWidget );
 
  342 QgsBrowserPropertiesDialog::QgsBrowserPropertiesDialog( 
const QString &settingsSection, QWidget *parent )
 
  344   , mSettingsSection( settingsSection )
 
  355   mPropertiesWidget = QgsBrowserPropertiesWidget::createWidget( item, context, 
this );
 
  356   mLayout->addWidget( mPropertiesWidget );
 
  365 QgsDockBrowserTreeView::QgsDockBrowserTreeView( QWidget *parent ) : 
QgsBrowserTreeView( parent )
 
  367   setDragDropMode( QTreeView::DragDrop ); 
 
  368   setSelectionMode( QAbstractItemView::ExtendedSelection );
 
  369   setContextMenuPolicy( Qt::CustomContextMenu );
 
  370   setHeaderHidden( 
true );
 
  371   setDropIndicatorShown( 
true );
 
  375 void QgsDockBrowserTreeView::setAction( QDropEvent *e )
 
  379   if ( e->mimeData()->hasFormat( QStringLiteral( 
"application/qgis.layertreemodeldata" ) ) &&
 
  380        e->mimeData()->hasFormat( QStringLiteral( 
"application/x-vnd.qgis.qgis.uri" ) ) )
 
  382     e->setDropAction( Qt::CopyAction );
 
  386 void QgsDockBrowserTreeView::dragEnterEvent( QDragEnterEvent *e )
 
  395 void QgsDockBrowserTreeView::dragMoveEvent( QDragMoveEvent *e )
 
  406   QTreeView::dragMoveEvent( e );
 
  410   if ( !e->mimeData()->hasFormat( QStringLiteral( 
"application/x-vnd.qgis.qgis.uri" ) ) )
 
  417 void QgsDockBrowserTreeView::dropEvent( QDropEvent *e )
 
  420   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 QgsGui * instance()
Returns a pointer to the singleton instance.
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
Added in 3.18.
@ VectorTileLayer
Added in 3.14.
@ AnnotationLayer
Contains freeform, georeferenced annotations. Added in QGIS 3.16.
#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.