22 #include <QAbstractTextDocumentLayout> 23 #include <QHeaderView> 26 #include <QToolButton> 27 #include <QFileDialog> 28 #include <QPlainTextDocumentLayout> 29 #include <QSortFilterProxyModel> 40 #include <QDragEnterEvent> 46 QgsBrowserPropertiesWrapLabel::QgsBrowserPropertiesWrapLabel(
const QString &text, QWidget *parent )
47 : QTextEdit( text, parent )
50 setFrameStyle( QFrame::NoFrame );
51 setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
52 QPalette
pal = palette();
53 pal.setColor( QPalette::Base, Qt::transparent );
55 setLineWrapMode( QTextEdit::WidgetWidth );
56 setWordWrapMode( QTextOption::WrapAnywhere );
57 connect( qobject_cast<QAbstractTextDocumentLayout *>( document()->documentLayout() ), &QAbstractTextDocumentLayout::documentSizeChanged,
58 this, &QgsBrowserPropertiesWrapLabel::adjustHeight );
59 setMaximumHeight( 20 );
62 void QgsBrowserPropertiesWrapLabel::adjustHeight( QSizeF size )
64 int height = size.height() + 2 * frameWidth();
65 setMinimumHeight( height );
66 setMaximumHeight( height );
69 QgsBrowserPropertiesWidget::QgsBrowserPropertiesWidget( QWidget *parent )
74 void QgsBrowserPropertiesWidget::setWidget( QWidget *paramWidget )
76 QVBoxLayout *layout =
new QVBoxLayout(
this );
77 paramWidget->setParent(
this );
78 layout->addWidget( paramWidget );
81 QgsBrowserPropertiesWidget *QgsBrowserPropertiesWidget::createWidget(
QgsDataItem *item, QWidget *parent )
83 QgsBrowserPropertiesWidget *propertiesWidget =
nullptr;
88 propertiesWidget =
new QgsBrowserDirectoryProperties( parent );
89 propertiesWidget->setItem( item );
97 propertiesWidget =
new QgsBrowserPropertiesWidget( parent );
98 propertiesWidget->setWidget( paramWidget );
102 propertiesWidget =
new QgsBrowserLayerProperties( parent );
103 propertiesWidget->setItem( item );
106 return propertiesWidget;
109 QgsBrowserLayerProperties::QgsBrowserLayerProperties( QWidget *parent )
110 : QgsBrowserPropertiesWidget( parent )
114 mUriLabel =
new QgsBrowserPropertiesWrapLabel( QString(),
this );
115 mHeaderGridLayout->addItem(
new QWidgetItem( mUriLabel ), 1, 1 );
118 void QgsBrowserLayerProperties::setItem(
QgsDataItem *item )
124 mNoticeLabel->clear();
127 QString layerMetadata = tr(
"Error" );
132 QString defaultProjectionOption = settings.
value( QStringLiteral(
"Projections/defaultBehavior" ),
"prompt" ).toString();
133 if ( settings.
value( QStringLiteral(
"Projections/defaultBehavior" ),
"prompt" ).toString() == QLatin1String(
"prompt" ) )
135 settings.
setValue( QStringLiteral(
"Projections/defaultBehavior" ),
"useProject" );
141 QgsDebugMsg( QString(
"creating temporary layer using path %1" ).arg( layerItem->
path() ) );
151 layerCrs = layer->
crs();
165 layerCrs = layer->
crs();
178 if ( defaultProjectionOption == QLatin1String(
"prompt" ) )
180 settings.
setValue( QStringLiteral(
"Projections/defaultBehavior" ), defaultProjectionOption );
183 mNameLabel->setText( layerItem->
name() );
184 mUriLabel->setText( layerItem->
uri() );
185 mProviderLabel->setText( layerItem->
providerKey() );
187 mMetadataTextBrowser->document()->setDefaultStyleSheet( myStyle );
188 mMetadataTextBrowser->setHtml( layerMetadata );
191 if ( defaultProjectionOption == QLatin1String(
"prompt" ) )
195 if ( layerCrs == defaultCrs )
196 mNoticeLabel->setText(
"NOTICE: Layer srs set from project (" + defaultCrs.
authid() +
')' );
199 if ( mNoticeLabel->text().isEmpty() )
201 mNoticeLabel->hide();
205 void QgsBrowserLayerProperties::setCondensedMode(
bool condensedMode )
209 mUriLabel->setLineWrapMode( QTextEdit::NoWrap );
210 mUriLabel->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
211 mUriLabel->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
215 mUriLabel->setLineWrapMode( QTextEdit::WidgetWidth );
216 mUriLabel->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
217 mUriLabel->setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded );
221 QgsBrowserDirectoryProperties::QgsBrowserDirectoryProperties( QWidget *parent )
222 : QgsBrowserPropertiesWidget( parent )
227 mPathLabel =
new QgsBrowserPropertiesWrapLabel( QString(), mHeaderWidget );
228 mHeaderGridLayout->addItem(
new QWidgetItem( mPathLabel ), 0, 1 );
231 void QgsBrowserDirectoryProperties::setItem(
QgsDataItem *item )
237 mPathLabel->setText( QDir::toNativeSeparators( directoryItem->
dirPath() ) );
239 mLayout->addWidget( mDirectoryWidget );
242 QgsBrowserPropertiesDialog::QgsBrowserPropertiesDialog(
const QString &settingsSection, QWidget *parent )
244 , mSettingsSection( settingsSection )
248 restoreGeometry( settings.
value( mSettingsSection +
"/propertiesDialog/geometry" ).toByteArray() );
251 QgsBrowserPropertiesDialog::~QgsBrowserPropertiesDialog()
257 void QgsBrowserPropertiesDialog::setItem(
QgsDataItem *item )
262 mPropertiesWidget = QgsBrowserPropertiesWidget::createWidget( item,
this );
263 mLayout->addWidget( mPropertiesWidget );
264 setWindowTitle( item->
type() ==
QgsDataItem::Layer ? tr(
"Layer Properties" ) : tr(
"Directory Properties" ) );
272 QgsDockBrowserTreeView::QgsDockBrowserTreeView( QWidget *parent ) :
QgsBrowserTreeView( parent )
274 setDragDropMode( QTreeView::DragDrop );
275 setSelectionMode( QAbstractItemView::ExtendedSelection );
276 setContextMenuPolicy( Qt::CustomContextMenu );
277 setHeaderHidden(
true );
278 setDropIndicatorShown(
true );
282 void QgsDockBrowserTreeView::setAction( QDropEvent *e )
286 if ( e->mimeData()->hasFormat( QStringLiteral(
"application/qgis.layertreemodeldata" ) ) &&
287 e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
289 e->setDropAction( Qt::CopyAction );
293 void QgsDockBrowserTreeView::dragEnterEvent( QDragEnterEvent *e )
302 void QgsDockBrowserTreeView::dragMoveEvent( QDragMoveEvent *e )
313 QTreeView::dragMoveEvent( e );
317 if ( !e->mimeData()->hasFormat( QStringLiteral(
"application/x-vnd.qgis.qgis.uri" ) ) )
324 void QgsDockBrowserTreeView::dropEvent( QDropEvent *e )
327 QTreeView::dropEvent( e );
336 QgsBrowserTreeFilterProxyModel::QgsBrowserTreeFilterProxyModel( QObject *parent )
337 : QSortFilterProxyModel( parent )
338 , mPatternSyntax( QStringLiteral(
"normal" ) )
339 , mCaseSensitivity( Qt::CaseInsensitive )
341 setDynamicSortFilter(
true );
343 setSortCaseSensitivity( Qt::CaseInsensitive );
347 void QgsBrowserTreeFilterProxyModel::setBrowserModel(
QgsBrowserModel *model )
350 setSourceModel( model );
353 void QgsBrowserTreeFilterProxyModel::setFilterSyntax(
const QString &syntax )
355 QgsDebugMsg( QString(
"syntax = %1" ).arg( syntax ) );
356 if ( mPatternSyntax == syntax )
358 mPatternSyntax = syntax;
362 void QgsBrowserTreeFilterProxyModel::setFilter(
const QString &filter )
364 QgsDebugMsg( QString(
"filter = %1" ).arg( mFilter ) );
365 if ( mFilter == filter )
371 void QgsBrowserTreeFilterProxyModel::setCaseSensitive(
bool caseSensitive )
373 mCaseSensitivity = caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive;
377 void QgsBrowserTreeFilterProxyModel::updateFilter()
379 QgsDebugMsg( QString(
"filter = %1 syntax = %2" ).arg( mFilter, mPatternSyntax ) );
381 if ( mPatternSyntax == QLatin1String(
"normal" ) )
383 Q_FOREACH (
const QString &
f, mFilter.split(
'|' ) )
385 QRegExp rx( QString(
"*%1*" ).arg( f.trimmed() ) );
386 rx.setPatternSyntax( QRegExp::Wildcard );
387 rx.setCaseSensitivity( mCaseSensitivity );
388 mREList.append( rx );
391 else if ( mPatternSyntax == QLatin1String(
"wildcard" ) )
393 Q_FOREACH (
const QString &f, mFilter.split(
'|' ) )
395 QRegExp rx( f.trimmed() );
396 rx.setPatternSyntax( QRegExp::Wildcard );
397 rx.setCaseSensitivity( mCaseSensitivity );
398 mREList.append( rx );
403 QRegExp rx( mFilter.trimmed() );
404 rx.setPatternSyntax( QRegExp::RegExp );
405 rx.setCaseSensitivity( mCaseSensitivity );
406 mREList.append( rx );
411 bool QgsBrowserTreeFilterProxyModel::filterAcceptsString(
const QString &value )
const 413 if ( mPatternSyntax == QLatin1String(
"normal" ) || mPatternSyntax == QLatin1String(
"wildcard" ) )
415 Q_FOREACH (
const QRegExp &rx, mREList )
417 QgsDebugMsg( QString(
"value: [%1] rx: [%2] match: %3" ).arg( value, rx.pattern() ).arg( rx.exactMatch( value ) ) );
418 if ( rx.exactMatch( value ) )
424 Q_FOREACH (
const QRegExp &rx, mREList )
426 QgsDebugMsg( QString(
"value: [%1] rx: [%2] match: %3" ).arg( value, rx.pattern() ).arg( rx.indexIn( value ) ) );
427 if ( rx.indexIn( value ) != -1 )
434 bool QgsBrowserTreeFilterProxyModel::filterAcceptsRow(
int sourceRow,
const QModelIndex &sourceParent )
const 436 if ( mFilter.isEmpty() || !mModel )
439 QModelIndex sourceIndex = mModel->
index( sourceRow, 0, sourceParent );
440 return filterAcceptsItem( sourceIndex ) || filterAcceptsAncestor( sourceIndex ) || filterAcceptsDescendant( sourceIndex );
443 bool QgsBrowserTreeFilterProxyModel::filterAcceptsAncestor(
const QModelIndex &sourceIndex )
const 448 QModelIndex sourceParentIndex = mModel->
parent( sourceIndex );
449 if ( !sourceParentIndex.isValid() )
451 if ( filterAcceptsItem( sourceParentIndex ) )
454 return filterAcceptsAncestor( sourceParentIndex );
457 bool QgsBrowserTreeFilterProxyModel::filterAcceptsDescendant(
const QModelIndex &sourceIndex )
const 462 for (
int i = 0; i < mModel->
rowCount( sourceIndex ); i++ )
465 QModelIndex sourceChildIndex = mModel->
index( i, 0, sourceIndex );
466 if ( filterAcceptsItem( sourceChildIndex ) )
468 if ( filterAcceptsDescendant( sourceChildIndex ) )
474 bool QgsBrowserTreeFilterProxyModel::filterAcceptsItem(
const QModelIndex &sourceIndex )
const 480 return ( filterAcceptsString( mModel->
data( sourceIndex, Qt::DisplayRole ).toString() )
481 || ( !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).
QString htmlMetadata() const override
Obtain a formatted HTML string containing assorted metadata for this layer.
This class is a composition of two QSettings instances:
QgsMapLayer::LayerType mapLayerType() const
Returns QgsMapLayer::LayerType.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Provides the number of rows of data exposed by the model.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Used to supply item data to views and delegates.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
static QString reportStyleSheet()
get a standard css style sheet for reports.
bool isValid() const
Return the status of the layer.
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.
void setValue(const QString &key, const QVariant &value, const QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
QString htmlMetadata() const override
Obtain a formatted HTML string containing assorted metadata for this layer.
QModelIndex parent(const QModelIndex &index) const override
Returns the parent of the model item with the given index.
LayerType
Types of layers that can be added to a map.
QgsCoordinateReferenceSystem crs
QgsCoordinateReferenceSystem crs() const
Returns the layer's spatial reference system.
A directory: contains subdirectories and layers.
Base class for all items in the model.
Custom sort role, see QgsDataItem::sortKey()
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), const Section section=NoSection) const
Returns the value for setting key.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Returns the index of the item in the model specified by the given row, column and parent index...
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.
Item that represents a layer that can be opened with one of the providers.
Represents a vector layer which manages a vector based data sets.
QString authid() const
Returns the authority identifier for the CRS.