24 #include <QAbstractTextDocumentLayout> 25 #include <QHeaderView> 28 #include <QToolButton> 29 #include <QFileDialog> 30 #include <QPlainTextDocumentLayout> 31 #include <QSortFilterProxyModel> 42 #include "qgsnative.h" 48 #include <QDesktopServices> 50 #include <QDragEnterEvent> 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 = 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 );
91 QgsBrowserPropertiesWidget *QgsBrowserPropertiesWidget::createWidget(
QgsDataItem *item, QWidget *parent )
93 QgsBrowserPropertiesWidget *propertiesWidget =
nullptr;
98 propertiesWidget =
new QgsBrowserDirectoryProperties( parent );
99 propertiesWidget->setItem( item );
107 propertiesWidget =
new QgsBrowserPropertiesWidget( parent );
108 propertiesWidget->setWidget( paramWidget );
112 propertiesWidget =
new QgsBrowserLayerProperties( parent );
113 propertiesWidget->setItem( item );
116 return propertiesWidget;
119 QgsBrowserLayerProperties::QgsBrowserLayerProperties( QWidget *parent )
120 : QgsBrowserPropertiesWidget( parent )
125 mMetadataTextBrowser->setOpenLinks(
false );
126 connect( mMetadataTextBrowser, &QTextBrowser::anchorClicked,
this, &QgsBrowserLayerProperties::urlClicked );
128 mMapCanvas->setProperty(
"browser_canvas",
true );
129 mMapCanvas->setLayers( QList< QgsMapLayer * >() );
131 mMapCanvas->freeze(
true );
133 connect( mTabWidget, &QTabWidget::currentChanged,
this, [ = ]
135 if ( mTabWidget->currentWidget() == mPreviewTab && mMapCanvas->isFrozen() )
137 mMapCanvas->freeze(
false );
138 mMapCanvas->refresh();
140 else if ( mTabWidget->currentWidget() == mAttributesTab )
142 if ( ! mAttributeTableFilterModel )
143 loadAttributeTable();
148 class ProjectionSettingRestorer
152 ProjectionSettingRestorer()
155 previousSetting = settings.
value( QStringLiteral(
"/Projections/defaultBehavior" ) ).toString();
156 settings.
setValue( QStringLiteral(
"/Projections/defaultBehavior" ), QStringLiteral(
"useProject" ) );
159 ~ProjectionSettingRestorer()
162 settings.
setValue( QStringLiteral(
"/Projections/defaultBehavior" ), previousSetting );
165 QString previousSetting;
168 void QgsBrowserLayerProperties::setItem(
QgsDataItem *item )
174 mNoticeLabel->clear();
177 QString layerMetadata = tr(
"Error" );
180 QString defaultProjectionOption =
QgsSettings().
value( QStringLiteral(
"Projections/defaultBehavior" ),
"prompt" ).toString();
183 ProjectionSettingRestorer restorer;
191 QgsDebugMsg( QStringLiteral(
"creating temporary layer using path %1" ).arg( layerItem->
path() ) );
196 QgsDebugMsg( QStringLiteral(
"creating raster layer" ) );
198 mLayer = qgis::make_unique< QgsRasterLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey() );
204 QgsDebugMsg( QStringLiteral(
"creating mesh layer" ) );
205 mLayer = qgis::make_unique < QgsMeshLayer >( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey() );
211 QgsDebugMsg( QStringLiteral(
"creating vector layer" ) );
212 mLayer = qgis::make_unique < QgsVectorLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey() );
223 mAttributeTable->setModel(
nullptr );
224 if ( mAttributeTableFilterModel )
227 mAttributeTableFilterModel->deleteLater();
228 mAttributeTableFilterModel =
nullptr;
230 if ( mLayer && mLayer->isValid() )
233 mLayer->loadDefaultMetadata( ok );
234 layerCrs = mLayer->crs();
235 layerMetadata = mLayer->htmlMetadata();
237 mMapCanvas->setDestinationCrs( mLayer->crs() );
238 mMapCanvas->setLayers( QList< QgsMapLayer * >() << mLayer.get() );
239 mMapCanvas->zoomToFullExtent();
243 mTabWidget->removeTab( mTabWidget->indexOf( mAttributesTab ) );
244 mAttributesTab =
nullptr;
249 mMetadataTextBrowser->document()->setDefaultStyleSheet( myStyle );
250 mMetadataTextBrowser->setHtml( layerMetadata );
253 if ( defaultProjectionOption == QLatin1String(
"prompt" ) )
257 if ( layerCrs == defaultCrs )
258 mNoticeLabel->setText(
"NOTICE: Layer CRS set from project (" + defaultCrs.
authid() +
')' );
261 if ( mNoticeLabel->text().isEmpty() )
263 mNoticeLabel->hide();
267 void QgsBrowserLayerProperties::setCondensedMode(
bool )
272 void QgsBrowserLayerProperties::urlClicked(
const QUrl &url )
274 QFileInfo file( url.toLocalFile() );
275 if ( file.exists() && !file.isDir() )
278 QDesktopServices::openUrl( url );
281 void QgsBrowserLayerProperties::loadAttributeTable()
292 layerCache->setParent( tableModel );
293 tableModel->setParent( mAttributeTableFilterModel );
295 mAttributeTable->setModel( mAttributeTableFilterModel );
297 QFont font = mAttributeTable->font();
298 int fontSize = font.pointSize();
300 fontSize = std::max( fontSize - 1, 8 );
302 fontSize = std::max( fontSize - 2, 6 );
304 font.setPointSize( fontSize );
305 mAttributeTable->setFont( font );
308 mAttributeTable->resizeColumnsToContents();
309 mAttributeTable->resizeRowsToContents();
310 mAttributeTable->verticalHeader()->setVisible(
false );
311 mAttributeTable->setAlternatingRowColors(
true );
314 QgsBrowserDirectoryProperties::QgsBrowserDirectoryProperties( QWidget *parent )
315 : QgsBrowserPropertiesWidget( parent )
320 mPathLabel =
new QgsBrowserPropertiesWrapLabel( QString(), mHeaderWidget );
321 mHeaderGridLayout->addItem(
new QWidgetItem( mPathLabel ), 0, 1 );
324 void QgsBrowserDirectoryProperties::setItem(
QgsDataItem *item )
330 mPathLabel->setText( QDir::toNativeSeparators( directoryItem->
dirPath() ) );
332 mLayout->addWidget( mDirectoryWidget );
335 QgsBrowserPropertiesDialog::QgsBrowserPropertiesDialog(
const QString &settingsSection, QWidget *parent )
337 , mSettingsSection( settingsSection )
341 restoreGeometry( settings.
value( mSettingsSection +
"/propertiesDialog/geometry" ).toByteArray() );
344 QgsBrowserPropertiesDialog::~QgsBrowserPropertiesDialog()
350 void QgsBrowserPropertiesDialog::setItem(
QgsDataItem *item )
355 mPropertiesWidget = QgsBrowserPropertiesWidget::createWidget( item,
this );
356 mLayout->addWidget( mPropertiesWidget );
357 setWindowTitle( item->
type() ==
QgsDataItem::Layer ? tr(
"Layer Properties" ) : tr(
"Directory Properties" ) );
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 );
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).
This class is a composition of two QSettings instances:
QgsMapLayer::LayerType mapLayerType() const
Returns QgsMapLayer::LayerType.
static QgsNative * nativePlatformInterface()
Returns the global native interface, which offers abstraction to the host OS's underlying public inte...
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
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.
virtual QWidget * paramWidget()
void saveGeometry(QWidget *widget, const QString &keyName)
Save the wigget geometry into settings.
bool restoreGeometry(QWidget *widget, const QString &keyName)
Restore the wigget geometry from settings.
LayerType
Types of layers that can be added to a map.
QgsCoordinateReferenceSystem crs
This class wraps a request for features to a vector layer (or directly its vector data provider)...
A directory: contains subdirectories and layers.
Base class for all items in the model.
This class caches features of a given QgsVectorLayer.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
void setCacheGeometry(bool cacheGeometry)
Enable or disable the caching of geometries.
static QgsProject * instance()
Returns the QgsProject singleton instance.
This class represents a coordinate reference system (CRS).
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.
Item that represents a layer that can be opened with one of the providers.
Geometry is not required. It may still be returned if e.g. required for a filter condition.
QString authid() const
Returns the authority identifier for the CRS.