17#include "moc_qgshistorywidget.cpp" 
   24#include <QTextBrowser> 
   28#include <QDesktopServices> 
   38  mProxyModel = 
new QgsHistoryEntryProxyModel( 
this );
 
   39  mProxyModel->setSourceModel( mModel );
 
   41  mTreeView->setModel( mProxyModel );
 
   43  mFilterEdit->setShowClearButton( 
true );
 
   44  mFilterEdit->setShowSearchIcon( 
true );
 
   45  connect( mFilterEdit, &QLineEdit::textChanged, mProxyModel, &QgsHistoryEntryProxyModel::setFilter );
 
   46  connect( mTreeView->selectionModel(), &QItemSelectionModel::currentChanged, 
this, &QgsHistoryWidget::currentItemChanged );
 
   47  connect( mTreeView, &QTreeView::doubleClicked, 
this, &QgsHistoryWidget::nodeDoubleClicked );
 
   48  mTreeView->setExpandsOnDoubleClick( 
false );
 
   50  mTreeView->setContextMenuPolicy( Qt::CustomContextMenu );
 
   51  connect( mTreeView, &QWidget::customContextMenuRequested, 
this, &QgsHistoryWidget::showNodeContextMenu );
 
   54  const QModelIndex firstGroup = mProxyModel->index( 0, 0, QModelIndex() );
 
   55  mTreeView->expand( firstGroup );
 
   58  mSplitter->restoreState( settings.
value( QStringLiteral( 
"history/splitterState%1" ).arg( providerId ) ).toByteArray() );
 
   60  connect( mSplitter, &QSplitter::splitterMoved, 
this, [providerId, 
this] {
 
   62    settings.
setValue( QStringLiteral( 
"history/splitterState%1" ).arg( providerId ), mSplitter->saveState() );
 
 
   66void QgsHistoryWidget::currentItemChanged( 
const QModelIndex &selected, 
const QModelIndex & )
 
   68  QWidget *newWidget = 
nullptr;
 
   71    newWidget = node->createWidget( mContext );
 
   74      const QString html = node->html( mContext );
 
   75      if ( !html.isEmpty() )
 
   77        QTextBrowser *htmlBrowser = 
new QTextBrowser();
 
   78        htmlBrowser->setOpenLinks( 
false );
 
   79        htmlBrowser->setHtml( html );
 
   80        connect( htmlBrowser, &QTextBrowser::anchorClicked, 
this, &QgsHistoryWidget::urlClicked );
 
   82        newWidget = htmlBrowser;
 
   87      mContainerStackedWidget->addWidget( newWidget );
 
   88      mContainerStackedWidget->setCurrentWidget( newWidget );
 
   95    if ( mContainerStackedWidget->count() > 1 )
 
   97      mContainerStackedWidget->removeWidget( mContainerStackedWidget->widget( 1 ) );
 
   98      mContainerStackedWidget->setCurrentIndex( 0 );
 
  103void QgsHistoryWidget::nodeDoubleClicked( 
const QModelIndex &index )
 
  107    if ( node->doubleClicked( mContext ) )
 
  112  if ( mTreeView->isExpanded( index ) )
 
  113    mTreeView->collapse( index );
 
  115    mTreeView->expand( index );
 
  118void QgsHistoryWidget::showNodeContextMenu( 
const QPoint &pos )
 
  122    QMenu *menu = 
new QMenu();
 
  124    node->populateContextMenu( menu, mContext );
 
  125    if ( !menu->isEmpty() )
 
  127      menu->exec( mTreeView->mapToGlobal( pos ) );
 
  133void QgsHistoryWidget::urlClicked( 
const QUrl &url )
 
  135  const QFileInfo file( url.toLocalFile() );
 
  136  if ( file.exists() && !file.isDir() )
 
  139    QDesktopServices::openUrl( url );
 
  147QgsHistoryEntryProxyModel::QgsHistoryEntryProxyModel( QObject *parent )
 
  148  : QSortFilterProxyModel( parent )
 
  150  setDynamicSortFilter( 
true );
 
  151  setRecursiveFilteringEnabled( 
true );
 
  154void QgsHistoryEntryProxyModel::setFilter( 
const QString &filter )
 
  156  if ( filter == mFilter )
 
  163bool QgsHistoryEntryProxyModel::filterAcceptsRow( 
int source_row, 
const QModelIndex &source_parent )
 const 
  165  if ( mFilter.isEmpty() )
 
  168  const QModelIndex sourceIndex = sourceModel()->index( source_row, 0, source_parent );
 
  169  if ( 
QgsHistoryEntryNode *node = qobject_cast<QgsHistoryEntryModel *>( sourceModel() )->index2node( sourceIndex ) )
 
  171    if ( !node->matchesString( mFilter ) )
 
QFlags< HistoryProviderBackend > HistoryProviderBackends
 
static QgsNative * nativePlatformInterface()
Returns the global native interface, which offers abstraction to the host OS's underlying public inte...
 
An item model representing history entries in a hierarchical tree structure.
 
QgsHistoryEntryNode * index2node(const QModelIndex &index) const
Returns node for given index.
 
Base class for nodes representing a QgsHistoryEntry.
 
A registry for objects which track user history (i.e.
 
Contains settings which reflect the context in which a history widget is shown, e....
 
void setHistoryWidget(QgsHistoryWidget *widget)
Sets the parent history widget.
 
QgsHistoryWidget(const QString &providerId=QString(), Qgis::HistoryProviderBackends backends=Qgis::HistoryProviderBackend::LocalProfile, QgsHistoryProviderRegistry *registry=nullptr, const QgsHistoryWidgetContext &context=QgsHistoryWidgetContext(), QWidget *parent=nullptr)
Constructor for QgsHistoryWidget, with the specified parent widget.
 
Stores settings for use within QGIS.
 
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
 
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.