Mercurial > hg > octave-jordi
changeset 16445:3f8d3fc907af
store workspace model in main_window, not in workspace view
* main-window.h, main-window.cc (main_window::_workspace_model):
New data member.
(main_window::construct): Create _workspace_model and make it the
model for _workspace_view. connect _workspace_model::model_changed
to _workspace_view::model_changed.
(main_window::~main_window): Delete _workspace_model.
* workspace-view.h, workspace-view.cc
(workspace_view::_workspace_model): Delete. Use model() method to get
model where needed.
(workspace_view::setModel): New function.
(workspace_view::view): Rename from _workspace_tree_view. Change all
uses.
(workspace_view::workspace_view): Don't connect
_workspace_model::model_changed signal to
workspace_view::model_changed here.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 06 Apr 2013 14:23:52 -0400 |
parents | 6cd66a5a76e8 |
children | 4b3a4bf8569b |
files | libgui/src/main-window.cc libgui/src/main-window.h libgui/src/workspace-view.cc libgui/src/workspace-view.h |
diffstat | 4 files changed, 50 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/main-window.cc +++ b/libgui/src/main-window.cc @@ -93,8 +93,8 @@ if (_history_dock_widget) delete _history_dock_widget; - if (_workspace_view) - delete _workspace_view; + delete _workspace_model; + delete _workspace_view; } void @@ -661,9 +661,18 @@ _closing = false; // flag for editor files when closed setWindowIcon (QIcon(":/actions/icons/logo.png")); + // Create a new workspace model. + _workspace_model = new workspace_model (); + // Setup dockable widgets and the status bar. _workspace_view = new workspace_view (this); + + _workspace_view->setModel (_workspace_model); _workspace_view->setStatusTip (tr ("View the variables in the active workspace.")); + + connect (_workspace_model, SIGNAL (model_changed ()), + _workspace_view, SLOT (model_changed ())); + _history_dock_widget = new history_dock_widget (this); _history_dock_widget->setStatusTip (tr ("Browse and search the command history.")); _files_dock_widget = new files_dock_widget (this);
--- a/libgui/src/main-window.h +++ b/libgui/src/main-window.h @@ -44,6 +44,7 @@ // Own includes #include "resource-manager.h" +#include "workspace-model.h" #include "workspace-view.h" #include "history-dockwidget.h" #include "files-dockwidget.h" @@ -158,6 +159,9 @@ QAction * _debug_step_out; QAction * _debug_quit; + // Data models. + workspace_model * _workspace_model; + // Dock widgets. workspace_view * _workspace_view; history_dock_widget * _history_dock_widget;
--- a/libgui/src/workspace-view.cc +++ b/libgui/src/workspace-view.cc @@ -38,23 +38,19 @@ setWindowIcon (QIcon(":/actions/icons/logo.png")); setWindowTitle (tr ("Workspace")); - // Create a new workspace model. - _workspace_model = new workspace_model (); - - _workspace_tree_view = new QTreeView (this); // Create a new tree view. - _workspace_tree_view->setHeaderHidden (false); // Do not show header columns. - _workspace_tree_view->setAlternatingRowColors (true); // Activate alternating row colors. - _workspace_tree_view->setAnimated (false); // Deactivate animations because of strange glitches. - _workspace_tree_view->setTextElideMode (Qt::ElideRight);// Elide text to the right side of the cells. - _workspace_tree_view->setWordWrap (false); // No wordwrapping in cells. - _workspace_tree_view->setModel (_workspace_model); // Assign model. + view = new QTreeView (this); // Create a new tree view. + view->setHeaderHidden (false); // Do not show header columns. + view->setAlternatingRowColors (true); // Activate alternating row colors. + view->setAnimated (false); // Deactivate animations because of strange glitches. + view->setTextElideMode (Qt::ElideRight);// Elide text to the right side of the cells. + view->setWordWrap (false); // No wordwrapping in cells. // Set an empty widget, so we can assign a layout to it. setWidget (new QWidget (this)); // Create a new layout and add widgets to it. QVBoxLayout *vbox_layout = new QVBoxLayout (); - vbox_layout->addWidget (_workspace_tree_view); + vbox_layout->addWidget (view); vbox_layout->setMargin (2); // Set the empty widget to have our layout. @@ -72,21 +68,18 @@ // Initialize column order and width of the workspace - _workspace_tree_view->header ()->restoreState (settings->value("workspaceview/column_state").toByteArray ()); + view->header ()->restoreState (settings->value("workspaceview/column_state").toByteArray ()); // Connect signals and slots. connect (this, SIGNAL (visibilityChanged (bool)), this, SLOT(handle_visibility_changed (bool))); - connect (_workspace_model, SIGNAL (model_changed ()), - this, SLOT (model_changed ())); - - connect (_workspace_tree_view, SIGNAL (collapsed (QModelIndex)), + connect (view, SIGNAL (collapsed (QModelIndex)), this, SLOT (collapse_requested (QModelIndex))); - connect (_workspace_tree_view, SIGNAL (expanded (QModelIndex)), + connect (view, SIGNAL (expanded (QModelIndex)), this, SLOT (expand_requested (QModelIndex))); - connect (_workspace_tree_view, SIGNAL (doubleClicked (QModelIndex)), + connect (view, SIGNAL (doubleClicked (QModelIndex)), this, SLOT (item_double_clicked (QModelIndex))); // topLevelChanged is emitted when floating property changes (floating = true) @@ -100,7 +93,7 @@ settings->setValue("workspaceview/local_collapsed", _explicit_collapse.local); settings->setValue("workspaceview/global_collapsed", _explicit_collapse.global); settings->setValue("workspaceview/persistent_collapsed", _explicit_collapse.persistent); - settings->setValue("workspaceview/column_state", _workspace_tree_view->header ()->saveState ()); + settings->setValue("workspaceview/column_state", view->header ()->saveState ()); settings->sync (); } @@ -114,7 +107,9 @@ void workspace_view::model_changed () { - _workspace_model->update_workspace_callback (); + QAbstractItemModel *m = view->model (); + + dynamic_cast<workspace_model *> (m)->update_workspace_callback (); // This code is very quirky and requires some explanation. // Usually, we should not deal with collapsing or expanding ourselves, @@ -130,26 +125,26 @@ // In order to make collapsing/expanding work again, we need to set // flags ourselves here. - QModelIndex local_model_index = _workspace_model->index (0, 0); - QModelIndex global_model_index = _workspace_model->index (1, 0); - QModelIndex persistent_model_index = _workspace_model->index (2, 0); + QModelIndex local_model_index = m->index (0, 0); + QModelIndex global_model_index = m->index (1, 0); + QModelIndex persistent_model_index = m->index (2, 0); if (_explicit_collapse.local) { - _workspace_tree_view->collapse (local_model_index); + view->collapse (local_model_index); } else { - _workspace_tree_view->expand (local_model_index); + view->expand (local_model_index); } if (_explicit_collapse.global) { - _workspace_tree_view->collapse (global_model_index); + view->collapse (global_model_index); } else { - _workspace_tree_view->expand (global_model_index); + view->expand (global_model_index); } if (_explicit_collapse.persistent) { - _workspace_tree_view->collapse (persistent_model_index); + view->collapse (persistent_model_index); } else { - _workspace_tree_view->expand (persistent_model_index); + view->expand (persistent_model_index); } } @@ -169,8 +164,9 @@ // // In order to make collapsing/expanding work again, we need to set // flags ourselves here. - QMap<int, QVariant> item_data - = _workspace_model->itemData (index); + QAbstractItemModel *m = view->model (); + + QMap<int, QVariant> item_data = m->itemData (index); if (item_data[0] == "Local") _explicit_collapse.local = true; @@ -196,8 +192,9 @@ // // In order to make collapsing/expanding work again, we need to do set // flags ourselves here. - QMap<int, QVariant> item_data - = _workspace_model->itemData (index); + QAbstractItemModel *m = view->model (); + + QMap<int, QVariant> item_data = m->itemData (index); if (item_data[0] == "Local") _explicit_collapse.local = false;
--- a/libgui/src/workspace-view.h +++ b/libgui/src/workspace-view.h @@ -36,6 +36,10 @@ workspace_view (QWidget * parent = 0); ~workspace_view (); +public: + + void setModel (workspace_model *model) { view->setModel (model); } + public slots: void handle_visibility_changed (bool visible); void model_changed (); @@ -55,10 +59,7 @@ void item_double_clicked (QModelIndex index); private: - QTreeView *_workspace_tree_view; - - /** Stores the current workspace model. */ - workspace_model *_workspace_model; + QTreeView *view; struct {