mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 13:31:49 +00:00
* LengthCombo.{cpp, h}:
- use model/view infrastructure to store reliable data - use real unit name, not i18n strings, for all comparision purposes - remove unit "mu" in default contruction (bug 5682) - add some helpers to add and remove units git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28146 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
b05dcd0252
commit
18a8d490c7
@ -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 @@ LengthCombo::LengthCombo(QWidget * parent)
|
||||
|
||||
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::has_activated(int)
|
||||
|
||||
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 @@ void LengthCombo::noPercents()
|
||||
{
|
||||
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,44 @@ void LengthCombo::noPercents()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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::removeItem(int item)
|
||||
{
|
||||
QComboBox::removeItem(item);
|
||||
}
|
||||
|
||||
|
||||
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 "moc_LengthCombo.cpp"
|
||||
|
@ -38,6 +38,14 @@ public:
|
||||
virtual void setEnabled(bool b);
|
||||
/// use the %-items?
|
||||
virtual void noPercents();
|
||||
/// remove a unit from the combo
|
||||
virtual void removeItem(lyx::Length::UNIT unit);
|
||||
/// remove an item to the combo
|
||||
virtual void removeItem(int item);
|
||||
/// 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);
|
||||
|
Loading…
Reference in New Issue
Block a user