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" 56 QgsBrowserPropertiesWrapLabel::QgsBrowserPropertiesWrapLabel(
const QString &text, QWidget *parent )
57 : QTextEdit( text, parent )
60 setFrameStyle( QFrame::NoFrame );
61 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
62 QPalette
pal = palette();
63 pal.setColor( QPalette::Base, Qt::transparent );
65 setLineWrapMode( QTextEdit::WidgetWidth );
66 setWordWrapMode( QTextOption::WrapAnywhere );
67 connect( document()->documentLayout(), &QAbstractTextDocumentLayout::documentSizeChanged,
68 this, &QgsBrowserPropertiesWrapLabel::adjustHeight );
69 setMaximumHeight( 20 );
72 void QgsBrowserPropertiesWrapLabel::adjustHeight( QSizeF size )
74 int height =
static_cast<int>( size.height() ) + 2 * frameWidth();
75 setMinimumHeight( height );
76 setMaximumHeight( height );
79 QgsBrowserPropertiesWidget::QgsBrowserPropertiesWidget( QWidget *parent )
84 void QgsBrowserPropertiesWidget::setWidget( QWidget *paramWidget )
86 QVBoxLayout *layout =
new QVBoxLayout(
this );
87 paramWidget->setParent(
this );
88 layout->addWidget( paramWidget );
93 QgsBrowserPropertiesWidget *propertiesWidget =
nullptr;
98 propertiesWidget =
new QgsBrowserDirectoryProperties( parent );
99 propertiesWidget->setItem( item );
104 QWidget *paramWidget =
nullptr;
108 paramWidget = provider->createParamWidget( item, context );
123 propertiesWidget =
new QgsBrowserPropertiesWidget( parent );
124 propertiesWidget->setWidget( paramWidget );
128 propertiesWidget =
new QgsBrowserLayerProperties( parent );
129 propertiesWidget->setItem( item );
132 return propertiesWidget;
135 QgsBrowserLayerProperties::QgsBrowserLayerProperties( QWidget *parent )
136 : QgsBrowserPropertiesWidget( parent )
141 mMetadataTextBrowser->setOpenLinks(
false );
142 connect( mMetadataTextBrowser, &QTextBrowser::anchorClicked,
this, &QgsBrowserLayerProperties::urlClicked );
144 mMapCanvas->setProperty(
"browser_canvas",
true );
145 mMapCanvas->setLayers( QList< QgsMapLayer * >() );
147 mMapCanvas->freeze(
true );
149 connect( mTabWidget, &QTabWidget::currentChanged,
this, [ = ]
151 if ( mTabWidget->currentWidget() == mPreviewTab && mMapCanvas->isFrozen() )
153 mMapCanvas->freeze(
false );
154 mMapCanvas->refresh();
156 else if ( mTabWidget->currentWidget() == mAttributesTab )
158 if ( ! mAttributeTableFilterModel )
159 loadAttributeTable();
164 void QgsBrowserLayerProperties::setItem(
QgsDataItem *item )
170 mNoticeLabel->clear();
173 QString layerMetadata = tr(
"Error" );
180 QgsDebugMsg( QStringLiteral(
"creating temporary layer using path %1" ).arg( layerItem->
path() ) );
185 QgsDebugMsg( QStringLiteral(
"creating raster layer" ) );
189 mLayer = qgis::make_unique< QgsRasterLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
195 QgsDebugMsg( QStringLiteral(
"creating mesh layer" ) );
198 mLayer = qgis::make_unique < QgsMeshLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
204 QgsDebugMsg( QStringLiteral(
"creating vector layer" ) );
207 mLayer = qgis::make_unique < QgsVectorLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
218 mAttributeTable->setModel(
nullptr );
219 if ( mAttributeTableFilterModel )
222 mAttributeTableFilterModel->deleteLater();
223 mAttributeTableFilterModel =
nullptr;
225 if ( mLayer && mLayer->isValid() )
228 mLayer->loadDefaultMetadata( ok );
229 layerMetadata = mLayer->htmlMetadata();
231 mMapCanvas->setDestinationCrs( mLayer->crs() );
232 mMapCanvas->setLayers( QList< QgsMapLayer * >() << mLayer.get() );
233 mMapCanvas->zoomToFullExtent();
237 mTabWidget->removeTab( mTabWidget->indexOf( mAttributesTab ) );
238 mAttributesTab =
nullptr;
243 mMetadataTextBrowser->document()->setDefaultStyleSheet( myStyle );
244 mMetadataTextBrowser->setHtml( layerMetadata );
246 if ( mNoticeLabel->text().isEmpty() )
248 mNoticeLabel->hide();
252 void QgsBrowserLayerProperties::setCondensedMode(
bool )
257 void QgsBrowserLayerProperties::urlClicked(
const QUrl &url )
259 QFileInfo file( url.toLocalFile() );
260 if ( file.exists() && !file.isDir() )
263 QDesktopServices::openUrl( url );
266 void QgsBrowserLayerProperties::loadAttributeTable()
277 layerCache->setParent( tableModel );
278 tableModel->setParent( mAttributeTableFilterModel );
280 mAttributeTable->setModel( mAttributeTableFilterModel );
282 QFont font = mAttributeTable->font();
283 int fontSize = font.pointSize();
285 fontSize = std::max( fontSize - 1, 8 );
287 fontSize = std::max( fontSize - 2, 6 );
289 font.setPointSize( fontSize );
290 mAttributeTable->setFont( font );
293 mAttributeTable->resizeColumnsToContents();
294 mAttributeTable->resizeRowsToContents();
295 mAttributeTable->verticalHeader()->setVisible(
false );
296 mAttributeTable->setAlternatingRowColors(
true );
299 QgsBrowserDirectoryProperties::QgsBrowserDirectoryProperties( QWidget *parent )
300 : QgsBrowserPropertiesWidget( parent )
305 mPathLabel =
new QgsBrowserPropertiesWrapLabel( QString(), mHeaderWidget );
306 mHeaderGridLayout->addItem(
new QWidgetItem( mPathLabel ), 0, 1 );
309 void QgsBrowserDirectoryProperties::setItem(
QgsDataItem *item )
315 mPathLabel->setText( QDir::toNativeSeparators( directoryItem->
dirPath() ) );
317 mLayout->addWidget( mDirectoryWidget );
320 QgsBrowserPropertiesDialog::QgsBrowserPropertiesDialog(
const QString &settingsSection, QWidget *parent )
322 , mSettingsSection( settingsSection )
333 mPropertiesWidget = QgsBrowserPropertiesWidget::createWidget( item, context,
this );
334 mLayout->addWidget( mPropertiesWidget );
335 setWindowTitle( item->
type() ==
QgsDataItem::Layer ? tr(
"Layer Properties" ) : tr(
"Directory Properties" ) );
343 QgsDockBrowserTreeView::QgsDockBrowserTreeView( QWidget *parent ) :
QgsBrowserTreeView( parent )
345 setDragDropMode( QTreeView::DragDrop );
346 setSelectionMode( QAbstractItemView::ExtendedSelection );
347 setContextMenuPolicy( Qt::CustomContextMenu );
348 setHeaderHidden(
true );
349 setDropIndicatorShown(
true );
353 void QgsDockBrowserTreeView::setAction( QDropEvent *e )
357 if ( e->mimeData()->hasFormat( QStringLiteral(
"application/qgis.layertreemodeldata" ) ) &&
358 e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
360 e->setDropAction( Qt::CopyAction );
364 void QgsDockBrowserTreeView::dragEnterEvent( QDragEnterEvent *e )
373 void QgsDockBrowserTreeView::dragMoveEvent( QDragMoveEvent *e )
384 QTreeView::dragMoveEvent( e );
388 if ( !e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
395 void QgsDockBrowserTreeView::dropEvent( QDropEvent *e )
398 QTreeView::dropEvent( e );
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.
QString providerKey() const
Returns provider key.
QString name() const
Returns the name of the item (the displayed text for the item).
static QgsNative * nativePlatformInterface()
Returns the global native interface, which offers abstraction to the host OS's underlying public inte...
Setting options for loading vector layers.
QgsMapLayerType mapLayerType() const
Returns QgsMapLayerType.
static QgsDataItemGuiProviderRegistry * dataItemGuiProviderRegistry()
Returns the global data item GUI provider registry, used for tracking providers which affect the brow...
#define Q_NOWARN_DEPRECATED_PUSH
QList< QgsDataItemGuiProvider * > providers() const
Returns the list of available providers.
Setting options for loading mesh layers.
A model backed by a QgsVectorLayerCache which is able to provide feature/attribute information to a Q...
static QString reportStyleSheet()
Returns a standard css style sheet for reports.
static QgsGui * instance()
Returns a pointer to the singleton instance.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
Abstract base class for providers which affect how QgsDataItem items behave within the application GU...
A directory: contains subdirectories and layers.
Base class for all items in the model.
Encapsulates the context in which a QgsDataItem is shown within the application GUI.
virtual Q_DECL_DEPRECATED QWidget * paramWidget()
Returns source widget from data item for QgsBrowserPropertiesWidget.
This class caches features of a given QgsVectorLayer.
QgsCoordinateTransformContext transformContext
bool skipCrsValidation
Controls whether the layer is allowed to have an invalid/unknown CRS.
#define Q_NOWARN_DEPRECATED_POP
void setCacheGeometry(bool cacheGeometry)
Enable or disable the caching of geometries.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QString uri() const
Returns layer uri or empty string if layer cannot be created.
QString dirPath() const
Returns the full path to the directory the item represents.
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...
Item that represents a layer that can be opened with one of the providers.
QgsMapLayerType
Types of layers that can be added to a map.
Geometry is not required. It may still be returned if e.g. required for a filter condition.
Setting options for loading raster layers.