fix crash when adding new format (bug 1692), improve qt converters ui (bug 1488)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9204 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2004-11-08 08:33:54 +00:00
parent 246b54496e
commit 248968e24c
4 changed files with 190 additions and 130 deletions

View File

@ -1,3 +1,12 @@
2004-11-08 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* QPrefsDialog.C (new_format(), remove_format()): fix crash when
adding new formats (add missing converters().update() call) [bug 1692]
* QPrefsDialog.[Ch]:
* ui/QPrefConvertersModule.C: improve ui for converter changes
[bug 1488].
2004-11-06 Lars Gullik Bjonnes <larsbj@gullik.net>
* QLImage.C (loadableFormats): use bind, equal_to instead of

View File

@ -48,6 +48,7 @@
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qspinbox.h>
#include <qstring.h>
using std::string;
@ -173,6 +174,10 @@ QPrefsDialog::QPrefsDialog(QPrefs * form)
connect(convertersModule->converterRemovePB, SIGNAL(clicked()), this, SLOT(remove_converter()));
connect(convertersModule->converterModifyPB, SIGNAL(clicked()), this, SLOT(modify_converter()));
connect(convertersModule->convertersLB, SIGNAL(highlighted(int)), this, SLOT(switch_converter(int)));
connect(convertersModule->converterFromCO, SIGNAL(activated(const QString&)), this, SLOT(converter_changed()));
connect(convertersModule->converterToCO, SIGNAL(activated(const QString&)), this, SLOT(converter_changed()));
connect(convertersModule->converterED, SIGNAL(textChanged(const QString&)), this, SLOT(converter_changed()));
connect(convertersModule->converterFlagED, SIGNAL(textChanged(const QString&)), this, SLOT(converter_changed()));
// Qt really sucks. This is as ugly as it looks, but the alternative
// means having to derive every module == bloat
@ -311,13 +316,15 @@ void QPrefsDialog::updateConverters()
Converters::const_iterator ccit = form_->converters().begin();
Converters::const_iterator cend = form_->converters().end();
for (; ccit != cend; ++ccit) {
string const name(ccit->From->prettyname() + " -> " +
ccit->To->prettyname());
std::string const name = ccit->From->prettyname() + " -> "
+ ccit->To->prettyname();
convertmod->convertersLB->insertItem(toqstr(name));
}
if (convertmod->convertersLB->currentItem() == -1)
convertmod->convertersLB->setCurrentItem(0);
updateConverterButtons();
}
@ -328,6 +335,40 @@ void QPrefsDialog::switch_converter(int nr)
convertersModule->converterToCO->setCurrentItem(form_->formats().getNumber(c.to));
convertersModule->converterED->setText(toqstr(c.command));
convertersModule->converterFlagED->setText(toqstr(c.flags));
updateConverterButtons();
}
void QPrefsDialog::converter_changed()
{
updateConverterButtons();
}
void QPrefsDialog::updateConverterButtons()
{
Format const & from(form_->formats().get(
convertersModule->converterFromCO->currentItem()));
Format const & to(form_->formats().get(
convertersModule->converterToCO->currentItem()));
int const sel = form_->converters().getNumber(from.name(), to.name());
bool const known = !(sel < 0);
bool const valid = !(convertersModule->converterED->text().isEmpty()
|| from.name() == to.name());
Converter const & c(form_->converters().get(
convertersModule->convertersLB->currentItem()));
string const old_command = c.command;
string const old_flag = c.flags;
string const new_command(fromqstr(convertersModule->converterED->text()));
string const new_flag(fromqstr(convertersModule->converterFlagED->text()));
bool modified = ((old_command != new_command) || (old_flag != new_flag));
convertersModule->converterModifyPB->setEnabled(valid && known && modified);
convertersModule->converterNewPB->setEnabled(valid && !known);
convertersModule->converterRemovePB->setEnabled(known);
}
@ -337,9 +378,11 @@ void QPrefsDialog::new_converter()
{
Format const & from(form_->formats().get(convertersModule->converterFromCO->currentItem()));
Format const & to(form_->formats().get(convertersModule->converterToCO->currentItem()));
string const command(fromqstr(convertersModule->converterED->text()));
string const flags(fromqstr(convertersModule->converterFlagED->text()));
Converter const * old = form_->converters().getConverter(from.name(), to.name());
form_->converters().add(from.name(), to.name(), "", "");
form_->converters().add(from.name(), to.name(), command, flags);
if (!old) {
form_->converters().updateLast(form_->formats());
}
@ -589,6 +632,7 @@ void QPrefsDialog::new_format()
form_->formats().sort();
updateFormats();
fileformatsModule->formatsLB->setCurrentItem(form_->formats().getNumber(_("New")));
form_->converters().update(form_->formats());
updateConverters();
}
@ -625,6 +669,7 @@ void QPrefsDialog::remove_format()
return;
form_->formats().erase(form_->formats().get(nr).name());
updateFormats();
form_->converters().update(form_->formats());
updateConverters();
}

View File

@ -49,6 +49,7 @@ public:
~QPrefsDialog();
void updateConverters();
void updateConverterButtons();
void updateCopiers();
void updateFormats();
@ -61,6 +62,7 @@ public slots:
void remove_format();
void switch_converter(int);
void converter_changed();
void new_converter();
void modify_converter();
void remove_converter();

