From 248968e24c18c3a0797680f6e0624216a7f39cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Mon, 8 Nov 2004 08:33:54 +0000 Subject: [PATCH] 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 --- src/frontends/qt2/ChangeLog | 9 + src/frontends/qt2/QPrefsDialog.C | 51 +++- src/frontends/qt2/QPrefsDialog.h | 2 + src/frontends/qt2/ui/QPrefConvertersModule.ui | 258 +++++++++--------- 4 files changed, 190 insertions(+), 130 deletions(-) diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 2194db2ae2..b93e27aaf0 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,12 @@ +2004-11-08 Jürgen Spitzmüller + + * 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 * QLImage.C (loadableFormats): use bind, equal_to instead of diff --git a/src/frontends/qt2/QPrefsDialog.C b/src/frontends/qt2/QPrefsDialog.C index cb1423e343..6cc4b52916 100644 --- a/src/frontends/qt2/QPrefsDialog.C +++ b/src/frontends/qt2/QPrefsDialog.C @@ -48,6 +48,7 @@ #include #include #include +#include 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(); } diff --git a/src/frontends/qt2/QPrefsDialog.h b/src/frontends/qt2/QPrefsDialog.h index 67bafd0477..4ad1ad26e6 100644 --- a/src/frontends/qt2/QPrefsDialog.h +++ b/src/frontends/qt2/QPrefsDialog.h @@ -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(); diff --git a/src/frontends/qt2/ui/QPrefConvertersModule.ui b/src/frontends/qt2/ui/QPrefConvertersModule.ui index 68113bb41a..0665bf07bf 100644 --- a/src/frontends/qt2/ui/QPrefConvertersModule.ui +++ b/src/frontends/qt2/ui/QPrefConvertersModule.ui @@ -13,15 +13,15 @@ 0 0 - 384 - 261 + 466 + 265 caption File Conversion - + margin 11 @@ -30,13 +30,13 @@ spacing 6 - + QLayoutWidget name - Layout4 + Layout7 - + margin 0 @@ -45,7 +45,7 @@ spacing 6 - + QLabel name @@ -60,82 +60,75 @@ convertersLB - - QLayoutWidget + + + name + Spacer8 + + + orientation + Horizontal + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + QPushButton name - Layout1 + converterRemovePB + + + text + &Remove - - - margin - 0 - - - spacing - 6 - - - QListBox - - - text - New Item - - - - name - convertersLB - - - sizePolicy - - 3 - 7 - - - - vScrollBarMode - AlwaysOn - - - hScrollBarMode - AlwaysOff - - - - QPushButton - - name - converterNewPB - - - text - &New - - - - QPushButton - - name - converterRemovePB - - - text - &Remove - - - - + + QListBox + + + text + New Item + + + + name + convertersLB + + + sizePolicy + + 3 + 7 + + + + vScrollBarMode + AlwaysOn + + + hScrollBarMode + AlwaysOff + + + - + QLayoutWidget name - Layout6 + Layout16 - + margin 0 @@ -144,7 +137,7 @@ spacing 6 - + QLayoutWidget name @@ -263,56 +256,7 @@ - - QLayoutWidget - - name - Layout5 - - - - margin - 0 - - - spacing - 6 - - - QPushButton - - name - converterModifyPB - - - text - &Modify - - - - - name - Spacer2 - - - orientation - Horizontal - - - sizeType - Expanding - - - sizeHint - - 20 - 20 - - - - - - + name Spacer28 @@ -333,9 +277,69 @@ - + + QLayoutWidget + + name + Layout14 + + + + margin + 0 + + + spacing + 6 + + + QPushButton + + name + converterNewPB + + + text + A&dd + + + + QPushButton + + name + converterModifyPB + + + text + &Modify + + + + + name + Spacer3 + + + orientation + Horizontal + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + + - + convertersLB