Migrate GuiNomencl to InsetParamsDialog.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35869 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2010-10-27 20:01:49 +00:00
parent 585f8b9fda
commit ee535fa8ea
5 changed files with 67 additions and 181 deletions

View File

@ -14,108 +14,60 @@
#include "GuiNomencl.h" #include "GuiNomencl.h"
#include "qt_helpers.h" #include "qt_helpers.h"
#include "FuncRequest.h"
#include "insets/InsetCommand.h" #include "insets/InsetNomencl.h"
#include "support/debug.h"
#include <QLabel>
#include <QLineEdit>
using namespace std; using namespace std;
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
GuiNomenclature::GuiNomenclature(GuiView & lv) GuiNomenclature::GuiNomenclature(QWidget * parent) : InsetParamsWidget(parent)
: GuiDialog(lv, "nomenclature", qt_("Nomenclature")),
params_(insetCode("nomenclature"))
{ {
setupUi(this); setupUi(this);
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
connect(symbolED, SIGNAL(textChanged(QString)), connect(symbolED, SIGNAL(textChanged(QString)),
this, SLOT(change_adaptor())); this, SIGNAL(changed()));
connect(descriptionTE, SIGNAL(textChanged()), connect(descriptionTE, SIGNAL(textChanged()),
this, SLOT(change_adaptor())); this, SIGNAL(changed()));
setFocusProxy(descriptionTE); setFocusProxy(descriptionTE);
bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
bc().setOK(okPB);
bc().setCancel(closePB);
bc().addReadOnly(symbolED);
bc().addReadOnly(descriptionTE);
bc().addReadOnly(prefixED);
} }
void GuiNomenclature::change_adaptor() void GuiNomenclature::paramsToDialog(Inset const * inset)
{ {
changed(); InsetNomencl const * nomencl = static_cast<InsetNomencl const *>(inset);
} InsetCommandParams const & params = nomencl->params();
prefixED->setText(toqstr(params["prefix"]));
void GuiNomenclature::reject() symbolED->setText(toqstr(params["symbol"]));
{ QString description = toqstr(params["description"]);
slotClose();
}
void GuiNomenclature::paramsToDialog(InsetCommandParams const & /*icp*/)
{
prefixED->setText(toqstr(params_["prefix"]));
symbolED->setText(toqstr(params_["symbol"]));
QString description = toqstr(params_["description"]);
description.replace("\\\\","\n"); description.replace("\\\\","\n");
descriptionTE->setPlainText(description); descriptionTE->setPlainText(description);
descriptionTE->setFocus(); descriptionTE->setFocus();
bc().setValid(isValid());
} }
void GuiNomenclature::applyView() docstring GuiNomenclature::dialogToParams() const
{ {
params_["prefix"] = qstring_to_ucs4(prefixED->text()); InsetCommandParams params(insetCode());
params_["symbol"] = qstring_to_ucs4(symbolED->text()); params["prefix"] = qstring_to_ucs4(prefixED->text());
params["symbol"] = qstring_to_ucs4(symbolED->text());
QString description = descriptionTE->toPlainText(); QString description = descriptionTE->toPlainText();
description.replace('\n',"\\\\"); description.replace('\n',"\\\\");
params_["description"] = qstring_to_ucs4(description); params["description"] = qstring_to_ucs4(description);
return from_ascii(InsetNomencl::params2string("nomenclature", params));
} }
bool GuiNomenclature::isValid() bool GuiNomenclature::checkWidgets() const
{ {
if (!InsetParamsWidget::checkWidgets())
return false;
QString const description = descriptionTE->toPlainText(); QString const description = descriptionTE->toPlainText();
return !symbolED->text().isEmpty() && !description.isEmpty(); return !symbolED->text().isEmpty() && !description.isEmpty();
} }
bool GuiNomenclature::initialiseParams(std::string const & data)
{
InsetCommand::string2params("nomenclature", data, params_);
paramsToDialog(params_);
return true;
}
void GuiNomenclature::dispatchParams()
{
std::string const lfun = InsetCommand::params2string("nomenclature", params_);
dispatch(FuncRequest(getLfun(), lfun));
}
Dialog * createGuiNomenclature(GuiView & lv)
{
return new GuiNomenclature(lv);
}
} // namespace frontend } // namespace frontend
} // namespace lyx } // namespace lyx

