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"
57 QgsBrowserPropertiesWrapLabel::QgsBrowserPropertiesWrapLabel(
const QString &text, QWidget *parent )
58 : QTextEdit( text, parent )
61 setFrameStyle( QFrame::NoFrame );
62 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
63 QPalette
pal = palette();
64 pal.setColor( QPalette::Base, Qt::transparent );
66 setLineWrapMode( QTextEdit::WidgetWidth );
67 setWordWrapMode( QTextOption::WrapAnywhere );
68 connect( document()->documentLayout(), &QAbstractTextDocumentLayout::documentSizeChanged,
69 this, &QgsBrowserPropertiesWrapLabel::adjustHeight );
70 setMaximumHeight( 20 );
73 void QgsBrowserPropertiesWrapLabel::adjustHeight( QSizeF size )
75 int height =
static_cast<int>( size.height() ) + 2 * frameWidth();
76 setMinimumHeight( height );
77 setMaximumHeight( height );
80 QgsBrowserPropertiesWidget::QgsBrowserPropertiesWidget( QWidget *parent )
85 void QgsBrowserPropertiesWidget::setWidget( QWidget *paramWidget )
87 QVBoxLayout *layout =
new QVBoxLayout(
this );
88 layout->setContentsMargins( 0, 0, 0, 0 );
89 paramWidget->setParent(
this );
90 layout->addWidget( paramWidget );
95 QgsBrowserPropertiesWidget *propertiesWidget =
nullptr;
100 propertiesWidget =
new QgsBrowserDirectoryProperties( parent );
101 propertiesWidget->setItem( item );
106 QWidget *paramWidget =
nullptr;
110 paramWidget = provider->createParamWidget( item, context );
125 propertiesWidget =
new QgsBrowserPropertiesWidget( parent );
126 propertiesWidget->setWidget( paramWidget );
130 propertiesWidget =
new QgsBrowserLayerProperties( parent );
131 propertiesWidget->setItem( item );
134 return propertiesWidget;
137 QgsBrowserLayerProperties::QgsBrowserLayerProperties( QWidget *parent )
138 : QgsBrowserPropertiesWidget( parent )
143 mMetadataTextBrowser->setOpenLinks(
false );
144 connect( mMetadataTextBrowser, &QTextBrowser::anchorClicked,
this, &QgsBrowserLayerProperties::urlClicked );
146 mMapCanvas->setProperty(
"browser_canvas",
true );
147 mMapCanvas->setLayers( QList< QgsMapLayer * >() );
149 mMapCanvas->freeze(
true );
151 connect( mTabWidget, &QTabWidget::currentChanged,
this, [ = ]
153 if ( mTabWidget->currentWidget() == mPreviewTab && mMapCanvas->isFrozen() )
155 mMapCanvas->freeze( false );
156 mMapCanvas->refresh();
158 else if ( mTabWidget->currentWidget() == mAttributesTab )
160 if ( ! mAttributeTableFilterModel )
161 loadAttributeTable();
166 void QgsBrowserLayerProperties::setItem(
QgsDataItem *item )
168 QgsLayerItem *layerItem = qobject_cast<QgsLayerItem *>( item );
172 mNoticeLabel->clear();
175 QString layerMetadata = tr(
"Error" );
182 QgsDebugMsg( QStringLiteral(
"creating temporary layer using path %1" ).arg( layerItem->
path() ) );
187 QgsDebugMsg( QStringLiteral(
"creating raster layer" ) );
191 mLayer = qgis::make_unique< QgsRasterLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
197 QgsDebugMsg( QStringLiteral(
"creating mesh layer" ) );
199 options.skipCrsValidation =
true;
200 mLayer = qgis::make_unique < QgsMeshLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
206 QgsDebugMsg( QStringLiteral(
"creating vector layer" ) );
208 options.skipCrsValidation =
true;
209 mLayer = qgis::make_unique < QgsVectorLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
216 mLayer = qgis::make_unique< QgsVectorTileLayer >( layerItem->
uri(), layerItem->
name() );
228 mAttributeTable->setModel(
nullptr );
229 if ( mAttributeTableFilterModel )
232 mAttributeTableFilterModel->deleteLater();
233 mAttributeTableFilterModel =
nullptr;
235 if ( mLayer && mLayer->isValid() )
238 mLayer->loadDefaultMetadata( ok );
239 layerMetadata = mLayer->htmlMetadata();
241 mMapCanvas->setDestinationCrs( mLayer->crs() );
242 mMapCanvas->setLayers( QList< QgsMapLayer * >() << mLayer.get() );
243 mMapCanvas->zoomToFullExtent();
247 mTabWidget->removeTab( mTabWidget->indexOf( mAttributesTab ) );
248 mAttributesTab =
nullptr;
253 mMetadataTextBrowser->document()->setDefaultStyleSheet( myStyle );
254 mMetadataTextBrowser->setHtml( layerMetadata );
256 if ( mNoticeLabel->text().isEmpty() )
258 mNoticeLabel->hide();
262 void QgsBrowserLayerProperties::setCondensedMode(
bool )
267 void QgsBrowserLayerProperties::urlClicked(
const QUrl &url )
269 QFileInfo file( url.toLocalFile() );
270 if ( file.exists() && !file.isDir() )
273 QDesktopServices::openUrl( url );
276 void QgsBrowserLayerProperties::loadAttributeTable()
287 layerCache->setParent( tableModel );
288 tableModel->setParent( mAttributeTableFilterModel );
290 mAttributeTable->setModel( mAttributeTableFilterModel );
292 QFont font = mAttributeTable->font();
293 int fontSize = font.pointSize();
295 fontSize = std::max( fontSize - 1, 8 );
297 fontSize = std::max( fontSize - 2, 6 );
299 font.setPointSize( fontSize );
300 mAttributeTable->setFont( font );
303 mAttributeTable->resizeColumnsToContents();
304 mAttributeTable->resizeRowsToContents();
305 mAttributeTable->verticalHeader()->setVisible(
false );
306 mAttributeTable->setAlternatingRowColors(
true );
309 QgsBrowserDirectoryProperties::QgsBrowserDirectoryProperties( QWidget *parent )
310 : QgsBrowserPropertiesWidget( parent )
315 mPathLabel =
new QgsBrowserPropertiesWrapLabel( QString(), mHeaderWidget );
316 mHeaderGridLayout->addItem(
new QWidgetItem( mPathLabel ), 0, 1 );
319 void QgsBrowserDirectoryProperties::setItem(
QgsDataItem *item )
325 mPathLabel->setText( QDir::toNativeSeparators( directoryItem->
dirPath() ) );
327 mLayout->addWidget( mDirectoryWidget );
330 QgsBrowserPropertiesDialog::QgsBrowserPropertiesDialog(
const QString &settingsSection, QWidget *parent )
332 , mSettingsSection( settingsSection )
343 mPropertiesWidget = QgsBrowserPropertiesWidget::createWidget( item, context,
this );
344 mLayout->addWidget( mPropertiesWidget );
345 setWindowTitle( item->
type() ==
QgsDataItem::Layer ? tr(
"Layer Properties" ) : tr(
"Directory Properties" ) );
353 QgsDockBrowserTreeView::QgsDockBrowserTreeView( QWidget *parent ) :
QgsBrowserTreeView( parent )
355 setDragDropMode( QTreeView::DragDrop );
356 setSelectionMode( QAbstractItemView::ExtendedSelection );
357 setContextMenuPolicy( Qt::CustomContextMenu );
358 setHeaderHidden(
true );
359 setDropIndicatorShown(
true );
363 void QgsDockBrowserTreeView::setAction( QDropEvent *e )
367 if ( e->mimeData()->hasFormat( QStringLiteral(
"application/qgis.layertreemodeldata" ) ) &&
368 e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
370 e->setDropAction( Qt::CopyAction );
374 void QgsDockBrowserTreeView::dragEnterEvent( QDragEnterEvent *e )
383 void QgsDockBrowserTreeView::dragMoveEvent( QDragMoveEvent *e )
394 QTreeView::dragMoveEvent( e );
398 if ( !e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
405 void QgsDockBrowserTreeView::dropEvent( QDropEvent *e )
408 QTreeView::dropEvent( e );