24 #include <QAbstractTextDocumentLayout> 25 #include <QHeaderView> 28 #include <QToolButton> 29 #include <QFileDialog> 30 #include <QPlainTextDocumentLayout> 31 #include <QSortFilterProxyModel> 42 #include "qgsnative.h" 47 #include <QDesktopServices> 49 #include <QDragEnterEvent> 55 QgsBrowserPropertiesWrapLabel::QgsBrowserPropertiesWrapLabel(
const QString &text, QWidget *parent )
56 : QTextEdit( text, parent )
59 setFrameStyle( QFrame::NoFrame );
60 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
61 QPalette
pal = palette();
62 pal.setColor( QPalette::Base, Qt::transparent );
64 setLineWrapMode( QTextEdit::WidgetWidth );
65 setWordWrapMode( QTextOption::WrapAnywhere );
66 connect( document()->documentLayout(), &QAbstractTextDocumentLayout::documentSizeChanged,
67 this, &QgsBrowserPropertiesWrapLabel::adjustHeight );
68 setMaximumHeight( 20 );
71 void QgsBrowserPropertiesWrapLabel::adjustHeight( QSizeF size )
73 int height = size.height() + 2 * frameWidth();
74 setMinimumHeight( height );
75 setMaximumHeight( height );
78 QgsBrowserPropertiesWidget::QgsBrowserPropertiesWidget( QWidget *parent )
83 void QgsBrowserPropertiesWidget::setWidget( QWidget *paramWidget )
85 QVBoxLayout *layout =
new QVBoxLayout(
this );
86 paramWidget->setParent(
this );
87 layout->addWidget( paramWidget );
90 QgsBrowserPropertiesWidget *QgsBrowserPropertiesWidget::createWidget(
QgsDataItem *item, QWidget *parent )
92 QgsBrowserPropertiesWidget *propertiesWidget =
nullptr;
97 propertiesWidget =
new QgsBrowserDirectoryProperties( parent );
98 propertiesWidget->setItem( item );
106 propertiesWidget =
new QgsBrowserPropertiesWidget( parent );
107 propertiesWidget->setWidget( paramWidget );
111 propertiesWidget =
new QgsBrowserLayerProperties( parent );
112 propertiesWidget->setItem( item );
115 return propertiesWidget;
118 QgsBrowserLayerProperties::QgsBrowserLayerProperties( QWidget *parent )
119 : QgsBrowserPropertiesWidget( parent )
124 mMetadataTextBrowser->setOpenLinks(
false );
125 connect( mMetadataTextBrowser, &QTextBrowser::anchorClicked,
this, &QgsBrowserLayerProperties::urlClicked );
127 mMapCanvas->setProperty(
"browser_canvas",
true );
128 mMapCanvas->setLayers( QList< QgsMapLayer * >() );
130 mMapCanvas->freeze(
true );
132 connect( mTabWidget, &QTabWidget::currentChanged,
this, [ = ]
134 if ( mTabWidget->currentWidget() == mPreviewTab && mMapCanvas->isFrozen() )
136 mMapCanvas->freeze(
false );
137 mMapCanvas->refresh();
139 else if ( mTabWidget->currentWidget() == mAttributesTab )
141 if ( ! mAttributeTableFilterModel )
142 loadAttributeTable();
147 class ProjectionSettingRestorer
151 ProjectionSettingRestorer()
154 previousSetting = settings.
value( QStringLiteral(
"/Projections/defaultBehavior" ) ).toString();
155 settings.
setValue( QStringLiteral(
"/Projections/defaultBehavior" ), QStringLiteral(
"useProject" ) );
158 ~ProjectionSettingRestorer()
161 settings.
setValue( QStringLiteral(
"/Projections/defaultBehavior" ), previousSetting );
164 QString previousSetting;
167 void QgsBrowserLayerProperties::setItem(
QgsDataItem *item )
173 mNoticeLabel->clear();
176 QString layerMetadata = tr(
"Error" );
179 QString defaultProjectionOption =
QgsSettings().
value( QStringLiteral(
"Projections/defaultBehavior" ),
"prompt" ).toString();
182 ProjectionSettingRestorer restorer;
190 QgsDebugMsg( QStringLiteral(
"creating temporary layer using path %1" ).arg( layerItem->
path() ) );
193 QgsDebugMsg( QStringLiteral(
"creating raster layer" ) );
195 mLayer = qgis::make_unique< QgsRasterLayer >( layerItem->
uri(), layerItem->
uri(), layerItem->
providerKey() );
199 QgsDebugMsg( QStringLiteral(
"creating mesh layer" ) );
200 mLayer = qgis::make_unique < QgsMeshLayer >( layerItem->
uri(), layerItem->
uri(), layerItem->
providerKey() );
204 QgsDebugMsg( QStringLiteral(
"creating vector layer" ) );
205 mLayer = qgis::make_unique < QgsVectorLayer>( layerItem->
uri(), layerItem->
name(), layerItem->
providerKey() );
213 mAttributeTable->setModel(
nullptr );
214 if ( mAttributeTableFilterModel )
217 mAttributeTableFilterModel->deleteLater();
218 mAttributeTableFilterModel =
nullptr;
220 if ( mLayer && mLayer->isValid() )
223 mLayer->loadDefaultMetadata( ok );
224 layerCrs = mLayer->crs();
225 layerMetadata = mLayer->htmlMetadata();
227 mMapCanvas->setDestinationCrs( mLayer->crs() );
228 mMapCanvas->setLayers( QList< QgsMapLayer * >() << mLayer.get() );
229 mMapCanvas->zoomToFullExtent();
233 mTabWidget->removeTab( mTabWidget->indexOf( mAttributesTab ) );
234 mAttributesTab =
nullptr;
239 mMetadataTextBrowser->document()->setDefaultStyleSheet( myStyle );
240 mMetadataTextBrowser->setHtml( layerMetadata );
243 if ( defaultProjectionOption == QLatin1String(
"prompt" ) )
247 if ( layerCrs == defaultCrs )
248 mNoticeLabel->setText(
"NOTICE: Layer CRS set from project (" + defaultCrs.
authid() +
')' );
251 if ( mNoticeLabel->text().isEmpty() )
253 mNoticeLabel->hide();
257 void QgsBrowserLayerProperties::setCondensedMode(
bool )
262 void QgsBrowserLayerProperties::urlClicked(
const QUrl &url )
264 QFileInfo file( url.toLocalFile() );
265 if ( file.exists() && !file.isDir() )
268 QDesktopServices::openUrl( url );
271 void QgsBrowserLayerProperties::loadAttributeTable()
282 layerCache->setParent( tableModel );
283 tableModel->setParent( mAttributeTableFilterModel );
285 mAttributeTable->setModel( mAttributeTableFilterModel );
287 QFont font = mAttributeTable->font();
288 int fontSize = font.pointSize();
290 fontSize = std::max( fontSize - 1, 8 );
292 fontSize = std::max( fontSize - 2, 6 );
294 font.setPointSize( fontSize );
295 mAttributeTable->setFont( font );
298 mAttributeTable->resizeColumnsToContents();
299 mAttributeTable->resizeRowsToContents();
300 mAttributeTable->verticalHeader()->setVisible(
false );
301 mAttributeTable->setAlternatingRowColors(
true );
304 QgsBrowserDirectoryProperties::QgsBrowserDirectoryProperties( QWidget *parent )
305 : QgsBrowserPropertiesWidget( parent )
310 mPathLabel =
new QgsBrowserPropertiesWrapLabel( QString(), mHeaderWidget );
311 mHeaderGridLayout->addItem(
new QWidgetItem( mPathLabel ), 0, 1 );
314 void QgsBrowserDirectoryProperties::setItem(
QgsDataItem *item )
320 mPathLabel->setText( QDir::toNativeSeparators( directoryItem->
dirPath() ) );
322 mLayout->addWidget( mDirectoryWidget );
325 QgsBrowserPropertiesDialog::QgsBrowserPropertiesDialog(
const QString &settingsSection, QWidget *parent )
327 , mSettingsSection( settingsSection )
331 restoreGeometry( settings.
value( mSettingsSection +
"/propertiesDialog/geometry" ).toByteArray() );
334 QgsBrowserPropertiesDialog::~QgsBrowserPropertiesDialog()
340 void QgsBrowserPropertiesDialog::setItem(
QgsDataItem *item )
345 mPropertiesWidget = QgsBrowserPropertiesWidget::createWidget( item,
this );
346 mLayout->addWidget( mPropertiesWidget );
347 setWindowTitle( item->
type() ==
QgsDataItem::Layer ? tr(
"Layer Properties" ) : tr(
"Directory Properties" ) );
355 QgsDockBrowserTreeView::QgsDockBrowserTreeView( QWidget *parent ) :
QgsBrowserTreeView( parent )
357 setDragDropMode( QTreeView::DragDrop );
358 setSelectionMode( QAbstractItemView::ExtendedSelection );
359 setContextMenuPolicy( Qt::CustomContextMenu );
360 setHeaderHidden(
true );
361 setDropIndicatorShown(
true );
365 void QgsDockBrowserTreeView::setAction( QDropEvent *e )
369 if ( e->mimeData()->hasFormat( QStringLiteral(
"application/qgis.layertreemodeldata" ) ) &&
370 e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
372 e->setDropAction( Qt::CopyAction );
376 void QgsDockBrowserTreeView::dragEnterEvent( QDragEnterEvent *e )
385 void QgsDockBrowserTreeView::dragMoveEvent( QDragMoveEvent *e )
396 QTreeView::dragMoveEvent( e );
400 if ( !e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
407 void QgsDockBrowserTreeView::dropEvent( QDropEvent *e )
410 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 name() const
Returns the name of the item (the displayed text for the item).
This class is a composition of two QSettings instances:
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)...
QString providerKey() const
Returns provider key.
A directory: contains subdirectories and layers.
Base class for all items in the model.
QgsMapLayer::LayerType mapLayerType() const
Returns QgsMapLayer::LayerType.
This class caches features of a given QgsVectorLayer.
QString uri() const
Returns layer uri or empty string if layer cannot be created.
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 authid() const
Returns the authority identifier for the CRS.
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.