View File

@ -14,46 +14,29 @@
#ifndef GUINOMENCLATURE_H #ifndef GUINOMENCLATURE_H
#define GUINOMENCLATURE_H #define GUINOMENCLATURE_H
#include "GuiDialog.h"
#include "ui_NomenclUi.h" #include "ui_NomenclUi.h"
#include "insets/InsetCommandParams.h" #include "InsetParamsWidget.h"
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
class GuiNomenclature : public GuiDialog, public Ui::NomenclUi class GuiNomenclature : public InsetParamsWidget, public Ui::NomenclUi
{ {
Q_OBJECT Q_OBJECT
public: public:
GuiNomenclature(GuiView & lv); GuiNomenclature(QWidget * parent = 0);
private Q_SLOTS:
void change_adaptor();
void reject();
private: private:
/// /// \name InsetParamsWidget inherited methods
bool isValid(); //@{
/// Apply changes InsetCode insetCode() const { return NOMENCL_CODE; }
void applyView(); FuncCode creationCode() const { return LFUN_INSET_INSERT; }
/// update void paramsToDialog(Inset const *);
void updateContents() {} docstring dialogToParams() const;
/// bool checkWidgets() const;
bool initialiseParams(std::string const & data); //@}
///
void paramsToDialog(InsetCommandParams const & icp);
/// clean-up on hide.
void clearParams() { params_.clear(); }
/// clean-up on hide.
void dispatchParams();
///
bool isBufferDependent() const { return true; }
private:
///
InsetCommandParams params_;
}; };
} // namespace frontend } // namespace frontend

View File

@ -3774,7 +3774,6 @@ Dialog * createGuiIndex(GuiView & lv);
Dialog * createGuiListings(GuiView & lv); Dialog * createGuiListings(GuiView & lv);
Dialog * createGuiLog(GuiView & lv); Dialog * createGuiLog(GuiView & lv);
Dialog * createGuiMathMatrix(GuiView & lv); Dialog * createGuiMathMatrix(GuiView & lv);
Dialog * createGuiNomenclature(GuiView & lv);
Dialog * createGuiNote(GuiView & lv); Dialog * createGuiNote(GuiView & lv);
Dialog * createGuiParagraph(GuiView & lv); Dialog * createGuiParagraph(GuiView & lv);
Dialog * createGuiPhantom(GuiView & lv); Dialog * createGuiPhantom(GuiView & lv);
@ -3849,8 +3848,6 @@ Dialog * GuiView::build(string const & name)
return createGuiDelimiter(*this); return createGuiDelimiter(*this);
if (name == "mathmatrix") if (name == "mathmatrix")
return createGuiMathMatrix(*this); return createGuiMathMatrix(*this);
if (name == "nomenclature")
return createGuiNomenclature(*this);
if (name == "nomencl_print") if (name == "nomencl_print")
return createGuiPrintNomencl(*this); return createGuiPrintNomencl(*this);
if (name == "note") if (name == "note")

View File

@ -16,11 +16,12 @@
#include "GuiBranch.h" #include "GuiBranch.h"
#include "GuiBibitem.h" #include "GuiBibitem.h"
#include "GuiERT.h" #include "GuiERT.h"
#include "GuiHSpace.h"
#include "GuiHyperlink.h" #include "GuiHyperlink.h"
#include "GuiInfo.h" #include "GuiInfo.h"
#include "GuiLabel.h" #include "GuiLabel.h"
#include "GuiLine.h" #include "GuiLine.h"
#include "GuiHSpace.h" #include "GuiNomencl.h"
#include "GuiTabular.h" #include "GuiTabular.h"
#include "GuiVSpace.h" #include "GuiVSpace.h"
#include "FloatPlacement.h" #include "FloatPlacement.h"
@ -249,6 +250,9 @@ Dialog * createDialog(GuiView & lv, InsetCode code)
case MATH_SPACE_CODE: case MATH_SPACE_CODE:
widget = new GuiHSpace(true); widget = new GuiHSpace(true);
break; break;
case NOMENCL_CODE:
widget = new GuiNomenclature;
break;
case SPACE_CODE: case SPACE_CODE:
widget = new GuiHSpace(false); widget = new GuiHSpace(false);
break; break;

