17#include "moc_qgscodeeditorhistorydialog.cpp"
19#include <QStandardItemModel>
33 listView->setToolTip( tr(
"Double-click on item to execute" ) );
35 mModel =
new CodeHistoryModel( listView );
36 listView->setModel( mModel );
40 QShortcut *deleteShortcut =
new QShortcut( QKeySequence( Qt::Key_Delete ),
this );
41 connect( deleteShortcut, &QShortcut::activated,
this, &QgsCodeEditorHistoryDialog::deleteItem );
42 connect( listView, &QListView::doubleClicked,
this, &QgsCodeEditorHistoryDialog::runCommand );
43 connect( mButtonReloadHistory, &QPushButton::clicked,
this, &QgsCodeEditorHistoryDialog::reloadHistory );
44 connect( mButtonSaveHistory, &QPushButton::clicked,
this, &QgsCodeEditorHistoryDialog::saveHistory );
45 connect( mButtonRunHistory, &QPushButton::clicked,
this, &QgsCodeEditorHistoryDialog::executeSelectedHistory );
48void QgsCodeEditorHistoryDialog::executeSelectedHistory()
53 QModelIndexList selection = listView->selectionModel()->selectedIndexes();
54 std::sort( selection.begin(), selection.end() );
55 for (
const QModelIndex &index : std::as_const( selection ) )
57 mEditor->runCommand( index.data( Qt::DisplayRole ).toString() );
61void QgsCodeEditorHistoryDialog::runCommand(
const QModelIndex &index )
66 mEditor->runCommand( index.data( Qt::DisplayRole ).toString() );
69void QgsCodeEditorHistoryDialog::saveHistory()
74 mEditor->writeHistoryFile();
77void QgsCodeEditorHistoryDialog::reloadHistory()
81 mModel->setStringList( mEditor->history() );
84 listView->scrollToBottom();
85 listView->setCurrentIndex( mModel->index( mModel->rowCount() - 1, 0 ) );
88void QgsCodeEditorHistoryDialog::deleteItem()
90 const QModelIndexList selection = listView->selectionModel()->selectedRows();
91 if ( selection.empty() )
94 QList<int> selectedRows;
95 selectedRows.reserve( selection.size() );
96 for (
const QModelIndex &index : selection )
97 selectedRows << index.row();
98 std::sort( selectedRows.begin(), selectedRows.end(), std::greater<int>() );
100 for (
int row : std::as_const( selectedRows ) )
103 mEditor->removeHistoryCommand( row );
106 mModel->removeRow( row );
111CodeHistoryModel::CodeHistoryModel( QObject *parent )
112 : QStringListModel( parent )
117QVariant CodeHistoryModel::data(
const QModelIndex &index,
int role )
const
119 if ( role == Qt::FontRole )
124 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.