Mercurial > hg > octave-nkf
changeset 14669:7605e7136b50 gui
Discarded initFileEditor, instead put that in the constructor. Speedup for updating the symbol table by lowering complexity from n² to n. Fixed problem with hangup on quit.
* FileEditor: Removed initFileEditor, put that code into the constructor.
* WorkspaceModel: Simplified updating the symbol table.
* OctaveLink: Add quit_allowed = true to prevent hangup on quit.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Tue, 22 May 2012 11:00:24 +0200 |
parents | 6a6733a55982 |
children | 7fbea449737d |
files | gui/src/FileEditor.cpp gui/src/FileEditor.h gui/src/MainWindow.cpp gui/src/WorkspaceModel.cpp gui/src/WorkspaceModel.h gui/src/backend/OctaveLink.cpp |
diffstat | 6 files changed, 28 insertions(+), 83 deletions(-) [+] |
line wrap: on
line diff
--- a/gui/src/FileEditor.cpp +++ b/gui/src/FileEditor.cpp @@ -25,10 +25,14 @@ #include <QStyle> #include <QTextStream> -FileEditor::FileEditor (QWidget * parent) - : QWidget (parent) +FileEditor::FileEditor (QTerminal *terminalView, LexerOctaveGui *lexer, MainWindow *mainWindow) + : QWidget () { construct (); + m_editor->setLexer (lexer); + m_terminalView = terminalView; // for sending commands to octave + m_mainWindow = mainWindow; // get the MainWindow for chekcing state at subwindow close + show (); } FileEditor::~FileEditor () @@ -208,7 +212,7 @@ if (!file.open (QFile::WriteOnly)) { QMessageBox::warning (this, tr ("File Editor"), - tr ("Cannot write file %1:\n%2."). + tr ("Cannot write file %1:\n%2."). arg (saveFileName).arg (file.errorString ())); return; } @@ -342,18 +346,6 @@ m_editor->setCursorPosition(prevline,0); } -// function for setting the already existing lexer from MainWindow -void -FileEditor::initEditor (QTerminal* terminalView, - LexerOctaveGui* lexer, - MainWindow* mainWindow) -{ - m_editor->setLexer(lexer); - m_terminalView = terminalView; // for sending commands to octave - // TODO: make a global commandOctave function? - m_mainWindow = mainWindow; // get the MainWindow for chekcing state at subwindow close -} - void FileEditor::setModified (bool modified) { @@ -483,7 +475,7 @@ m_toolBar->addSeparator(); m_toolBar->addAction (runAction); - // menu bar + // menu bar QMenu *fileMenu = new QMenu(tr("&File"),m_menuBar); fileMenu->addAction(newAction); fileMenu->addAction(openAction); @@ -544,5 +536,4 @@ m_fileName = ""; newWindowTitle (false); setWindowIcon(QIcon::fromTheme("accessories-text-editor",style->standardIcon (QStyle::SP_FileIcon))); - show (); }
--- a/gui/src/FileEditor.h +++ b/gui/src/FileEditor.h @@ -44,12 +44,9 @@ Q_OBJECT public: - FileEditor (QWidget * parent = 0); + FileEditor (QTerminal *terminalView, LexerOctaveGui *lexer, MainWindow *mainWindow); ~FileEditor (); void loadFile (QString fileName); - void initEditor (QTerminal *terminalView, - LexerOctaveGui *lexer, - MainWindow *mainWindow); public slots:
--- a/gui/src/MainWindow.cpp +++ b/gui/src/MainWindow.cpp @@ -53,9 +53,8 @@ void MainWindow::newEditorWindow (QString fileName) { - FileEditor *fileEditor = new FileEditor (); + FileEditor *fileEditor = new FileEditor (m_terminalView, m_lexer, this); fileEditor->setAttribute (Qt::WA_DeleteOnClose); - fileEditor->initEditor(m_terminalView, m_lexer, this); // init necessary informations for editor if (fileName.isEmpty ()) fileEditor->newFile ();
--- a/gui/src/WorkspaceModel.cpp +++ b/gui/src/WorkspaceModel.cpp @@ -17,6 +17,7 @@ #include "WorkspaceModel.h" #include <QTreeWidget> +#include <QTime> WorkspaceModel::WorkspaceModel(QObject *parent) : QAbstractItemModel(parent) @@ -146,7 +147,6 @@ WorkspaceModel::updateFromSymbolTable () { std::list < symbol_table::symbol_record > allVariables = symbol_table::all_variables (); - // Split the symbol table into its different categories. QList < symbol_table::symbol_record* > localSymbolTable; QList < symbol_table::symbol_record* > globalSymbolTable; @@ -184,71 +184,22 @@ updateCategory (2, persistentSymbolTable); updateCategory (3, hiddenSymbolTable); reset(); + emit expandRequest(); } void -WorkspaceModel::updateCategory (int topLevelItemIndex, QList < symbol_table::symbol_record* > symbolTable) +WorkspaceModel::updateCategory (int topLevelItemIndex, const QList < symbol_table::symbol_record* > &symbolTable) { - // This method may be a little bit confusing; variablesList is a complete list of all - // variables that are in the workspace currently. TreeItem *treeItem = topLevelItem (topLevelItemIndex); - - // 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 (symbol_table::symbol_record *symbolRecord, symbolTable) - { - int childCount = treeItem->childCount (); - bool alreadyExists = false; - TreeItem *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 = treeItem->child (i); - if (child->data (0).toString () == - QString (symbolRecord->name ().c_str ())) - { - alreadyExists = true; - break; - } - } + treeItem->deleteChildItems(); - // If it already exists, just update it. - if (alreadyExists) - { - updateTreeEntry (child, symbolRecord); - } - else - { - // It does not exist, so create a new one and set the right values. - child = new TreeItem (); - updateTreeEntry (child, symbolRecord); - treeItem->addChild (child); - } - } - - // Check the tree against the list for deleted variables. - for (int i = 0; i < treeItem->childCount (); i++) + int symbolTableSize = symbolTable.size (); + for(int j = 0; j < symbolTableSize; j++) { - bool existsInVariableList = false; - TreeItem *child = treeItem->child (i); - foreach (symbol_table::symbol_record *symbolRecord, symbolTable) - { - if (QString (symbolRecord->name ().c_str ()) == - child->data (0).toString ()) - { - existsInVariableList = true; - } - } - - if (!existsInVariableList) - { - treeItem->removeChild (child); - delete child; - i--; - } + TreeItem *child = new TreeItem (); + updateTreeEntry (child, symbolTable[j]); + treeItem->addChild (child); } }
--- a/gui/src/WorkspaceModel.h +++ b/gui/src/WorkspaceModel.h @@ -56,6 +56,7 @@ // Qt includes #include <QAbstractItemModel> +#include <QVector> class TreeItem { @@ -73,7 +74,7 @@ } ~TreeItem() { - qDeleteAll(_childItems); + qDeleteAll(_childItems); } void insertChildItem(int at, TreeItem *item) { @@ -86,6 +87,11 @@ _childItems.append(item); } + void deleteChildItems() { + qDeleteAll(_childItems); + _childItems.clear(); + } + void removeChild(TreeItem *item) { _childItems.removeAll(item); } @@ -154,7 +160,7 @@ void updateFromSymbolTable (); void updateTreeEntry (TreeItem * treeItem, symbol_table::symbol_record *symbolRecord); - void updateCategory (int topLevelItemIndex, QList < symbol_table::symbol_record *> symbolTable); + void updateCategory (int topLevelItemIndex, const QList < symbol_table::symbol_record *> &symbolTable); QString octaveValueAsQString (const octave_value &octaveValue); signals: