# HG changeset patch # User Jacob Dawid # Date 1311083623 -7200 # Node ID bace956a37249c8e3d372c6323bb1d86572da059 # Parent 86adc9c4ec4bd1eec4bf8582f7f6c0076488015e Put history model part into OctaveLink. diff --git a/gui/src/HistoryDockWidget.cpp b/gui/src/HistoryDockWidget.cpp --- a/gui/src/HistoryDockWidget.cpp +++ b/gui/src/HistoryDockWidget.cpp @@ -26,18 +26,10 @@ } 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->setModel (OctaveLink::instance ()->historyModel()); m_historyListView->setAlternatingRowColors (true); m_historyListView->setEditTriggers (QAbstractItemView::NoEditTriggers); QHBoxLayout *layout = new QHBoxLayout (); @@ -49,14 +41,4 @@ layout->setMargin (2); widget ()->setLayout (layout); - //connect (m_historyListView, SIGNAL (doubleClicked (QModelIndex)), this, - // SLOT (handleListViewItemDoubleClicked (QModelIndex))); } - -void -HistoryDockWidget::updateHistory (QStringList history) -{/* - m_historyListModel->setStringList (history); - emit information (tr ("History updated.")); - */ -} diff --git a/gui/src/HistoryDockWidget.h b/gui/src/HistoryDockWidget.h --- a/gui/src/HistoryDockWidget.h +++ b/gui/src/HistoryDockWidget.h @@ -21,7 +21,7 @@ #include #include -#include +#include "OctaveLink.h" class HistoryDockWidget:public QDockWidget { @@ -32,15 +32,10 @@ signals: void information (QString message); - void commandDoubleClicked (QString command); - -private slots: - void handleListViewItemDoubleClicked (QModelIndex modelIndex); private: void construct (); QListView *m_historyListView; - QStringListModel *m_historyListModel; }; #endif // HISTORYDOCKWIDGET_H diff --git a/gui/src/MainWindow.cpp b/gui/src/MainWindow.cpp --- a/gui/src/MainWindow.cpp +++ b/gui/src/MainWindow.cpp @@ -257,8 +257,6 @@ 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, diff --git a/gui/src/MainWindow.h b/gui/src/MainWindow.h --- a/gui/src/MainWindow.h +++ b/gui/src/MainWindow.h @@ -156,13 +156,7 @@ setVariablesList (symbolTable); } - // Collect history list. - QStringList history = OctaveLink::instance ()->currentHistory (); - if (history.length ()) - { - m_mainWindow->historyDockWidget ()->updateHistory (history); - } - + OctaveLink::instance ()->updateHistoryModel (); usleep (100000); } } diff --git a/gui/src/OctaveLink.cpp b/gui/src/OctaveLink.cpp --- a/gui/src/OctaveLink.cpp +++ b/gui/src/OctaveLink.cpp @@ -32,6 +32,7 @@ { m_symbolTableSemaphore = new QSemaphore (1); m_historySemaphore = new QSemaphore (1); + m_historyModel = new QStringListModel (this); } OctaveLink::~OctaveLink () @@ -118,26 +119,6 @@ emit symbolTableChanged (); } - -void -OctaveLink::fetchHistory () -{ - int currentLen = command_history::length (); - if (currentLen != m_previousHistoryLength) - { - m_historySemaphore->acquire (); - for (int i = m_previousHistoryLength; i < currentLen; i++) - { - QString entry = QString(command_history::get_entry (i).c_str()); - if (!entry.startsWith ("#")) - m_historyBuffer.append (entry); - } - m_historySemaphore->release (); - m_previousHistoryLength = currentLen; - emit historyChanged (); - } -} - QList < SymbolRecord > OctaveLink::currentSymbolTable () { QList < SymbolRecord > m_symbolTableCopy; @@ -151,18 +132,36 @@ return m_symbolTableCopy; } -QStringList -OctaveLink::currentHistory () + +void +OctaveLink::updateHistoryModel () { - m_historySemaphore->acquire (); - QStringList historyBuffer = m_historyBuffer; - m_historySemaphore->release (); - return historyBuffer; + // TODO: Use the following code to update the history model. + /* + int currentLen = command_history::length (); + if (currentLen != m_previousHistoryLength) + { + m_historySemaphore->acquire (); + for (int i = m_previousHistoryLength; i < currentLen; i++) + { + QString entry = QString(command_history::get_entry (i).c_str()); + if (!entry.startsWith ("#")) + m_historyBuffer.append (entry); + } + m_historySemaphore->release (); + m_previousHistoryLength = currentLen; + } + */ +} + +QStringListModel * +OctaveLink::historyModel () +{ + return m_historyModel; } void OctaveLink::processOctaveServerData () { fetchSymbolTable (); - fetchHistory (); } diff --git a/gui/src/OctaveLink.h b/gui/src/OctaveLink.h --- a/gui/src/OctaveLink.h +++ b/gui/src/OctaveLink.h @@ -79,6 +79,7 @@ #include #include #include +#include typedef symbol_table::symbol_record SymbolRecord; typedef octave_value OctaveValue; @@ -107,12 +108,11 @@ */ QList < SymbolRecord > currentSymbolTable (); - /** - * Returns a copy of the current history buffer. - * \return Copy of the current history buffer. - */ - QStringList - currentHistory (); + void + updateHistoryModel (); + + QStringListModel * + historyModel (); void processOctaveServerData (); @@ -124,18 +124,9 @@ void fetchSymbolTable (); - /** - * Updates the current history buffer with new data - * from octave. - */ - void - fetchHistory (); - signals: void symbolTableChanged (); - void - historyChanged (); private: OctaveLink (); @@ -146,6 +137,7 @@ QList < SymbolRecord > m_symbolTableBuffer; /** History related member variables. */ + QStringListModel *m_historyModel; QSemaphore *m_historySemaphore; QStringList m_historyBuffer; int m_previousHistoryLength;