24 #include <QAbstractTextDocumentLayout> 25 #include <QHeaderView> 28 #include <QToolButton> 29 #include <QFileDialog> 30 #include <QPlainTextDocumentLayout> 31 #include <QSortFilterProxyModel> 42 #include <QDragEnterEvent> 48 QgsBrowserPropertiesWrapLabel::QgsBrowserPropertiesWrapLabel(
const QString &text, QWidget *parent )
49 : QTextEdit( text, parent )
52 setFrameStyle( QFrame::NoFrame );
53 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
54 QPalette
pal = palette();
55 pal.setColor( QPalette::Base, Qt::transparent );
57 setLineWrapMode( QTextEdit::WidgetWidth );
58 setWordWrapMode( QTextOption::WrapAnywhere );
59 connect( qobject_cast<QAbstractTextDocumentLayout *>( document()->documentLayout() ), &QAbstractTextDocumentLayout::documentSizeChanged,
60 this, &QgsBrowserPropertiesWrapLabel::adjustHeight );
61 setMaximumHeight( 20 );
64 void QgsBrowserPropertiesWrapLabel::adjustHeight( QSizeF size )
66 int height = size.height() + 2 * frameWidth();
67 setMinimumHeight( height );
68 setMaximumHeight( height );
71 QgsBrowserPropertiesWidget::QgsBrowserPropertiesWidget( QWidget *parent )
76 void QgsBrowserPropertiesWidget::setWidget( QWidget *paramWidget )
78 QVBoxLayout *layout =
new QVBoxLayout(
this );
79 paramWidget->setParent(
this );
80 layout->addWidget( paramWidget );
83 QgsBrowserPropertiesWidget *QgsBrowserPropertiesWidget::createWidget(
QgsDataItem *item, QWidget *parent )
85 QgsBrowserPropertiesWidget *propertiesWidget =
nullptr;
90 propertiesWidget =
new QgsBrowserDirectoryProperties( parent );
91 propertiesWidget->setItem( item );
99 propertiesWidget =
new QgsBrowserPropertiesWidget( parent );
100 propertiesWidget->setWidget( paramWidget );
104 propertiesWidget =
new QgsBrowserLayerProperties( parent );
105 propertiesWidget->setItem( item );
108 return propertiesWidget;
111 QgsBrowserLayerProperties::QgsBrowserLayerProperties( QWidget *parent )
112 : QgsBrowserPropertiesWidget( parent )
116 mUriLabel =
new QgsBrowserPropertiesWrapLabel( QString(),
this );
117 mHeaderGridLayout->addItem(
new QWidgetItem( mUriLabel ), 1, 1 );
120 void QgsBrowserLayerProperties::setItem(
QgsDataItem *item )
126 mNoticeLabel->clear();
129 QString layerMetadata = tr(
"Error" );
134 QString defaultProjectionOption = settings.
value( QStringLiteral(
"Projections/defaultBehavior" ),
"prompt" ).toString();
135 if ( settings.
value( QStringLiteral(
"Projections/defaultBehavior" ),
"prompt" ).toString() == QLatin1String(
"prompt" ) )
137 settings.
setValue( QStringLiteral(
"Projections/defaultBehavior" ),
"useProject" );
143 QgsDebugMsg( QString(
"creating temporary layer using path %1" ).arg( layerItem->
path() ) );
151 if ( layer->isValid() )
153 layerCrs = layer->crs();
154 layerMetadata = layer->htmlMetadata();
164 if ( layer->isValid() )
166 layerCrs = layer->crs();
167 layerMetadata = layer->htmlMetadata();
177 if ( layer->isValid() )
179 layerCrs = layer->crs();
180 layerMetadata = layer->htmlMetadata();
191 if ( defaultProjectionOption == QLatin1String(
"prompt" ) )
193 settings.
setValue( QStringLiteral(
"Projections/defaultBehavior" ), defaultProjectionOption );
196 mNameLabel->setText( layerItem->
name() );
197 mUriLabel->setText( layerItem->
uri() );
198 mProviderLabel->setText( layerItem->
providerKey() );
200 mMetadataTextBrowser->document()->setDefaultStyleSheet( myStyle );
201 mMetadataTextBrowser->setHtml( layerMetadata );
204 if ( defaultProjectionOption == QLatin1String(
"prompt" ) )
208 if ( layerCrs == defaultCrs )
209 mNoticeLabel->setText(
"NOTICE: Layer srs set from project (" + defaultCrs.
authid() +
')' );
212 if ( mNoticeLabel->text().isEmpty() )
214 mNoticeLabel->hide();
218 void QgsBrowserLayerProperties::setCondensedMode(
bool condensedMode )
222 mUriLabel->setLineWrapMode( QTextEdit::NoWrap );
223 mUriLabel->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
224 mUriLabel->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
228 mUriLabel->setLineWrapMode( QTextEdit::WidgetWidth );
229 mUriLabel->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
230 mUriLabel->setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded );
234 QgsBrowserDirectoryProperties::QgsBrowserDirectoryProperties( QWidget *parent )
235 : QgsBrowserPropertiesWidget( parent )
240 mPathLabel =
new QgsBrowserPropertiesWrapLabel( QString(), mHeaderWidget );
241 mHeaderGridLayout->addItem(
new QWidgetItem( mPathLabel ), 0, 1 );
244 void QgsBrowserDirectoryProperties::setItem(
QgsDataItem *item )
250 mPathLabel->setText( QDir::toNativeSeparators( directoryItem->
dirPath() ) );
252 mLayout->addWidget( mDirectoryWidget );
255 QgsBrowserPropertiesDialog::QgsBrowserPropertiesDialog(
const QString &settingsSection, QWidget *parent )
257 , mSettingsSection( settingsSection )
261 restoreGeometry( settings.
value( mSettingsSection +
"/propertiesDialog/geometry" ).toByteArray() );
264 QgsBrowserPropertiesDialog::~QgsBrowserPropertiesDialog()
270 void QgsBrowserPropertiesDialog::setItem(
QgsDataItem *item )
275 mPropertiesWidget = QgsBrowserPropertiesWidget::createWidget( item,
this );
276 mLayout->addWidget( mPropertiesWidget );
277 setWindowTitle( item->
type() ==
QgsDataItem::Layer ? tr(
"Layer Properties" ) : tr(
"Directory Properties" ) );
285 QgsDockBrowserTreeView::QgsDockBrowserTreeView( QWidget *parent ) :
QgsBrowserTreeView( parent )
287 setDragDropMode( QTreeView::DragDrop );
288 setSelectionMode( QAbstractItemView::ExtendedSelection );
289 setContextMenuPolicy( Qt::CustomContextMenu );
290 setHeaderHidden(
true );
291 setDropIndicatorShown(
true );
295 void QgsDockBrowserTreeView::setAction( QDropEvent *e )
299 if ( e->mimeData()->hasFormat( QStringLiteral(
"application/qgis.layertreemodeldata" ) ) &&
300 e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
302 e->setDropAction( Qt::CopyAction );
306 void QgsDockBrowserTreeView::dragEnterEvent( QDragEnterEvent *e )
315 void QgsDockBrowserTreeView::dragMoveEvent( QDragMoveEvent *e )
326 QTreeView::dragMoveEvent( e );
330 if ( !e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
337 void QgsDockBrowserTreeView::dropEvent( QDropEvent *e )
340 QTreeView::dropEvent( e );
349 QgsBrowserTreeFilterProxyModel::QgsBrowserTreeFilterProxyModel( QObject *parent )
350 : QSortFilterProxyModel( parent )
351 , mPatternSyntax( QStringLiteral(
"normal" ) )
352 , mCaseSensitivity( Qt::CaseInsensitive )
354 setDynamicSortFilter(
true );
356 setSortCaseSensitivity( Qt::CaseInsensitive );
360 void QgsBrowserTreeFilterProxyModel::setBrowserModel(
QgsBrowserModel *model )
363 setSourceModel( model );
366 void QgsBrowserTreeFilterProxyModel::setFilterSyntax(
const QString &syntax )
368 QgsDebugMsg( QString(
"syntax = %1" ).arg( syntax ) );
369 if ( mPatternSyntax == syntax )
371 mPatternSyntax = syntax;
375 void QgsBrowserTreeFilterProxyModel::setFilter(
const QString &filter )
377 QgsDebugMsg( QString(
"filter = %1" ).arg( mFilter ) );
378 if ( mFilter == filter )
384 void QgsBrowserTreeFilterProxyModel::setCaseSensitive(
bool caseSensitive )
386 mCaseSensitivity = caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive;
390 void QgsBrowserTreeFilterProxyModel::updateFilter()
392 QgsDebugMsg( QString(
"filter = %1 syntax = %2" ).arg( mFilter, mPatternSyntax ) );
394 if ( mPatternSyntax == QLatin1String(
"normal" ) )
396 Q_FOREACH (
const QString &f, mFilter.split(
'|' ) )
398 QRegExp rx( QString(
"*%1*" ).arg( f.trimmed() ) );
399 rx.setPatternSyntax( QRegExp::Wildcard );
400 rx.setCaseSensitivity( mCaseSensitivity );
401 mREList.append( rx );
404 else if ( mPatternSyntax == QLatin1String(
"wildcard" ) )
406 Q_FOREACH (
const QString &f, mFilter.split(
'|' ) )
408 QRegExp rx( f.trimmed() );
409 rx.setPatternSyntax( QRegExp::Wildcard );
410 rx.setCaseSensitivity( mCaseSensitivity );
411 mREList.append( rx );
416 QRegExp rx( mFilter.trimmed() );
417 rx.setPatternSyntax( QRegExp::RegExp );
418 rx.setCaseSensitivity( mCaseSensitivity );
419 mREList.append( rx );
424 bool QgsBrowserTreeFilterProxyModel::filterAcceptsString(
const QString &value )
const 426 if ( mPatternSyntax == QLatin1String(
"normal" ) || mPatternSyntax == QLatin1String(
"wildcard" ) )
428 Q_FOREACH (
const QRegExp &rx, mREList )
430 QgsDebugMsg( QString(
"value: [%1] rx: [%2] match: %3" ).arg( value, rx.pattern() ).arg( rx.exactMatch( value ) ) );
431 if ( rx.exactMatch( value ) )
437 Q_FOREACH (
const QRegExp &rx, mREList )
439 QgsDebugMsg( QString(
"value: [%1] rx: [%2] match: %3" ).arg( value, rx.pattern() ).arg( rx.indexIn( value ) ) );
440 if ( rx.indexIn( value ) != -1 )
447 bool QgsBrowserTreeFilterProxyModel::filterAcceptsRow(
int sourceRow,
const QModelIndex &sourceParent )
const 449 if ( mFilter.isEmpty() || !mModel )
452 QModelIndex sourceIndex = mModel->
index( sourceRow, 0, sourceParent );
453 return filterAcceptsItem( sourceIndex ) || filterAcceptsAncestor( sourceIndex ) || filterAcceptsDescendant( sourceIndex );
456 bool QgsBrowserTreeFilterProxyModel::filterAcceptsAncestor(
const QModelIndex &sourceIndex )
const 461 QModelIndex sourceParentIndex = mModel->
parent( sourceIndex );
462 if ( !sourceParentIndex.isValid() )
464 if ( filterAcceptsItem( sourceParentIndex ) )
467 return filterAcceptsAncestor( sourceParentIndex );
470 bool QgsBrowserTreeFilterProxyModel::filterAcceptsDescendant(
const QModelIndex &sourceIndex )
const 475 for (
int i = 0; i < mModel->
rowCount( sourceIndex ); i++ )
478 QModelIndex sourceChildIndex = mModel->
index( i, 0, sourceIndex );
479 if ( filterAcceptsItem( sourceChildIndex ) )
481 if ( filterAcceptsDescendant( sourceChildIndex ) )
487 bool QgsBrowserTreeFilterProxyModel::filterAcceptsItem(
const QModelIndex &sourceIndex )
const 493 return ( filterAcceptsString( mModel->
data( sourceIndex, Qt::DisplayRole ).toString() )
494 || ( !comment.isEmpty() && filterAcceptsString( comment ) ) );
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.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
static QString reportStyleSheet()
Returns a standard css style sheet for reports.
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.
QModelIndex parent(const QModelIndex &index) const override
LayerType
Types of layers that can be added to a map.
QgsCoordinateReferenceSystem crs
A directory: contains subdirectories and layers.
Base class for all items in the model.
Custom sort role, see QgsDataItem::sortKey()
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
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.
A model for showing available data sources and other items in a structured tree.
Item that represents a layer that can be opened with one of the providers.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
Represents a vector layer which manages a vector based data sets.
QString authid() const
Returns the authority identifier for the CRS.