changeset 16574:17941fedd4ce

Change workspace row height to font height. * main-window.cc (main_window::construct): Connect workspace_model signal to workspace_view slot. * workspace-view.cc, workspace-view.h (workspace_view::workspace_view): New variable view_previous_row_count initialized to zero. (workspace_view::contextmenu_requested): Rename pos from shadow to qpos. (workspace_view::handle_model_changed): New slot to adjust appearance.
author Daniel J Sebald <daniel.sebald@ieee.org>
date Fri, 12 Apr 2013 03:48:56 -0500
parents 4d8462fe15b9
children dd66c5bcb21e
files libgui/src/main-window.cc libgui/src/workspace-view.cc libgui/src/workspace-view.h
diffstat 3 files changed, 22 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/main-window.cc
+++ b/libgui/src/main-window.cc
@@ -670,6 +670,8 @@
   setWindowIcon (QIcon (":/actions/icons/logo.png"));
 
   workspace_window->setModel (_workspace_model);
+  connect (_workspace_model, SIGNAL (model_changed (void)),
+           workspace_window, SLOT (handle_model_changed (void)));
 
   // Create and set the central widget.  QMainWindow takes ownership of
   // the widget (pointer) so there is no need to delete the object upon
--- a/libgui/src/workspace-view.cc
+++ b/libgui/src/workspace-view.cc
@@ -49,6 +49,7 @@
 
   view->setWordWrap (false);
   view->setContextMenuPolicy (Qt::CustomContextMenu);
+  view_previous_row_count = 0;
 
   // Set an empty widget, so we can assign a layout to it.
   setWidget (new QWidget (this));
@@ -96,11 +97,11 @@
 }
 
 void
-workspace_view::contextmenu_requested (const QPoint& pos)
+workspace_view::contextmenu_requested (const QPoint& qpos)
 {
   QMenu menu (this);
 
-  QModelIndex index = view->indexAt (pos);
+  QModelIndex index = view->indexAt (qpos);
   QAbstractItemModel *m = view->model ();
 
   // if it isnt Local, Glocal etc, allow the ctx menu
@@ -137,7 +138,7 @@
       menu.addAction ("stem(" + var_name + ")", this,
                       SLOT (handle_contextmenu_stem ()));
 
-      menu.exec (view->mapToGlobal (pos));
+      menu.exec (view->mapToGlobal (qpos));
     }
 }
 
@@ -228,3 +229,16 @@
       emit command_requested (cmdname + "(" + var_name + ")\n");
     }
 }
+
+void
+workspace_view::handle_model_changed (void)
+{
+  // Just modify those rows that have been added rather than go through
+  // the whole list.  For-loop test will handle when number of rows reduced.
+  QFontMetrics fm = view->fontMetrics ();
+  int row_height =  fm.height ();
+  int new_row_count = view->model ()->rowCount ();
+  for (int i = view_previous_row_count; i < new_row_count; i++)
+    view->setRowHeight (i, row_height);
+  view_previous_row_count = new_row_count;
+}
--- a/libgui/src/workspace-view.h
+++ b/libgui/src/workspace-view.h
@@ -65,11 +65,14 @@
   void handle_contextmenu_plot (void);
   void handle_contextmenu_stem (void);
 
+  void handle_model_changed (void);
+
 private:
 
   void relay_contextmenu_command (const QString& cmdname);
 
   QTableView *view;
+  int view_previous_row_count;
 };
 
 #endif