18#include <QStandardItemModel>
32 listView->setToolTip( tr(
"Double-click on item to execute" ) );
34 mModel =
new CodeHistoryModel( listView );
35 listView->setModel( mModel );
39 QShortcut *deleteShortcut =
new QShortcut( QKeySequence( Qt::Key_Delete ),
this );
40 connect( deleteShortcut, &QShortcut::activated,
this, &QgsCodeEditorHistoryDialog::deleteItem );
41 connect( listView, &QListView::doubleClicked,
this, &QgsCodeEditorHistoryDialog::runCommand );
42 connect( mButtonReloadHistory, &QPushButton::clicked,
this, & QgsCodeEditorHistoryDialog::reloadHistory );
43 connect( mButtonSaveHistory, &QPushButton::clicked,
this, & QgsCodeEditorHistoryDialog::saveHistory );
44 connect( mButtonRunHistory, &QPushButton::clicked,
this, &QgsCodeEditorHistoryDialog::executeSelectedHistory );
47void QgsCodeEditorHistoryDialog::executeSelectedHistory()
52 QModelIndexList selection = listView->selectionModel()->selectedIndexes();
53 std::sort( selection.begin(), selection.end() );
54 for (
const QModelIndex &index : std::as_const( selection ) )
56 mEditor->runCommand( index.data( Qt::DisplayRole ).toString() );
60void QgsCodeEditorHistoryDialog::runCommand(
const QModelIndex &index )
65 mEditor->runCommand( index.data( Qt::DisplayRole ).toString() );
68void QgsCodeEditorHistoryDialog::saveHistory()
73 mEditor->writeHistoryFile();
76void QgsCodeEditorHistoryDialog::reloadHistory()
80 mModel->setStringList( mEditor->history() );
83 listView->scrollToBottom();
84 listView->setCurrentIndex( mModel->index( mModel->rowCount() - 1, 0 ) );
87void QgsCodeEditorHistoryDialog::deleteItem()
89 const QModelIndexList selection = listView->selectionModel()->selectedRows();
90 if ( selection.empty() )
93 QList< int > selectedRows;
94 selectedRows.reserve( selection.size() );
95 for (
const QModelIndex &index : selection )
96 selectedRows << index.row();
97 std::sort( selectedRows.begin(), selectedRows.end(), std::greater< int >() );
99 for (
int row : std::as_const( selectedRows ) )
102 mEditor->removeHistoryCommand( row );
105 mModel->removeRow( row );
110CodeHistoryModel::CodeHistoryModel( QObject *parent )
111 : QStringListModel( parent )
116QVariant CodeHistoryModel::data(
const QModelIndex &index,
int role )
const
118 if ( role == Qt::FontRole )
123 return QStringListModel::data( index, role );
QgsCodeEditorHistoryDialog(QgsCodeEditor *editor, QWidget *parent=nullptr)
Constructor for QgsCodeEditorHistoryDialog.
A text editor based on QScintilla2.
static QFont getMonospaceFont()
Returns the monospaced font to use for code editors.
static QString languageToString(Qgis::ScriptLanguage language)
Returns a user-friendly, translated name of the specified script language.