# HG changeset patch # User John Donoghue # Date 1428423179 14400 # Node ID 76c72314d9055aa9fa70e2b39fec41ebe65d9a96 # Parent 0e712de0af4d5761b46a99c5ab3bb3b5e7349473 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 diff -r 0e712de0af4d -r 76c72314d905 libgui/graphics/EditControl.cc --- 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 (); 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 (); + QString txt = (m_multiLine ? qWidget ()->toPlainText () : qWidget ()->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; diff -r 0e712de0af4d -r 76c72314d905 libgui/graphics/QtHandlesUtils.cc --- 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 QFont computeFont (const typename T::properties& props, int height) diff -r 0e712de0af4d -r 76c72314d905 libgui/graphics/QtHandlesUtils.h --- 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 QFont computeFont (const typename T::properties& props, int height = -1); diff -r 0e712de0af4d -r 76c72314d905 libgui/graphics/TextControl.cc --- 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: