Mercurial > hg > octave-nkf
changeset 13457:aa1d4754edc3
Improved octave value conversion.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Sat, 16 Apr 2011 15:54:53 +0200 |
parents | 8a8a479c2e78 |
children | 16d26344c2a2 |
files | gui//src/OctaveLink.cpp gui//src/OctaveLink.h gui//src/VariablesDockWidget.cpp |
diffstat | 3 files changed, 32 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/gui//src/OctaveLink.cpp +++ b/gui//src/OctaveLink.cpp @@ -52,6 +52,35 @@ return 0; } +QString OctaveLink::octaveValueAsQString(OctaveValue octaveValue) { + // Convert string. + if(octaveValue.is_string()) { + return QString("\"%1\"").arg(octaveValue.string_value().c_str()); + + // Convert real scalar. + } else if(octaveValue.is_real_scalar()) { + return QString("%1").arg(octaveValue.scalar_value()); + + // Convert complex scalar. + } else if(octaveValue.is_complex_scalar()) { + return QString("%1 + %2i").arg(octaveValue.scalar_value()).arg(octaveValue.complex_value().imag()); + + // Convert real matrix. + } else if(octaveValue.is_real_matrix()) { + // TODO: Convert real matrix into a string. + return QString("{matrix}"); + + // Convert complex matrix. + } else if(octaveValue.is_complex_matrix()) { + // TODO: Convert complex matrix into a string. + return QString("{complex matrix}"); + + // If everything else does not fit, we could not recognize the type. + } else { + return QString("<Type not recognized>"); + } +} + //************************************************************************* OctaveLink::OctaveLink() : m_previousHistoryLength(0) {
--- a/gui//src/OctaveLink.h +++ b/gui//src/OctaveLink.h @@ -74,6 +74,7 @@ #include <QVector> typedef symbol_table::symbol_record SymbolRecord; +typedef octave_value OctaveValue; /** * \class OctaveLink @@ -84,6 +85,7 @@ public: static OctaveLink *instance() { return &m_singleton; } static int readlineEventHook(void); + static QString octaveValueAsQString(OctaveValue octaveValue); /** * Enumeration used to identify breakpoint actions
--- a/gui//src/VariablesDockWidget.cpp +++ b/gui//src/VariablesDockWidget.cpp @@ -47,21 +47,7 @@ void VariablesDockWidget::updateTreeEntry(QTreeWidgetItem *treeItem, SymbolRecord symbolRecord) { treeItem->setData(0, 0, QString(symbolRecord.name().c_str())); treeItem->setData(1, 0, QString(symbolRecord.varval().type_name().c_str())); - - QString type = QString(symbolRecord.varval().type_name().c_str()); - if(type == "string") { - QString stringValue = QString("\"%1\"").arg(symbolRecord.varval().string_value().c_str()); - treeItem->setData(2, 0, stringValue); - } else if(type == "scalar") { - double scalarValue = symbolRecord.varval().scalar_value(); - treeItem->setData(2, 0, QString("%1").arg(scalarValue)); - } else if(type == "matrix") { - //Matrix matrixValue = symbolRecord.varval().matrix_value(); - // TODO: Display matrix values. - treeItem->setData(2, 0, QString("{matrix}")); - } else { - treeItem->setData(2, 0, QString("<Type not recognized>")); - } + treeItem->setData(2, 0, OctaveLink::octaveValueAsQString(symbolRecord.varval())); } void VariablesDockWidget::setVariablesList(QList<SymbolRecord> symbolTable) {