changeset 20072:76c72314d905

QT Text/EditControl: support String cells (Bug 44749) * libgui/graphics/QtHandlesUtils.cc/h (toCellString): New function * libgui/graphics/EditControl.cc (EditControl::init): set text as string_vector (EditControl::updateMultiLine): set text as string_vector (EditControl::returnPressed): set String as cells (EditControl::editingFinished): set String as cells * libgui/graphics/TextControl.cc (TextControl::TextControl): set text as string vector (TextControl::update): set text as string vector
author John Donoghue
date Tue, 07 Apr 2015 12:12:59 -0400
parents 0e712de0af4d
children 6b78feb92f53
files libgui/graphics/EditControl.cc libgui/graphics/QtHandlesUtils.cc libgui/graphics/QtHandlesUtils.h libgui/graphics/TextControl.cc
diffstat 4 files changed, 33 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/graphics/EditControl.cc	Mon Apr 06 23:06:08 2015 -0400
+++ b/libgui/graphics/EditControl.cc	Tue Apr 07 12:12:59 2015 -0400
@@ -104,8 +104,7 @@
   uicontrol::properties& up = properties<uicontrol> ();
 
   edit->setAcceptRichText (false);
-  // FIXME: support string_vector
-  edit->setPlainText (Utils::fromStdString (up.get_string_string ()));
+  edit->setPlainText (Utils::fromStringVector (up.get_string_vector()).join("\n"));
 
   connect (edit, SIGNAL (textChanged (void)),
            SLOT (textChanged (void)));
@@ -191,7 +190,7 @@
   switch (pId)
     {
     case uicontrol::properties::ID_STRING:
-      edit->setPlainText (Utils::fromStdString (up.get_string_string ()));
+      edit->setPlainText (Utils::fromStringVector (up.get_string_vector()).join("\n"));
       return true;
 
     case uicontrol::properties::ID_MIN:
@@ -227,7 +226,10 @@
 
   if (m_textChanged)
     {
-      gh_manager::post_set (m_handle, "string", Utils::toStdString (txt), false);
+      if (m_multiLine)
+        gh_manager::post_set (m_handle, "string", Utils::toCellString(txt.split("\n")), false);
+      else
+        gh_manager::post_set (m_handle, "string", Utils::toStdString (txt), false);
 
       m_textChanged = false;
     }
@@ -241,11 +243,15 @@
 {
   if (m_textChanged)
     {
+      uicontrol::properties& up = properties<uicontrol> ();
+
       QString txt = (m_multiLine
                      ? qWidget<TextEdit> ()->toPlainText ()
                      : qWidget<QLineEdit> ()->text ());
-
-      gh_manager::post_set (m_handle, "string", Utils::toStdString (txt), false);
+      if (m_multiLine)
+        gh_manager::post_set (m_handle, "string", Utils::toCellString(txt.split("\n")), false);
+      else
+        gh_manager::post_set (m_handle, "string", Utils::toStdString (txt), false);
       gh_manager::post_callback (m_handle, "callback");
 
       m_textChanged = false;
--- a/libgui/graphics/QtHandlesUtils.cc	Mon Apr 06 23:06:08 2015 -0400
+++ b/libgui/graphics/QtHandlesUtils.cc	Tue Apr 07 12:12:59 2015 -0400
@@ -81,6 +81,23 @@
   return v;
 }
 
+Cell toCellString (const QStringList& l)
+{
+  QStringList tmp = l;
+
+  // dont get any empty lines from end of the list
+  while ((tmp.length () > 0) && (tmp.last ().length () == 0))
+    {
+      tmp.removeLast ();
+    }
+  // no strings will be a a 1x1 cell with empty string
+  if (tmp.length () == 0)
+    tmp += "";
+
+  Cell v(toStringVector (tmp));
+  return v;
+}
+
 template <class T>
 QFont
 computeFont (const typename T::properties& props, int height)
--- a/libgui/graphics/QtHandlesUtils.h	Mon Apr 06 23:06:08 2015 -0400
+++ b/libgui/graphics/QtHandlesUtils.h	Tue Apr 07 12:12:59 2015 -0400
@@ -47,6 +47,8 @@
   QStringList fromStringVector (const string_vector& v);
   string_vector toStringVector (const QStringList& l);
 
+  Cell toCellString (const QStringList& l);
+
   template <class T>
   QFont computeFont (const typename T::properties& props, int height = -1);
 
--- a/libgui/graphics/TextControl.cc	Mon Apr 06 23:06:08 2015 -0400
+++ b/libgui/graphics/TextControl.cc	Tue Apr 07 12:12:59 2015 -0400
@@ -59,8 +59,7 @@
   label->setWordWrap (false);
   label->setAlignment (Utils::fromHVAlign (up.get_horizontalalignment (),
                                            up.get_verticalalignment ()));
-  // FIXME: support string_vector
-  label->setText (Utils::fromStdString (up.get_string_string ()));
+  label->setText(Utils::fromStringVector (up.get_string_vector()).join("\n"));
 }
 
 TextControl::~TextControl (void)
@@ -76,8 +75,7 @@
   switch (pId)
     {
     case uicontrol::properties::ID_STRING:
-      // FIXME: support string_vector
-      label->setText (Utils::fromStdString (up.get_string_string ()));
+      label->setText(Utils::fromStringVector (up.get_string_vector()).join("\n"));
       break;
 
     case uicontrol::properties::ID_HORIZONTALALIGNMENT: