]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiPrintNomencl.cpp
Properly track the lifetime of signals2::slots (#8261)
[lyx.git] / src / frontends / qt4 / GuiPrintNomencl.cpp
index a63866b703f329f44d7b230968ee888b149a4fcd..a70a9e091ce535d2eda06467e16c19e94e8f95f4 100644 (file)
@@ -17,7 +17,6 @@
 #include "qt_helpers.h"
 #include "Validator.h"
 
-#include "Spacing.h"
 #include "FuncRequest.h"
 
 #include "insets/InsetNomencl.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
 
-#include <QLineEdit>
-#include <QPushButton>
-#include <QValidator>
-
 using namespace std;
 
 namespace lyx {
 namespace frontend {
 
-GuiPrintNomencl::GuiPrintNomencl(GuiView & lv)
-       : GuiDialog(lv, "nomencl_print", qt_("Nomenclature settings")),
-         params_(insetCode("nomencl_print"))
+GuiPrintNomencl::GuiPrintNomencl(QWidget * parent) : InsetParamsWidget(parent)
 {
        setupUi(this);
 
-       connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
-       connect(applyPB, SIGNAL(clicked()), this, SLOT(slotApply()));
-       connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
-
        connect(valueLE, SIGNAL(textChanged(QString)),
-               this, SLOT(change_adaptor()));
+               this, SIGNAL(changed()));
        connect(unitLC, SIGNAL(selectionChanged(lyx::Length::UNIT)),
-               this, SLOT(change_adaptor()));
+               this, SIGNAL(changed()));
 
        valueLE->setValidator(unsignedLengthValidator(valueLE));
 
-       // Manage the ok, apply, restore and cancel/close buttons
-       bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
-       bc().setOK(okPB);
-       bc().setApply(applyPB);
-       bc().setCancel(closePB);
-
-       // disable for read-only documents
-       bc().addReadOnly(valueLE);
-       bc().addReadOnly(unitLC);
-
        // initialize the length validator
-       bc().addCheckedLineEdit(valueLE, valueLA);
+       addCheckedWidget(valueLE, valueLA);
 
-       setWidthCO->addItem(qt_("Predefined"),
+       setWidthCO->addItem(qt_("Default"),
                QVariant(toqstr("none")));
-       setWidthCO->addItem(qt_("Auto-determined"),
+       setWidthCO->addItem(qt_("Longest label width"),
                QVariant(toqstr("auto")));
        setWidthCO->addItem(qt_("Custom"),
                QVariant(toqstr("custom")));
 }
 
 
-void GuiPrintNomencl::change_adaptor()
-{
-       changed();
-}
-
-
-void GuiPrintNomencl::on_setWidthCO_activated(int i)
+void GuiPrintNomencl::on_setWidthCO_activated(int /*i*/)
 {
-       bool const custom =
-               (setWidthCO->itemData(i).toString()
-                == "custom");
-       valueLE->setEnabled(custom);
-       unitLC->setEnabled(custom);
-       valueLA->setEnabled(custom);
        changed();
 }
 
 
-void GuiPrintNomencl::paramsToDialog(InsetCommandParams const & /*icp*/)
+void GuiPrintNomencl::paramsToDialog(InsetCommandParams const & params)
 {
        setWidthCO->setCurrentIndex(
-               setWidthCO->findData(toqstr(params_["set_width"])));
-       
-       lengthToWidgets(valueLE,
-                       unitLC,
-                       params_["width"],
-                       Length::defaultUnit());
-
-       bc().setValid(isValid());
+               setWidthCO->findData(toqstr(params["set_width"])));
+
+       lengthToWidgets(valueLE, unitLC,
+                       params["width"], Length::defaultUnit());
 }
 
 
-void GuiPrintNomencl::updateContents()
+void GuiPrintNomencl::paramsToDialog(Inset const * inset)
 {
-       bool const custom = (setWidthCO->itemData(
-                                 setWidthCO->currentIndex()).toString()
-                            == "custom");
-       valueLE->setEnabled(custom);
-       unitLC->setEnabled(custom);
-       valueLA->setEnabled(custom);
+       InsetNomencl const * nomencl = static_cast<InsetNomencl const *>(inset);
+       paramsToDialog(nomencl->params());
 }
 
 
-void GuiPrintNomencl::applyView()
+docstring GuiPrintNomencl::dialogToParams() const
 {
+       InsetCommandParams params(insetCode());
        docstring const set_width = qstring_to_ucs4(setWidthCO->itemData(
                setWidthCO->currentIndex()).toString());
-       params_["set_width"] = set_width;
+       params["set_width"] = set_width;
        docstring width;
        if (set_width == from_ascii("custom"))
                width = from_utf8(widgetsToLength(valueLE, unitLC));
-       params_["width"] = width;
+       params["width"] = width;
+       return from_ascii(InsetNomencl::params2string(params));
 }
 
 
-bool GuiPrintNomencl::isValid()
+bool GuiPrintNomencl::checkWidgets(bool readonly) const
 {
-       return (setWidthCO->itemData(
+       valueLE->setReadOnly(readonly);
+       if (readonly) {
+               setWidthCO->setEnabled(false);
+               unitLC->setEnabled(false);
+               valueLA->setEnabled(false);
+       } else {
+               bool const custom =
+                       (setWidthCO->itemData(setWidthCO->currentIndex()).toString() == "custom");
+               valueLE->setEnabled(custom);
+               unitLC->setEnabled(custom);
+               valueLA->setEnabled(custom);
+       }
+
+       if (!InsetParamsWidget::checkWidgets())
+               return false;
+       return setWidthCO->itemData(
                        setWidthCO->currentIndex()).toString() != "custom"
-               || !valueLE->text().isEmpty());
-}
-
-
-bool GuiPrintNomencl::initialiseParams(std::string const & data)
-{
-       InsetCommand::string2params("nomencl_print", data, params_);
-       paramsToDialog(params_);
-       return true;
-}
-
-
-void GuiPrintNomencl::dispatchParams()
-{
-       std::string const lfun = InsetCommand::params2string("nomencl_print", params_);
-       dispatch(FuncRequest(getLfun(), lfun));
+               || !valueLE->text().isEmpty();
 }
 
-
-
-Dialog * createGuiPrintNomencl(GuiView & lv)
-{
-       return new GuiPrintNomencl(lv);
-}
-
-
 } // namespace frontend
 } // namespace lyx