changeset 13518:bace956a3724

Put history model part into OctaveLink.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Tue, 19 Jul 2011 15:53:43 +0200
parents 86adc9c4ec4b
children 35ecb6063c7b
files gui/src/HistoryDockWidget.cpp gui/src/HistoryDockWidget.h gui/src/MainWindow.cpp gui/src/MainWindow.h gui/src/OctaveLink.cpp gui/src/OctaveLink.h
diffstat 6 files changed, 36 insertions(+), 76 deletions(-) [+]
line wrap: on
line diff
--- 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."));
-  */
-}
--- a/gui/src/HistoryDockWidget.h
+++ b/gui/src/HistoryDockWidget.h
@@ -21,7 +21,7 @@
 
 #include <QDockWidget>
 #include <QListView>
-#include <QStringListModel>
+#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
--- 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,
--- 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);
       }
   }
--- 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 ();
 }
--- a/gui/src/OctaveLink.h
+++ b/gui/src/OctaveLink.h
@@ -79,6 +79,7 @@
 #include <QVector>
 #include <QSemaphore>
 #include <QObject>
+#include <QStringListModel>
 
 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;