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"
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 const 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 );
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;
143 QgsBrowserLayerProperties::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();
172 void 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 );
197 mLayer = std::make_unique< QgsRasterLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
205 options.skipCrsValidation =
true;
206 mLayer = std::make_unique < QgsMeshLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
214 options.skipCrsValidation =
true;
215 mLayer = std::make_unique < QgsVectorLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
222 mLayer = std::make_unique< QgsVectorTileLayer >( layerItem->
uri(), layerItem->
name() );
230 options.skipCrsValidation =
true;
231 mLayer = std::make_unique< QgsPointCloudLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey(), options );
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();
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();
278 void QgsBrowserLayerProperties::setCondensedMode(
bool )
283 void QgsBrowserLayerProperties::urlClicked(
const QUrl &url )
285 const QFileInfo file( url.toLocalFile() );
286 if ( file.exists() && !file.isDir() )
289 QDesktopServices::openUrl( url );
292 void QgsBrowserLayerProperties::loadAttributeTable()
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 );
325 QgsBrowserDirectoryProperties::QgsBrowserDirectoryProperties( QWidget *parent )
326 : QgsBrowserPropertiesWidget( parent )
331 mPathLabel =
new QgsBrowserPropertiesWrapLabel( QString(), mHeaderWidget );
332 mHeaderGridLayout->addItem(
new QWidgetItem( mPathLabel ), 0, 1 );
335 void QgsBrowserDirectoryProperties::setItem(
QgsDataItem *item )
341 mPathLabel->setText( QDir::toNativeSeparators( directoryItem->
dirPath() ) );
343 mLayout->addWidget( mDirectoryWidget );
346 QgsBrowserPropertiesDialog::QgsBrowserPropertiesDialog(
const QString &settingsSection, QWidget *parent )
348 , mSettingsSection( settingsSection )
359 mPropertiesWidget = QgsBrowserPropertiesWidget::createWidget( item, context,
this );
360 mLayout->addWidget( mPropertiesWidget );
369 QgsDockBrowserTreeView::QgsDockBrowserTreeView( QWidget *parent ) :
QgsBrowserTreeView( parent )
371 setDragDropMode( QTreeView::DragDrop );
372 setSelectionMode( QAbstractItemView::ExtendedSelection );
373 setContextMenuPolicy( Qt::CustomContextMenu );
374 setHeaderHidden(
true );
375 setDropIndicatorShown(
true );
379 void 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 );
390 void QgsDockBrowserTreeView::dragEnterEvent( QDragEnterEvent *e )
399 void QgsDockBrowserTreeView::dragMoveEvent( QDragMoveEvent *e )
410 QTreeView::dragMoveEvent( e );
414 if ( !e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
421 void QgsDockBrowserTreeView::dropEvent( QDropEvent *e )
424 QTreeView::dropEvent( e );