View File

@ -1,132 +1,82 @@
<ui version="4.0" > <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NomenclUi</class> <class>NomenclUi</class>
<widget class="QDialog" name="NomenclUi" > <widget class="QWidget" name="NomenclUi">
<property name="geometry" > <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>254</width> <width>254</width>
<height>165</height> <height>172</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="windowTitle">
<string/> <string>Nomenclature</string>
</property> </property>
<property name="sizeGripEnabled" > <layout class="QGridLayout">
<bool>true</bool> <property name="margin">
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number> <number>9</number>
</property> </property>
<property name="spacing" > <property name="spacing">
<number>6</number> <number>6</number>
</property> </property>
<item row="2" column="1" > <item row="2" column="1">
<widget class="QLineEdit" name="prefixED" /> <widget class="QLineEdit" name="prefixED"/>
</item> </item>
<item row="2" column="0" > <item row="2" column="0">
<widget class="QLabel" name="prefixLA" > <widget class="QLabel" name="prefixLA">
<property name="text" > <property name="text">
<string>Sort &amp;as:</string> <string>Sort &amp;as:</string>
</property> </property>
<property name="buddy" > <property name="buddy">
<cstring>prefixED</cstring> <cstring>prefixED</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0" > <item row="1" column="0">
<widget class="QLabel" name="descrLA" > <widget class="QLabel" name="descrLA">
<property name="text" > <property name="text">
<string>&amp;Description:</string> <string>&amp;Description:</string>
</property> </property>
<property name="buddy" > <property name="buddy">
<cstring>descriptionTE</cstring> <cstring>descriptionTE</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0" > <item row="0" column="0">
<widget class="QLabel" name="symbolLA" > <widget class="QLabel" name="symbolLA">
<property name="text" > <property name="text">
<string>&amp;Symbol:</string> <string>&amp;Symbol:</string>
</property> </property>
<property name="buddy" > <property name="buddy">
<cstring>symbolED</cstring> <cstring>symbolED</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1" > <item row="0" column="1">
<widget class="QLineEdit" name="symbolED" > <widget class="QLineEdit" name="symbolED">
<property name="toolTip" > <property name="toolTip">
<string/> <string/>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0" colspan="2" > <item row="1" column="1">
<layout class="QHBoxLayout" > <widget class="QTextEdit" name="descriptionTE">
<property name="margin" > <property name="acceptRichText">
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="okPB" >
<property name="text" >
<string>&amp;OK</string>
</property>
<property name="shortcut" >
<string>Alt+O</string>
</property>
<property name="default" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closePB" >
<property name="text" >
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="1" >
<widget class="QTextEdit" name="descriptionTE" >
<property name="acceptRichText" >
<bool>false</bool> <bool>false</bool>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget> </widget>
<layoutdefault spacing="6" margin="11" /> <layoutdefault spacing="6" margin="11"/>
<tabstops> <tabstops>
<tabstop>symbolED</tabstop> <tabstop>symbolED</tabstop>
<tabstop>descriptionTE</tabstop> <tabstop>descriptionTE</tabstop>
<tabstop>prefixED</tabstop> <tabstop>prefixED</tabstop>
<tabstop>okPB</tabstop>
<tabstop>closePB</tabstop>
</tabstops> </tabstops>
<includes> <includes>
<include location="local" >qt_i18n.h</include> <include location="local">qt_i18n.h</include>
</includes> </includes>
<resources/> <resources/>
<connections/> <connections/>