some refactoring

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@20821 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2007-10-07 14:59:01 +00:00
parent 4b510c9b7c
commit 24b95a387c
5 changed files with 32 additions and 50 deletions

View File

@ -160,11 +160,11 @@ Dialog * Dialogs::build(string const & name)
if (name == "include") if (name == "include")
return createGuiInclude(lyxview_); return createGuiInclude(lyxview_);
if (name == "index") if (name == "index")
return new GuiIndexDialog(lyxview_); return createGuiIndex(lyxview_);
if (name == "nomenclature") if (name == "nomenclature")
return createGuiNomenclature(lyxview_); return createGuiNomenclature(lyxview_);
if (name == "label") if (name == "label")
return new GuiLabelDialog(lyxview_); return createGuiLabel(lyxview_);
if (name == "log") if (name == "log")
return createGuiLog(lyxview_); return createGuiLog(lyxview_);
if (name == "view-source") if (name == "view-source")

View File

@ -25,6 +25,8 @@
#include "support/lstrings.h" #include "support/lstrings.h"
#include "support/docstring.h" #include "support/docstring.h"
#include "insets/InsetCommand.h"
#include <vector> #include <vector>
#include <string> #include <string>
@ -75,11 +77,10 @@ static vector<lyx::docstring> to_docstring_vector(QStringList const & qlist)
GuiCitation::GuiCitation(LyXView & lv) GuiCitation::GuiCitation(LyXView & lv)
: GuiDialog(lv, "citation"), ControlCommand(*this, "citation") : GuiCommand(lv, "citation")
{ {
setupUi(this); setupUi(this);
setViewTitle(_("Citation")); setViewTitle(_("Citation"));
setController(this, false);
connect(citationStyleCO, SIGNAL(activated(int)), connect(citationStyleCO, SIGNAL(activated(int)),
this, SLOT(changed())); this, SLOT(changed()));
@ -246,7 +247,7 @@ void GuiCitation::updateStyle()
citationStyleCO->setEnabled(!basic_engine && haveSelection); citationStyleCO->setEnabled(!basic_engine && haveSelection);
citationStyleLA->setEnabled(!basic_engine && haveSelection); citationStyleLA->setEnabled(!basic_engine && haveSelection);
string const & command = params().getCmdName(); string const & command = params_.getCmdName();
// Find the style of the citekeys // Find the style of the citekeys
vector<biblio::CiteStyle> const & styles = citeStyles_; vector<biblio::CiteStyle> const & styles = citeStyles_;
@ -458,10 +459,10 @@ void GuiCitation::apply(int const choice, bool const full, bool const force,
biblio::CitationStyle(styles[choice], full, force) biblio::CitationStyle(styles[choice], full, force)
.asLatexStr(); .asLatexStr();
params().setCmdName(command); params_.setCmdName(command);
params()["key"] = qstring_to_ucs4(cited_keys_.join(",")); params_["key"] = qstring_to_ucs4(cited_keys_.join(","));
params()["before"] = qstring_to_ucs4(before); params_["before"] = qstring_to_ucs4(before);
params()["after"] = qstring_to_ucs4(after); params_["after"] = qstring_to_ucs4(after);
dispatchParams(); dispatchParams();
} }
@ -475,13 +476,13 @@ void GuiCitation::clearSelection()
QString GuiCitation::textBefore() QString GuiCitation::textBefore()
{ {
return toqstr(params()["before"]); return toqstr(params_["before"]);
} }
QString GuiCitation::textAfter() QString GuiCitation::textAfter()
{ {
return toqstr(params()["after"]); return toqstr(params_["after"]);
} }
@ -492,7 +493,7 @@ void GuiCitation::init()
available_model_.setStringList(all_keys_); available_model_.setStringList(all_keys_);
// Ditto for the keys cited in this inset // Ditto for the keys cited in this inset
QString str = toqstr(params()["key"]); QString str = toqstr(params_["key"]);
if (str.isEmpty()) if (str.isEmpty())
cited_keys_.clear(); cited_keys_.clear();
else else
@ -586,8 +587,7 @@ void GuiCitation::setCitedKeys()
bool GuiCitation::initialiseParams(string const & data) bool GuiCitation::initialiseParams(string const & data)
{ {
if (!ControlCommand::initialiseParams(data)) InsetCommandMailer::string2params(lfun_name_, data, params_);
return false;
biblio::CiteEngine const engine = buffer().params().getEngine(); biblio::CiteEngine const engine = buffer().params().getEngine();
@ -607,10 +607,9 @@ bool GuiCitation::initialiseParams(string const & data)
} }
void GuiCitation::clearParams() void GuiCitation::clearParams()
{ {
ControlCommand::clearParams(); params_.clear();
bibkeysInfo_.clear(); bibkeysInfo_.clear();
} }

View File

@ -29,8 +29,7 @@
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
class GuiCitation class GuiCitation : public GuiCommand, public Ui::CitationUi
: public GuiDialog, public Ui::CitationUi, public ControlCommand
{ {
Q_OBJECT Q_OBJECT
@ -54,8 +53,6 @@ public Q_SLOTS:
void updateView(); void updateView();
private: private:
///
ControlCommand & controller() { return *this; }
/// ///
void closeEvent(QCloseEvent * e); void closeEvent(QCloseEvent * e);
/// prepares a call to GuiCitation::searchKeys when we /// prepares a call to GuiCitation::searchKeys when we
@ -101,28 +98,20 @@ private:
/// ///
void init(); void init();
/// Available keys /// Available keys
QStringListModel * available() { return &available_model_; } QStringListModel * available() { return &available_model_; }
/// Selected keys /// Selected keys
QStringListModel * selected() { return &selected_model_; } QStringListModel * selected() { return &selected_model_; }
/// Text before cite /// Text before cite
QString textBefore(); QString textBefore();
/// Text after cite /// Text after cite
QString textAfter(); QString textAfter();
/// Get key description /// Get key description
QString getKeyInfo(QString const &); QString getKeyInfo(QString const &);
/// Clear selected keys /// Clear selected keys
void clearSelection(); void clearSelection();
/// Return a list of available fields /// Return a list of available fields
QStringList getFieldsAsQStringList(); QStringList getFieldsAsQStringList();
/// Return a list of available fields /// Return a list of available fields
QStringList getEntriesAsQStringList(); QStringList getEntriesAsQStringList();

View File

@ -12,8 +12,6 @@
#include "GuiIndex.h" #include "GuiIndex.h"
#include "ControlCommand.h"
#include "debug.h" #include "debug.h"
#include "qt_helpers.h" #include "qt_helpers.h"
@ -36,12 +34,11 @@ namespace frontend {
GuiIndexDialogBase::GuiIndexDialogBase(LyXView & lv, GuiIndexDialogBase::GuiIndexDialogBase(LyXView & lv,
docstring const & title, QString const & label, std::string const & name) docstring const & title, QString const & label, std::string const & name)
: GuiDialog(lv, name) : GuiCommand(lv, name)
{ {
label_ = label; label_ = label;
setupUi(this); setupUi(this);
setViewTitle(title); setViewTitle(title);
setController(new ControlCommand(*this, name));
connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK())); connect(okPB, SIGNAL(clicked()), this, SLOT(slotOK()));
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
@ -75,12 +72,6 @@ GuiIndexDialogBase::GuiIndexDialogBase(LyXView & lv,
} }
ControlCommand & GuiIndexDialogBase::controller()
{
return static_cast<ControlCommand &>(GuiDialog::controller());
}
void GuiIndexDialogBase::change_adaptor() void GuiIndexDialogBase::change_adaptor()
{ {
changed(); changed();
@ -102,7 +93,7 @@ void GuiIndexDialogBase::closeEvent(QCloseEvent * e)
void GuiIndexDialogBase::updateContents() void GuiIndexDialogBase::updateContents()
{ {
docstring const contents = controller().params()["name"]; docstring const contents = params_["name"];
keywordED->setText(toqstr(contents)); keywordED->setText(toqstr(contents));
bc().setValid(!contents.empty()); bc().setValid(!contents.empty());
} }
@ -110,7 +101,7 @@ void GuiIndexDialogBase::updateContents()
void GuiIndexDialogBase::applyView() void GuiIndexDialogBase::applyView()
{ {
controller().params()["name"] = qstring_to_ucs4(keywordED->text()); params_["name"] = qstring_to_ucs4(keywordED->text());
} }
@ -127,7 +118,7 @@ bool GuiIndexDialogBase::isValid()
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
GuiIndexDialog::GuiIndexDialog(LyXView & lv) GuiIndex::GuiIndex(LyXView & lv)
: GuiIndexDialogBase(lv, _("Index Entry"), qt_("&Keyword:"), "index") : GuiIndexDialogBase(lv, _("Index Entry"), qt_("&Keyword:"), "index")
{ {
keywordED->setWhatsThis( qt_( keywordED->setWhatsThis( qt_(
@ -148,17 +139,23 @@ GuiIndexDialog::GuiIndexDialog(LyXView & lv)
} }
Dialog * createGuiIndex(LyXView & lv) { return new GuiIndex(lv); }
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// //
// Label Dialog // Label Dialog
// //
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
GuiLabelDialog::GuiLabelDialog(LyXView & lv) GuiLabel::GuiLabel(LyXView & lv)
: GuiIndexDialogBase(lv, _("Label"), qt_("&Label:"), "label") : GuiIndexDialogBase(lv, _("Label"), qt_("&Label:"), "label")
{} {}
Dialog * createGuiLabel(LyXView & lv) { return new GuiLabel(lv); }
} // namespace frontend } // namespace frontend
} // namespace lyx } // namespace lyx

View File

@ -14,13 +14,12 @@
#define GUIINDEX_H #define GUIINDEX_H
#include "GuiDialog.h" #include "GuiDialog.h"
#include "ControlCommand.h"
#include "ui_IndexUi.h" #include "ui_IndexUi.h"
namespace lyx { namespace lyx {
namespace frontend { namespace frontend {
class GuiIndexDialogBase : public GuiDialog, public Ui::IndexUi class GuiIndexDialogBase : public GuiCommand, public Ui::IndexUi
{ {
Q_OBJECT Q_OBJECT
@ -35,8 +34,6 @@ private Q_SLOTS:
private: private:
/// ///
void closeEvent(QCloseEvent * e); void closeEvent(QCloseEvent * e);
/// parent controller
ControlCommand & controller();
/// ///
bool isValid(); bool isValid();
/// Apply changes /// Apply changes
@ -49,17 +46,17 @@ private:
}; };
class GuiIndexDialog : public GuiIndexDialogBase class GuiIndex : public GuiIndexDialogBase
{ {
public: public:
GuiIndexDialog(LyXView & lv); GuiIndex(LyXView & lv);
}; };
class GuiLabelDialog : public GuiIndexDialogBase class GuiLabel : public GuiIndexDialogBase
{ {
public: public:
GuiLabelDialog(LyXView & lv); GuiLabel(LyXView & lv);
}; };