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"
58 QgsBrowserPropertiesWrapLabel::QgsBrowserPropertiesWrapLabel(
const QString &text, QWidget *parent )
59 : QTextEdit( text, parent )
62 setFrameStyle( QFrame::NoFrame );
63 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
64 QPalette
pal = palette();
65 pal.setColor( QPalette::Base, Qt::transparent );
67 setLineWrapMode( QTextEdit::WidgetWidth );
68 setWordWrapMode( QTextOption::WrapAnywhere );
69 connect( document()->documentLayout(), &QAbstractTextDocumentLayout::documentSizeChanged,
70 this, &QgsBrowserPropertiesWrapLabel::adjustHeight );
71 setMaximumHeight( 20 );
74 void QgsBrowserPropertiesWrapLabel::adjustHeight( QSizeF size )
76 int height =
static_cast<int>( size.height() ) + 2 * frameWidth();
77 setMinimumHeight( height );
78 setMaximumHeight( height );
81 QgsBrowserPropertiesWidget::QgsBrowserPropertiesWidget( QWidget *parent )
86 void QgsBrowserPropertiesWidget::setWidget( QWidget *paramWidget )
88 QVBoxLayout *layout =
new QVBoxLayout(
this );
89 layout->setContentsMargins( 0, 0, 0, 0 );
90 paramWidget->setParent(
this );
91 layout->addWidget( paramWidget );
96 QgsBrowserPropertiesWidget *propertiesWidget =
nullptr;
101 propertiesWidget =
new QgsBrowserDirectoryProperties( parent );
102 propertiesWidget->setItem( item );
107 QWidget *paramWidget =
nullptr;
111 paramWidget = provider->createParamWidget( item, context );
126 propertiesWidget =
new QgsBrowserPropertiesWidget( parent );
127 propertiesWidget->setWidget( paramWidget );
131 propertiesWidget =
new QgsBrowserLayerProperties( parent );
132 propertiesWidget->setItem( item );
135 return propertiesWidget;
138 QgsBrowserLayerProperties::QgsBrowserLayerProperties( QWidget *parent )
139 : QgsBrowserPropertiesWidget( parent )
144 mMetadataTextBrowser->setOpenLinks(
false );
145 connect( mMetadataTextBrowser, &QTextBrowser::anchorClicked,
this, &QgsBrowserLayerProperties::urlClicked );
147 mMapCanvas->setProperty(
"browser_canvas",
true );
148 mMapCanvas->setLayers( QList< QgsMapLayer * >() );
150 mMapCanvas->freeze(
true );
152 connect( mTabWidget, &QTabWidget::currentChanged,
this, [ = ]
154 if ( mTabWidget->currentWidget() == mPreviewTab && mMapCanvas->isFrozen() )
156 mMapCanvas->freeze( false );
157 mMapCanvas->refresh();
159 else if ( mTabWidget->currentWidget() == mAttributesTab )
161 if ( ! mAttributeTableFilterModel )
162 loadAttributeTable();
167 void QgsBrowserLayerProperties::setItem(
QgsDataItem *item )
169 QgsLayerItem *layerItem = qobject_cast<QgsLayerItem *>( item );
173 mNoticeLabel->clear();
176 QString layerMetadata = tr(
"Error" );
183 QgsDebugMsg( QStringLiteral(
"creating temporary layer using path %1" ).arg( layerItem->
path() ) );
188 QgsDebugMsg( QStringLiteral(
"creating raster layer" ) );
192 mLayer = qgis::make_unique< QgsRasterLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
198 QgsDebugMsg( QStringLiteral(
"creating mesh layer" ) );
200 options.skipCrsValidation =
true;
201 mLayer = qgis::make_unique < QgsMeshLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
207 QgsDebugMsg( QStringLiteral(
"creating vector layer" ) );
209 options.skipCrsValidation =
true;
210 mLayer = qgis::make_unique < QgsVectorLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
217 mLayer = qgis::make_unique< QgsVectorTileLayer >( layerItem->
uri(), layerItem->
name() );
225 options.skipCrsValidation =
true;
226 mLayer = qgis::make_unique< QgsPointCloudLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
238 mAttributeTable->setModel(
nullptr );
239 if ( mAttributeTableFilterModel )
242 mAttributeTableFilterModel->deleteLater();
243 mAttributeTableFilterModel =
nullptr;
245 if ( mLayer && mLayer->isValid() )
248 mLayer->loadDefaultMetadata( ok );
249 layerMetadata = mLayer->htmlMetadata();
251 mMapCanvas->setDestinationCrs( mLayer->crs() );
252 mMapCanvas->setLayers( QList< QgsMapLayer * >() << mLayer.get() );
253 mMapCanvas->zoomToFullExtent();
257 mTabWidget->removeTab( mTabWidget->indexOf( mAttributesTab ) );
258 mAttributesTab =
nullptr;
263 mMetadataTextBrowser->document()->setDefaultStyleSheet( myStyle );
264 mMetadataTextBrowser->setHtml( layerMetadata );
266 if ( mNoticeLabel->text().isEmpty() )
268 mNoticeLabel->hide();
272 void QgsBrowserLayerProperties::setCondensedMode(
bool )
277 void QgsBrowserLayerProperties::urlClicked(
const QUrl &url )
279 QFileInfo file( url.toLocalFile() );
280 if ( file.exists() && !file.isDir() )
283 QDesktopServices::openUrl( url );
286 void QgsBrowserLayerProperties::loadAttributeTable()
297 layerCache->setParent( tableModel );
298 tableModel->setParent( mAttributeTableFilterModel );
300 mAttributeTable->setModel( mAttributeTableFilterModel );
302 QFont font = mAttributeTable->font();
303 int fontSize = font.pointSize();
305 fontSize = std::max( fontSize - 1, 8 );
307 fontSize = std::max( fontSize - 2, 6 );
309 font.setPointSize( fontSize );
310 mAttributeTable->setFont( font );
313 mAttributeTable->resizeColumnsToContents();
314 mAttributeTable->resizeRowsToContents();
315 mAttributeTable->verticalHeader()->setVisible(
false );
316 mAttributeTable->setAlternatingRowColors(
true );
319 QgsBrowserDirectoryProperties::QgsBrowserDirectoryProperties( QWidget *parent )
320 : QgsBrowserPropertiesWidget( parent )
325 mPathLabel =
new QgsBrowserPropertiesWrapLabel( QString(), mHeaderWidget );
326 mHeaderGridLayout->addItem(
new QWidgetItem( mPathLabel ), 0, 1 );
329 void QgsBrowserDirectoryProperties::setItem(
QgsDataItem *item )
335 mPathLabel->setText( QDir::toNativeSeparators( directoryItem->
dirPath() ) );
337 mLayout->addWidget( mDirectoryWidget );
340 QgsBrowserPropertiesDialog::QgsBrowserPropertiesDialog(
const QString &settingsSection, QWidget *parent )
342 , mSettingsSection( settingsSection )
353 mPropertiesWidget = QgsBrowserPropertiesWidget::createWidget( item, context,
this );
354 mLayout->addWidget( mPropertiesWidget );
355 setWindowTitle( item->
type() ==
QgsDataItem::Layer ? tr(
"Layer Properties" ) : tr(
"Directory Properties" ) );
363 QgsDockBrowserTreeView::QgsDockBrowserTreeView( QWidget *parent ) :
QgsBrowserTreeView( parent )
365 setDragDropMode( QTreeView::DragDrop );
366 setSelectionMode( QAbstractItemView::ExtendedSelection );
367 setContextMenuPolicy( Qt::CustomContextMenu );
368 setHeaderHidden(
true );
369 setDropIndicatorShown(
true );
373 void QgsDockBrowserTreeView::setAction( QDropEvent *e )
377 if ( e->mimeData()->hasFormat( QStringLiteral(
"application/qgis.layertreemodeldata" ) ) &&
378 e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
380 e->setDropAction( Qt::CopyAction );
384 void QgsDockBrowserTreeView::dragEnterEvent( QDragEnterEvent *e )
393 void QgsDockBrowserTreeView::dragMoveEvent( QDragMoveEvent *e )
404 QTreeView::dragMoveEvent( e );
408 if ( !e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
415 void QgsDockBrowserTreeView::dropEvent( QDropEvent *e )
418 QTreeView::dropEvent( e );
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.
@ Custom
Custom item type.
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.