Jürgen Spitzmüller wrote:
> > AFAIK, it is only usable in math. So we might want to _add_ it only  
> > in this case (if we ever need it).
>
> that might be more tricky.

Would be the attached. Some testing would be nice.

BTW, why did we remove the %-items from hspace and vspace again? I think that 
\hspace{0.25\linewidth} or \vspace{.5\textheight} might be quite useful, 
wouldn't it?

Jürgen
Index: src/frontends/qt4/LengthCombo.cpp
===================================================================
--- src/frontends/qt4/LengthCombo.cpp	(Revision 28098)
+++ src/frontends/qt4/LengthCombo.cpp	(Arbeitskopie)
@@ -4,6 +4,7 @@
  * Licence details can be found in the file COPYING.
  *
  * \author John Levon
+ * \author Jürgen Spitzmüller
  * \author Herbert Voß
  *
  * Full author contact details are available in file CREDITS.
@@ -11,16 +12,26 @@
 
 #include <config.h>
 
+#include "support/qstring_helpers.h"
+
 #include "LengthCombo.h"
 
 #include "qt_helpers.h"
 
+#include <string>
 
+
 LengthCombo::LengthCombo(QWidget * parent)
 	: QComboBox(parent)
 {
-	for (int i = 0; i < lyx::num_units; i++)
-		addItem(lyx::qt_(lyx::unit_name_gui[i]));
+	for (int i = 0; i < lyx::num_units; i++) {
+		// mu does not make sense usually
+		// so it must be added manually, if needed
+		if (lyx::unit_name[i] == "mu")
+			continue;
+		QComboBox::addItem(lyx::qt_(lyx::unit_name_gui[i]),
+			lyx::toqstr(lyx::unit_name[i]));
+	}
 
 	connect(this, SIGNAL(activated(int)),
 		this, SLOT(has_activated(int)));
@@ -29,7 +40,8 @@
 
 lyx::Length::UNIT LengthCombo::currentLengthItem() const
 {
-	return static_cast<lyx::Length::UNIT>(currentIndex());
+	QString const val = itemData(currentIndex()).toString();
+	return lyx::unitFromString(lyx::fromqstr(val));
 }
 
 
@@ -42,7 +54,14 @@
 
 void LengthCombo::setCurrentItem(lyx::Length::UNIT unit)
 {
-	QComboBox::setCurrentIndex(int(unit));
+	QString const val = lyx::toqstr(lyx::stringFromUnit(unit));
+	int num = QComboBox::count();
+	for (int i = 0; i < num; i++) {
+		if (QComboBox::itemData(i).toString() == val) {
+			QComboBox::setCurrentIndex(i);
+			break;
+		}
+	}
 }
 
 
@@ -62,7 +81,7 @@
 {
 	int num = QComboBox::count();
 	for (int i = 0; i < num; i++) {
-		if (QComboBox::itemText(i).contains('%') > 0) {
+		if (QComboBox::itemData(i).toString().contains('%')) {
 			QComboBox::removeItem(i);
 			--i;
 			--num;
@@ -70,4 +89,38 @@
 	}
 }
 
+
+void LengthCombo::removeItem(lyx::Length::UNIT unit)
+{
+	QString const val = lyx::toqstr(lyx::stringFromUnit(unit));
+	int num = QComboBox::count();
+	for (int i = 0; i < num; i++) {
+		if (QComboBox::itemData(i).toString() == val) {
+			QComboBox::removeItem(i);
+			break;
+		}
+	}
+}
+
+
+void LengthCombo::addItem(lyx::Length::UNIT unit)
+{
+	QString const val = lyx::toqstr(lyx::stringFromUnit(unit));
+	int num = QComboBox::count();
+	for (int i = 0; i < num; i++) {
+		if (QComboBox::itemData(i).toString() == val) {
+			// already there, nothing to do
+			return;
+		}
+	}
+	insertItem(int(unit), lyx::qt_(lyx::unit_name_gui[int(unit)]),
+		   lyx::toqstr(lyx::unit_name[int(unit)]));
+}
+
+
+void LengthCombo::addItem(QString const item)
+{
+	QComboBox::addItem(item);
+}
+
 #include "LengthCombo_moc.cpp"
Index: src/frontends/qt4/LengthCombo.h
===================================================================
--- src/frontends/qt4/LengthCombo.h	(Revision 28098)
+++ src/frontends/qt4/LengthCombo.h	(Arbeitskopie)
@@ -38,6 +38,12 @@
 	virtual void setEnabled(bool b);
 	/// use the %-items?
 	virtual void noPercents();
+	/// remove items from the combo
+	virtual void removeItem(lyx::Length::UNIT unit);
+	/// add a unit to the combo
+	virtual void addItem(lyx::Length::UNIT unit);
+	/// add an item to the combo
+	virtual void addItem(QString const item);
 
 protected Q_SLOTS:
 	virtual void has_activated(int index);

Reply via email to