17#include "moc_qgshistorywidget.cpp" 
   24#include <QTextBrowser> 
   28#include <QDesktopServices> 
   37  mProxyModel = 
new QgsHistoryEntryProxyModel( 
this );
 
   38  mProxyModel->setSourceModel( mModel );
 
   40  mTreeView->setModel( mProxyModel );
 
   42  mFilterEdit->setShowClearButton( 
true );
 
   43  mFilterEdit->setShowSearchIcon( 
true );
 
   44  connect( mFilterEdit, &QLineEdit::textChanged, mProxyModel, &QgsHistoryEntryProxyModel::setFilter );
 
   45  connect( mTreeView->selectionModel(), &QItemSelectionModel::currentChanged, 
this, &QgsHistoryWidget::currentItemChanged );
 
   46  connect( mTreeView, &QTreeView::doubleClicked, 
this, &QgsHistoryWidget::nodeDoubleClicked );
 
   47  mTreeView->setExpandsOnDoubleClick( 
false );
 
   49  mTreeView->setContextMenuPolicy( Qt::CustomContextMenu );
 
   50  connect( mTreeView, &QWidget::customContextMenuRequested, 
this, &QgsHistoryWidget::showNodeContextMenu );
 
   53  const QModelIndex firstGroup = mProxyModel->index( 0, 0, QModelIndex() );
 
   54  mTreeView->expand( firstGroup );
 
   57  mSplitter->restoreState( settings.
value( QStringLiteral( 
"history/splitterState%1" ).arg( providerId ) ).toByteArray() );
 
   59  connect( mSplitter, &QSplitter::splitterMoved, 
this, [providerId, 
this] {
 
   61    settings.
setValue( QStringLiteral( 
"history/splitterState%1" ).arg( providerId ), mSplitter->saveState() );
 
 
   65void QgsHistoryWidget::currentItemChanged( 
const QModelIndex &selected, 
const QModelIndex & )
 
   67  QWidget *newWidget = 
nullptr;
 
   70    newWidget = node->createWidget( mContext );
 
   73      const QString html = node->html( mContext );
 
   74      if ( !html.isEmpty() )
 
   76        QTextBrowser *htmlBrowser = 
new QTextBrowser();
 
   77        htmlBrowser->setOpenLinks( 
false );
 
   78        htmlBrowser->setHtml( html );
 
   79        connect( htmlBrowser, &QTextBrowser::anchorClicked, 
this, &QgsHistoryWidget::urlClicked );
 
   81        newWidget = htmlBrowser;
 
   86      mContainerStackedWidget->addWidget( newWidget );
 
   87      mContainerStackedWidget->setCurrentWidget( newWidget );
 
   94    if ( mContainerStackedWidget->count() > 1 )
 
   96      mContainerStackedWidget->removeWidget( mContainerStackedWidget->widget( 1 ) );
 
   97      mContainerStackedWidget->setCurrentIndex( 0 );
 
  102void QgsHistoryWidget::nodeDoubleClicked( 
const QModelIndex &index )
 
  106    if ( node->doubleClicked( mContext ) )
 
  111  if ( mTreeView->isExpanded( index ) )
 
  112    mTreeView->collapse( index );
 
  114    mTreeView->expand( index );
 
  117void QgsHistoryWidget::showNodeContextMenu( 
const QPoint &pos )
 
  121    QMenu *menu = 
new QMenu();
 
  123    node->populateContextMenu( menu, mContext );
 
  124    if ( !menu->isEmpty() )
 
  126      menu->exec( mTreeView->mapToGlobal( pos ) );
 
  132void QgsHistoryWidget::urlClicked( 
const QUrl &url )
 
  134  const QFileInfo file( url.toLocalFile() );
 
  135  if ( file.exists() && !file.isDir() )
 
  138    QDesktopServices::openUrl( url );
 
  146QgsHistoryEntryProxyModel::QgsHistoryEntryProxyModel( QObject *parent )
 
  147  : QSortFilterProxyModel( parent )
 
  149  setDynamicSortFilter( 
true );
 
  150  setRecursiveFilteringEnabled( 
true );
 
  153void QgsHistoryEntryProxyModel::setFilter( 
const QString &filter )
 
  155  if ( filter == mFilter )
 
  162bool QgsHistoryEntryProxyModel::filterAcceptsRow( 
int source_row, 
const QModelIndex &source_parent )
 const 
  164  if ( mFilter.isEmpty() )
 
  167  const QModelIndex sourceIndex = sourceModel()->index( source_row, 0, source_parent );
 
  168  if ( 
QgsHistoryEntryNode *node = qobject_cast<QgsHistoryEntryModel *>( sourceModel() )->index2node( sourceIndex ) )
 
  170    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.
 
The QgsHistoryProviderRegistry is a registry for objects which track user history (i....
 
Contains settings which reflect the context in which a history widget is shown, e....
 
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.
 
This class is a composition of two QSettings instances:
 
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.