mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +00:00
simplify GuiToc / TocWidget interaction. Much can still be simplified...
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22953 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
a464490870
commit
8c73b3d2ce
@ -41,7 +41,7 @@ namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
GuiToc::GuiToc(GuiView & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags)
|
||||
: DockView(parent, "toc", qt_("Outline"), area, flags), params_(TOC_CODE)
|
||||
: DockView(parent, "toc", qt_("Outline"), area, flags)
|
||||
{
|
||||
widget_ = new TocWidget(*this);
|
||||
setWidget(widget_);
|
||||
@ -139,7 +139,15 @@ TocList const & GuiToc::tocs() const
|
||||
|
||||
bool GuiToc::initialiseParams(string const & data)
|
||||
{
|
||||
InsetCommandMailer::string2params("toc", data, params_);
|
||||
LYXERR(Debug::GUI, data);
|
||||
QString str = QString::fromUtf8(data.c_str());
|
||||
string new_type = "tableofcontents";
|
||||
if (str.contains("floatlist")) {
|
||||
if (str.contains("figure"))
|
||||
new_type = "figure";
|
||||
else if (str.contains("table"))
|
||||
new_type = "table";
|
||||
}
|
||||
|
||||
types_.clear();
|
||||
type_names_.clear();
|
||||
@ -153,20 +161,16 @@ bool GuiToc::initialiseParams(string const & data)
|
||||
toc_models_.push_back(new TocModel(it->second));
|
||||
}
|
||||
|
||||
string selected_type ;
|
||||
if (params_["type"].empty()) //Then plain toc...
|
||||
selected_type = params_.getCmdName();
|
||||
else
|
||||
selected_type = to_ascii(params_["type"]);
|
||||
selected_type_ = -1;
|
||||
int selected_type = -1;
|
||||
for (size_t i = 0; i != types_.size(); ++i) {
|
||||
if (selected_type == types_[i]) {
|
||||
selected_type_ = i;
|
||||
if (new_type == types_[i]) {
|
||||
selected_type = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
modelReset();
|
||||
widget_->updateGui(selected_type);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -237,9 +241,6 @@ docstring GuiToc::guiName(string const & type) const
|
||||
|
||||
void GuiToc::dispatchParams()
|
||||
{
|
||||
string const lfun =
|
||||
InsetCommandMailer::params2string("toc", params_);
|
||||
dispatch(FuncRequest(getLfun(), lfun));
|
||||
}
|
||||
|
||||
|
||||
|
@ -83,9 +83,6 @@ public:
|
||||
std::vector<docstring> const & typeNames() const
|
||||
{ return type_names_; }
|
||||
|
||||
///
|
||||
int selectedType() { return selected_type_; }
|
||||
|
||||
/// Return the first TocItem before the cursor
|
||||
TocIterator currentTocItem(int type) const;
|
||||
|
||||
@ -102,21 +99,16 @@ public:
|
||||
|
||||
std::vector<std::string> types_;
|
||||
std::vector<docstring> type_names_;
|
||||
int selected_type_;
|
||||
|
||||
/// Return the guiname from a given cmdName of the TOC param
|
||||
docstring guiName(std::string const & type) const;
|
||||
|
||||
/// clean-up on hide.
|
||||
void clearParams() { params_.clear(); }
|
||||
void clearParams() {}
|
||||
///
|
||||
void dispatchParams();
|
||||
///
|
||||
bool isBufferDependent() const { return true; }
|
||||
|
||||
private:
|
||||
///
|
||||
InsetCommandParams params_;
|
||||
};
|
||||
|
||||
} // namespace frontend
|
||||
|
@ -32,8 +32,6 @@ TocWidget::TocWidget(GuiToc & form, QWidget * parent)
|
||||
{
|
||||
setupUi(this);
|
||||
|
||||
connect(&form_, SIGNAL(modelReset()), SLOT(updateGui()));
|
||||
|
||||
moveOutTB->setIcon(QIcon(":/images/promote.png"));
|
||||
moveInTB->setIcon(QIcon(":/images/demote.png"));
|
||||
moveUpTB->setIcon(QIcon(":/images/up.png"));
|
||||
@ -212,7 +210,7 @@ void TocWidget::updateView()
|
||||
}
|
||||
|
||||
|
||||
void TocWidget::updateGui()
|
||||
void TocWidget::updateGui(int selected_type)
|
||||
{
|
||||
vector<docstring> const & type_names = form_.typeNames();
|
||||
if (type_names.empty()) {
|
||||
@ -224,20 +222,13 @@ void TocWidget::updateGui()
|
||||
}
|
||||
|
||||
QString current_text = typeCO->currentText();
|
||||
//lyxerr << "current_text " << fromqstr(current_text) << endl;
|
||||
typeCO->blockSignals(true);
|
||||
typeCO->clear();
|
||||
int current_type = -1;
|
||||
for (size_t i = 0; i != type_names.size(); ++i) {
|
||||
QString item = toqstr(type_names[i]);
|
||||
typeCO->addItem(item);
|
||||
if (item == current_text)
|
||||
current_type = i;
|
||||
}
|
||||
if (current_type != -1)
|
||||
typeCO->setCurrentIndex(current_type);
|
||||
else
|
||||
typeCO->setCurrentIndex(form_.selectedType());
|
||||
typeCO->setCurrentIndex(selected_type);
|
||||
typeCO->blockSignals(false);
|
||||
|
||||
setTocModel(typeCO->currentIndex());
|
||||
|
@ -32,9 +32,10 @@ public:
|
||||
/// Update the display of the dialog whilst it is still visible.
|
||||
void updateView();
|
||||
|
||||
protected Q_SLOTS:
|
||||
/// Update Gui of the display.
|
||||
void updateGui();
|
||||
void updateGui(int selected_type);
|
||||
|
||||
protected Q_SLOTS:
|
||||
///
|
||||
void setTocModel(size_t type);
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user