Mercurial > hg > octave-terminal
changeset 13465:3542af417878
Added buttons to load, save and clear the workspace. Double-clicking an item in the history list will now send the command to the console.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Sun, 17 Apr 2011 22:12:02 +0200 |
parents | 661f66fb26a7 |
children | 32e2bc78ae77 |
files | gui//src/HistoryDockWidget.cpp gui//src/HistoryDockWidget.h gui//src/MainWindow.cpp gui//src/MainWindow.h gui//src/VariablesDockWidget.cpp gui//src/VariablesDockWidget.h |
diffstat | 6 files changed, 82 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/gui//src/HistoryDockWidget.cpp +++ b/gui//src/HistoryDockWidget.cpp @@ -25,12 +25,17 @@ construct(); } +void HistoryDockWidget::handleListViewItemDoubleClicked(QModelIndex modelIndex) { + QString command = m_historyListModel->data(modelIndex, 0).toString(); + emit commandDoubleClicked(command); +} + void HistoryDockWidget::construct() { m_historyListModel = new QStringListModel(); m_historyListView = new QListView(this); m_historyListView->setModel(m_historyListModel); m_historyListView->setAlternatingRowColors(true); - + m_historyListView->setEditTriggers(QAbstractItemView::NoEditTriggers); QHBoxLayout *layout = new QHBoxLayout(); setWindowTitle("Command History"); @@ -40,14 +45,16 @@ layout->setMargin(2); widget()->setLayout(layout); + connect(m_historyListView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(handleListViewItemDoubleClicked(QModelIndex))); } void HistoryDockWidget::updateHistory(string_vector historyEntries) { QStringList stringList = m_historyListModel->stringList(); for(size_t i = 0; i < historyEntries.length(); i++) { QString command(historyEntries[i].c_str()); - if(!command.startsWith("#")) - stringList.push_front(QString("%1: ").arg(stringList.size() + 1) + command); + if(!command.startsWith("#")) { + stringList.push_front(command); + } } m_historyListModel->setStringList(stringList); emit information("History updated.");
--- a/gui//src/HistoryDockWidget.h +++ b/gui//src/HistoryDockWidget.h @@ -41,6 +41,10 @@ signals: void information(QString message); + void commandDoubleClicked(QString command); + +private slots: + void handleListViewItemDoubleClicked(QModelIndex modelIndex); private: void construct();
--- a/gui//src/MainWindow.cpp +++ b/gui//src/MainWindow.cpp @@ -62,6 +62,22 @@ m_browserWidget->load(QUrl(url)); } +void MainWindow::handleSaveWorkspaceRequest() { + // TODO: Handle saving of workspace. +} + +void MainWindow::handleLoadWorkspaceRequest() { + // TODO: Handle loading of workspace. +} + +void MainWindow::handleClearWorkspaceRequest() { + // TODO: Handle clearing of workspace. +} + +void MainWindow::handleCommandDoubleClicked(QString command) { + m_octaveTerminal->sendText(command); +} + void MainWindow::closeEvent(QCloseEvent *closeEvent) { m_isRunning = false; reportStatusMessage("Saving data and shutting down."); @@ -123,6 +139,10 @@ connect(m_filesDockWidget, SIGNAL(openFile(QString)), this, SLOT(handleOpenFileRequest(QString))); connect(m_historyDockWidget, SIGNAL(information(QString)), this, SLOT(reportStatusMessage(QString))); + connect(m_historyDockWidget, SIGNAL(commandDoubleClicked(QString)), this, SLOT(handleCommandDoubleClicked(QString))); + connect(m_variablesDockWidget, SIGNAL(saveWorkspace()), this, SLOT(handleSaveWorkspaceRequest())); + connect(m_variablesDockWidget, SIGNAL(loadWorkspace()), this, SLOT(handleLoadWorkspaceRequest())); + connect(m_variablesDockWidget, SIGNAL(clearWorkspace()), this, SLOT(handleClearWorkspaceRequest())); openWebPage("http://www.gnu.org/software/octave/doc/interpreter/"); m_serviceWidget->load(QUrl("http://savannah.gnu.org/bugs/?group=octave"));
--- a/gui//src/MainWindow.h +++ b/gui//src/MainWindow.h @@ -100,6 +100,10 @@ void handleOpenFileRequest(QString fileName); void reportStatusMessage(QString statusMessage); void openWebPage(QString url); + void handleSaveWorkspaceRequest(); + void handleLoadWorkspaceRequest(); + void handleClearWorkspaceRequest(); + void handleCommandDoubleClicked(QString command); protected: void closeEvent(QCloseEvent *closeEvent);
--- a/gui//src/VariablesDockWidget.cpp +++ b/gui//src/VariablesDockWidget.cpp @@ -1,5 +1,7 @@ #include "VariablesDockWidget.h" #include <QHBoxLayout> +#include <QVBoxLayout> +#include <QPushButton> VariablesDockWidget::VariablesDockWidget(QWidget *parent) : QDockWidget(parent) { @@ -14,16 +16,32 @@ m_variablesTreeWidget = new QTreeWidget(this); m_variablesTreeWidget->setHeaderHidden(false); m_variablesTreeWidget->setHeaderLabels(headerLabels); - QHBoxLayout *layout = new QHBoxLayout(); + QVBoxLayout *layout = new QVBoxLayout(); setWindowTitle("Workspace"); setWidget(new QWidget()); layout->addWidget(m_variablesTreeWidget); - layout->setMargin(2); + QWidget *buttonBar = new QWidget(this); + layout->addWidget(buttonBar); + QHBoxLayout *buttonBarLayout = new QHBoxLayout(); + QPushButton *saveWorkspaceButton = new QPushButton("Save", buttonBar); + QPushButton *loadWorkspaceButton = new QPushButton("Load", buttonBar); + QPushButton *clearWorkspaceButton = new QPushButton("Clear", buttonBar); + buttonBarLayout->addWidget(saveWorkspaceButton); + buttonBarLayout->addWidget(loadWorkspaceButton); + buttonBarLayout->addWidget(clearWorkspaceButton); + buttonBarLayout->setMargin(2); + buttonBar->setLayout(buttonBarLayout); + + layout->setMargin(2); widget()->setLayout(layout); + connect(saveWorkspaceButton, SIGNAL(clicked()), this, SLOT(emitSaveWorkspace())); + connect(loadWorkspaceButton, SIGNAL(clicked()), this, SLOT(emitLoadWorkspace())); + connect(clearWorkspaceButton, SIGNAL(clicked()), this, SLOT(emitClearWorkspace())); + QTreeWidgetItem *treeWidgetItem = new QTreeWidgetItem(); treeWidgetItem->setData(0, 0, QString("Local")); m_variablesTreeWidget->insertTopLevelItem(0, treeWidgetItem); @@ -42,7 +60,7 @@ m_variablesTreeWidget->expandAll(); m_variablesTreeWidget->setAlternatingRowColors(true); - m_variablesTreeWidget->setAnimated(true); + m_variablesTreeWidget->setAnimated(true); } void VariablesDockWidget::updateTreeEntry(QTreeWidgetItem *treeItem, SymbolRecord symbolRecord) { @@ -136,3 +154,15 @@ } } } + +void VariablesDockWidget::emitSaveWorkspace() { + emit saveWorkspace(); +} + +void VariablesDockWidget::emitLoadWorkspace() { + emit loadWorkspace(); +} + +void VariablesDockWidget::emitClearWorkspace() { + emit clearWorkspace(); +}
--- a/gui//src/VariablesDockWidget.h +++ b/gui//src/VariablesDockWidget.h @@ -8,10 +8,21 @@ class VariablesDockWidget : public QDockWidget { + Q_OBJECT public: VariablesDockWidget(QWidget *parent = 0); void setVariablesList(QList<SymbolRecord> symbolTable); +signals: + void saveWorkspace(); + void loadWorkspace(); + void clearWorkspace(); + +private slots: + void emitSaveWorkspace(); + void emitLoadWorkspace(); + void emitClearWorkspace(); + private: void construct(); void updateTreeEntry(QTreeWidgetItem *treeItem, SymbolRecord symbolRecord);