View File

@ -13,15 +13,15 @@
<rect>
<x>0</x>
<y>0</y>
<width>384</width>
<height>261</height>
<width>466</width>
<height>265</height>
</rect>
</property>
<property stdset="1">
<name>caption</name>
<string>File Conversion</string>
</property>
<hbox>
<grid>
<property stdset="1">
<name>margin</name>
<number>11</number>
@ -30,13 +30,13 @@
<name>spacing</name>
<number>6</number>
</property>
<widget>
<widget row="0" column="0" >
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Layout4</cstring>
<cstring>Layout7</cstring>
</property>
<vbox>
<grid>
<property stdset="1">
<name>margin</name>
<number>0</number>
@ -45,7 +45,7 @@
<name>spacing</name>
<number>6</number>
</property>
<widget>
<widget row="0" column="0" rowspan="1" colspan="2" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
@ -60,82 +60,75 @@
<cstring>convertersLB</cstring>
</property>
</widget>
<widget>
<class>QLayoutWidget</class>
<spacer row="2" column="1" >
<property>
<name>name</name>
<cstring>Spacer8</cstring>
</property>
<property stdset="1">
<name>orientation</name>
<enum>Horizontal</enum>
</property>
<property stdset="1">
<name>sizeType</name>
<enum>Expanding</enum>
</property>
<property>
<name>sizeHint</name>
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
<widget row="2" column="0" >
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>Layout1</cstring>
<cstring>converterRemovePB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Remove</string>
</property>
<grid>
<property stdset="1">
<name>margin</name>
<number>0</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<widget row="0" column="0" rowspan="1" colspan="2" >
<class>QListBox</class>
<item>
<property>
<name>text</name>
<string>New Item</string>
</property>
</item>
<property stdset="1">
<name>name</name>
<cstring>convertersLB</cstring>
</property>
<property stdset="1">
<name>sizePolicy</name>
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>7</vsizetype>
</sizepolicy>
</property>
<property stdset="1">
<name>vScrollBarMode</name>
<enum>AlwaysOn</enum>
</property>
<property stdset="1">
<name>hScrollBarMode</name>
<enum>AlwaysOff</enum>
</property>
</widget>
<widget row="1" column="0" >
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>converterNewPB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;New</string>
</property>
</widget>
<widget row="1" column="1" >
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>converterRemovePB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Remove</string>
</property>
</widget>
</grid>
</widget>
</vbox>
<widget row="1" column="0" rowspan="1" colspan="2" >
<class>QListBox</class>
<item>
<property>
<name>text</name>
<string>New Item</string>
</property>
</item>
<property stdset="1">
<name>name</name>
<cstring>convertersLB</cstring>
</property>
<property stdset="1">
<name>sizePolicy</name>
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>7</vsizetype>
</sizepolicy>
</property>
<property stdset="1">
<name>vScrollBarMode</name>
<enum>AlwaysOn</enum>
</property>
<property stdset="1">
<name>hScrollBarMode</name>
<enum>AlwaysOff</enum>
</property>
</widget>
</grid>
</widget>
<widget>
<widget row="0" column="1" >
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Layout6</cstring>
<cstring>Layout16</cstring>
</property>
<vbox>
<grid>
<property stdset="1">
<name>margin</name>
<number>0</number>
@ -144,7 +137,7 @@
<name>spacing</name>
<number>6</number>
</property>
<widget>
<widget row="0" column="0" >
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
@ -263,56 +256,7 @@
</widget>
</grid>
</widget>
<widget>
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Layout5</cstring>
</property>
<hbox>
<property stdset="1">
<name>margin</name>
<number>0</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<widget>
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>converterModifyPB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Modify</string>
</property>
</widget>
<spacer>
<property>
<name>name</name>
<cstring>Spacer2</cstring>
</property>
<property stdset="1">
<name>orientation</name>
<enum>Horizontal</enum>
</property>
<property stdset="1">
<name>sizeType</name>
<enum>Expanding</enum>
</property>
<property>
<name>sizeHint</name>
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</hbox>
</widget>
<spacer>
<spacer row="2" column="0" >
<property>
<name>name</name>
<cstring>Spacer28</cstring>
@ -333,9 +277,69 @@
</size>
</property>
</spacer>
</vbox>
<widget row="1" column="0" >
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Layout14</cstring>
</property>
<hbox>
<property stdset="1">
<name>margin</name>
<number>0</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<widget>
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>converterNewPB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>A&amp;dd</string>
</property>
</widget>
<widget>
<class>QPushButton</class>
<property stdset="1">
<name>name</name>
<cstring>converterModifyPB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>&amp;Modify</string>
</property>
</widget>
<spacer>
<property>
<name>name</name>
<cstring>Spacer3</cstring>
</property>
<property stdset="1">
<name>orientation</name>
<enum>Horizontal</enum>
</property>
<property stdset="1">
<name>sizeType</name>
<enum>Expanding</enum>
</property>
<property>
<name>sizeHint</name>
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</hbox>
</widget>
</grid>
</widget>
</hbox>
</grid>
</widget>
<tabstops>
<tabstop>convertersLB</tabstop>