Mercurial > hg > octave-lyh
changeset 13426:c14c80c8c29d
Variable tree now gets updated, further refactored OctaveLink as a prestep.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Wed, 13 Apr 2011 22:57:47 +0200 |
parents | 4cc9ec20c2be |
children | 3c5d9483dbe5 |
files | gui//src/MainWindow.h gui//src/OctaveLink.cpp gui//src/OctaveLink.h gui//src/VariablesDockWidget.cpp gui//src/VariablesDockWidget.h |
diffstat | 5 files changed, 97 insertions(+), 78 deletions(-) [+] |
line wrap: on
line diff
--- a/gui//src/MainWindow.h +++ b/gui//src/MainWindow.h @@ -157,20 +157,20 @@ while(m_mainWindow->isRunning()) { // Get a full variable list. - std::vector<OctaveLink::VariableMetaData> variables + QList<OctaveLink::VariableMetaData> variables = OctaveLink::instance()->variableInfoList(); if(variables.size()) { - // TODO: Update variables view. + m_mainWindow->variablesDockWidget()->setVariablesList(variables); } // Check whether any requested variables have been returned. - std::vector<OctaveLink::RequestedVariable> reqVars + QList<OctaveLink::RequestedVariable> reqVars = OctaveLink::instance()->requestedVariables(); - for(std::vector<OctaveLink::RequestedVariable>::iterator it = reqVars.begin(); - it != reqVars.end(); it++ ) { + //for(std::vector<OctaveLink::RequestedVariable>::iterator it = reqVars.begin(); + // it != reqVars.end(); it++ ) { // TODO: Process requested variables. - } + //} // Collect history list. string_vector historyList = OctaveLink::instance()->getHistoryList();
--- a/gui//src/OctaveLink.cpp +++ b/gui//src/OctaveLink.cpp @@ -83,6 +83,7 @@ #include <QFileInfo> #include <QMutexLocker> +#include <QList> OctaveLink OctaveLink::m_singleton; @@ -128,40 +129,22 @@ *******************************************************************************/ //************************************************************************* -std::vector<OctaveLink::VariableMetaData> OctaveLink::variableInfoList(void) { +QList<OctaveLink::VariableMetaData> OctaveLink::variableInfoList() { QMutexLocker mutexLocker(&m_internalAccessMutex); - - // Copy the list of variable information - std::vector<VariableMetaData> retval( m_variableSymbolTableList.size() ); - std::copy( m_variableSymbolTableList.begin(), m_variableSymbolTableList.end(), retval.begin() ); - m_variableSymbolTableList = std::vector<VariableMetaData>(); - - return retval; + return m_variableSymbolTableList; } //************************************************************************* -std::vector<OctaveLink::RequestedVariable> OctaveLink::requestedVariables(void) -{ +QList<OctaveLink::RequestedVariable> OctaveLink::requestedVariables() { QMutexLocker mutexLocker(&m_internalAccessMutex); - - // Copy the list of requested variables - std::vector<RequestedVariable> retval( m_requestedVariables.size() ); - std::copy( m_requestedVariables.begin(), m_requestedVariables.end(), retval.begin() ); - m_requestedVariables = std::vector<RequestedVariable>(); - - return retval; + return m_requestedVariables; } //************************************************************************* -int OctaveLink::setRequestedVariableNames( std::vector<std::string> variables_names ) -{ +int OctaveLink::setRequestedVariableNames(QList<QString> variablesNames) { QMutexLocker mutexLocker(&m_internalAccessMutex); - - // Set the list of requested variables - m_variablesRequestList = std::vector<std::string>( variables_names.size() ); - std::copy( variables_names.begin(), variables_names.end(), m_variablesRequestList.begin() ); - + m_variablesRequestList = variablesNames; return 0; } @@ -253,7 +236,7 @@ process_breakpoint_action(); processBreakpointAndRemoveModify(); processRequestedVariables(); - setVariableInfoList(); + retrieveVariables(); setHistoryList(); setBreakPointList(); @@ -267,40 +250,24 @@ //************************************************************************* -int OctaveLink::setVariableInfoList( void ) -{ - static std::vector<VariableMetaData> lastVars; - std::vector<VariableMetaData> currVars; - std::list<symbol_table::symbol_record> lvars = symbol_table::all_variables(); - std::list<symbol_table::symbol_record>::iterator it; +void OctaveLink::retrieveVariables() { + QList<VariableMetaData> currentVariables; + std::list<symbol_table::symbol_record> allVariables = symbol_table::all_variables(); + std::list<symbol_table::symbol_record>::iterator iterator; - for ( it = lvars.begin() ; it != lvars.end() ; it++ ) - { - octave_value varval( it->varval() ); - std::string nm = (*it).name(); - - dim_vector dims = varval.dims (); + for(iterator = allVariables.begin(); iterator != allVariables.end(); iterator++) { + octave_value octaveVariableValue(iterator->varval()); - VariableMetaData tempVar; - tempVar.variableName = it->name(); - tempVar.dimensionalSize.push_back( varval.rows() ); - tempVar.dimensionalSize.push_back( varval.columns() ); - tempVar.byteSize = varval.byte_size(); - tempVar.typeName = varval.type_name(); - - currVars.push_back(tempVar); - } + VariableMetaData variableMetaData; + variableMetaData.variableName = QString(iterator->name().c_str()); + variableMetaData.dimensionalSize.push_back(octaveVariableValue.rows()); + variableMetaData.dimensionalSize.push_back(octaveVariableValue.columns()); + variableMetaData.byteSize = octaveVariableValue.byte_size(); + variableMetaData.typeName = QString(octaveVariableValue.type_name().c_str()); + currentVariables.append(variableMetaData); + } - if ( lastVars != currVars ) - { - lastVars = currVars; - - // Copy currVars into octave_server::variable_symtab_list - m_variableSymbolTableList = std::vector<VariableMetaData>( currVars.size() ); - - std::copy( currVars.begin(), currVars.end(), m_variableSymbolTableList.begin() ); - } - return 0; + m_variableSymbolTableList = currentVariables; }
--- a/gui//src/OctaveLink.h +++ b/gui//src/OctaveLink.h @@ -39,6 +39,9 @@ #include <string> #include <vector> #include <QMutex> +#include <QList> +#include <QString> +#include <QVector> /** * \class OctaveLink @@ -92,16 +95,16 @@ typedef struct VariableMetaData { /** The name of the variable. */ - std::string variableName; + QString variableName; /** The dimensional size of the variable. */ - std::vector<int> dimensionalSize; + QVector<int> dimensionalSize; /** The size of the variable in bytes. */ unsigned long long byteSize; /** The name of the variable type. */ - std::string typeName; + QString typeName; friend int operator==(const VariableMetaData& left, const VariableMetaData& right) { @@ -137,13 +140,13 @@ int setBreakpointAction(BreakPointAction action); /** Variable related methods. */ - std::vector<VariableMetaData> variableInfoList(void); + QList<VariableMetaData> variableInfoList(void); /** TODO: Describe. */ - std::vector<RequestedVariable> requestedVariables(void); + QList<RequestedVariable> requestedVariables(void); /** TODO: Describe. */ - int setRequestedVariableNames(std::vector<std::string> variableNames); + int setRequestedVariableNames(QList<QString> variableNames); /** * History related methods. @@ -189,8 +192,8 @@ int process_breakpoint_action(void); /** Variable related methods. */ - /** TODO: Describe. */ - int setVariableInfoList(void); + /** Retrieves all variables from Octave. */ + void retrieveVariables(void); /** TODO: Describe. */ int processRequestedVariables(void); @@ -215,13 +218,13 @@ BreakPointAction m_breakPointAction; /** Variable related member variables. */ - std::vector<VariableMetaData> m_variableSymbolTableList; - std::vector<std::string> m_variablesRequestList; + QList<VariableMetaData> m_variableSymbolTableList; + QList<QString> m_variablesRequestList; // NOTE: Create an overloaded operator<< for octave_value to do the // flattening. This will allow us to append easily to an ostringstream // for output. - std::vector<RequestedVariable> m_requestedVariables; + QList<RequestedVariable> m_requestedVariables; /** History related member variables. */ string_vector m_historyList;
--- a/gui//src/VariablesDockWidget.cpp +++ b/gui//src/VariablesDockWidget.cpp @@ -7,15 +7,61 @@ } void VariablesDockWidget::construct() { - m_variablesTreeView = new QTreeView(this); - + QStringList headerLabels; + headerLabels << "Name" << "Type" << "Value"; + m_variablesTreeWidget = new QTreeWidget(this); + m_variablesTreeWidget->setHeaderHidden(false); + m_variablesTreeWidget->setHeaderLabels(headerLabels); QHBoxLayout *layout = new QHBoxLayout(); setWindowTitle("Workspace"); setWidget(new QWidget()); - layout->addWidget(m_variablesTreeView); + layout->addWidget(m_variablesTreeWidget); layout->setMargin(2); widget()->setLayout(layout); + + QTreeWidgetItem *treeWidgetItem = new QTreeWidgetItem(); + treeWidgetItem->setData(0, 0, QString("Global")); + m_variablesTreeWidget->insertTopLevelItem(0, treeWidgetItem); + m_variablesTreeWidget->expandAll(); } + +void VariablesDockWidget::setVariablesList(QList<OctaveLink::VariableMetaData> variablesList) { + // This method may be a little bit confusing; variablesList is a complete list of all + // variables that are in the workspace currently. + QTreeWidgetItem *topLevelItem = m_variablesTreeWidget->topLevelItem(0); + + // First we check, if any variables that exist in the model tree have to be updated + // or created. So we walk the variablesList check against the tree. + foreach(OctaveLink::VariableMetaData variable, variablesList) { + int childCount = topLevelItem->childCount(); + bool alreadyExists = false; + QTreeWidgetItem *child; + + // Search for the corresponding item in the tree. If it has been found, child + // will contain the appropriate QTreeWidgetItem* pointing at it. + for(int i = 0; i < childCount; i++) { + child = topLevelItem->child(i); + if(child->data(0, 0).toString() == variable.variableName) { + alreadyExists = true; + break; + } + } + + // If it already exists, just update it. + if(alreadyExists) { + child->setData(0, 0, variable.variableName); + child->setData(1, 0, variable.typeName); + } else { + // It does not exist, so create a new one and set the right values. + child = new QTreeWidgetItem(); + child->setData(0, 0, variable.variableName); + child->setData(1, 0, variable.typeName); + topLevelItem->addChild(child); + } + } + + // TODO: Check the tree against the list for deleted variables. +}
--- a/gui//src/VariablesDockWidget.h +++ b/gui//src/VariablesDockWidget.h @@ -2,16 +2,19 @@ #define VARIABLESDOCKWIDGET_H #include <QDockWidget> -#include <QTreeView> +#include <QTreeWidget> +#include "OctaveLink.h" class VariablesDockWidget : public QDockWidget { public: VariablesDockWidget(QWidget *parent = 0); + void setVariablesList(QList<OctaveLink::VariableMetaData> variablesList); + private: void construct(); - QTreeView *m_variablesTreeView; + QTreeWidget *m_variablesTreeWidget; }; #endif // VARIABLESDOCKWIDGET_H