#include "GuiView.h"
#include "DockView.h"
#include "TocWidget.h"
-#include "FuncRequest.h"
-
-#include "insets/InsetCommand.h"
-
-#include "TocModel.h"
#include "qt_helpers.h"
#include "Buffer.h"
#include "BufferView.h"
#include "BufferParams.h"
-#include "FloatList.h"
#include "FuncRequest.h"
-#include "TextClass.h"
-#include "support/convert.h"
#include "support/debug.h"
#include "support/gettext.h"
-
#include "support/lassert.h"
-#include <algorithm>
-
using namespace std;
namespace lyx {
GuiToc::GuiToc(GuiView & parent, Qt::DockWidgetArea area, Qt::WindowFlags flags)
: DockView(parent, "toc", qt_("Outline"), area, flags)
{
- widget_ = new TocWidget(*this, &parent);
+ widget_ = new TocWidget(parent.tocModels(), &parent);
setWidget(widget_);
}
GuiToc::~GuiToc()
{
- clearTocModels();
delete widget_;
}
-void GuiToc::clearTocModels()
-{
- const unsigned int size = toc_models_.size();
- for (unsigned int i = 0; i < size; ++i) {
- delete toc_models_[i];
- }
- toc_models_.clear();
-}
-
-
-int GuiToc::getTocDepth(int type)
-{
- if (type < 0)
- return 0;
- return toc_models_[type]->modelDepth();
-}
-
-
-QStandardItemModel * GuiToc::tocModel(int type)
-{
- if (type < 0)
- return 0;
-
- if (toc_models_.empty()) {
- LYXERR(Debug::GUI, "GuiToc::tocModel(): no types available ");
- return 0;
- }
-
- LYXERR(Debug::GUI, "GuiToc: type " << type
- << " toc_models_.size() " << toc_models_.size());
-
- LASSERT(type >= 0 && type < int(toc_models_.size()), /**/);
- return toc_models_[type];
-}
-
-
-QModelIndex GuiToc::currentIndex(int type) const
-{
- if (type < 0)
- return QModelIndex();
-
- return toc_models_[type]->modelIndex(currentTocItem(type));
-}
-
-
-void GuiToc::goTo(int type, QModelIndex const & index)
-{
- if (type < 0 || !index.isValid()
- || index.model() != toc_models_[type]) {
- LYXERR(Debug::GUI, "GuiToc::goTo(): QModelIndex is invalid!");
- return;
- }
-
- LASSERT(type >= 0 && type < int(toc_models_.size()), /**/);
-
- TocIterator const it = toc_models_[type]->tocIterator(index);
-
- LYXERR(Debug::GUI, "GuiToc::goTo " << to_utf8(it->str()));
-
- string const tmp = convert<string>(it->id());
- dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
-}
-
-
void GuiToc::updateView()
{
widget_->updateView();
}
-TocList const & GuiToc::tocs() const
-{
- return buffer().masterBuffer()->tocBackend().tocs();
-}
-
-
bool GuiToc::initialiseParams(string const & data)
{
- LYXERR(Debug::GUI, data);
- types_.clear();
- type_names_.clear();
- clearTocModels();
- if (!bufferview())
- // Nothing to show here.
- return true;
-
- QString str = toqstr(data);
- QString new_type;
- if (str.contains("tableofcontents")) {
- new_type = "tableofcontents";
- } else if (str.contains("floatlist")) {
- if (str.contains("\"figure"))
- new_type = "figure";
- else if (str.contains("\"table"))
- new_type = "table";
- else if (str.contains("\"algorithm"))
- new_type = "algorithm";
- } else if (!str.isEmpty()) {
- new_type = str;
- } else {
- // Default to Outliner.
- new_type = "tableofcontents";
- }
-
- TocList const & tocs = buffer().masterBuffer()->tocBackend().tocs();
- TocList::const_iterator it = tocs.begin();
- TocList::const_iterator end = tocs.end();
- for (; it != end; ++it) {
- types_.push_back(toqstr(it->first));
- type_names_.push_back(toqstr(guiName(it->first)));
- toc_models_.push_back(new TocModel(it->second));
- }
-
- widget_->updateGui(types_.indexOf(new_type));
-
+ widget_->init(toqstr(data));
return true;
}
-bool GuiToc::canOutline(int type) const
-{
- return types_[type] == "tableofcontents";
-}
-
-
-void GuiToc::outlineUp()
-{
- dispatch(FuncRequest(LFUN_OUTLINE_UP));
-}
-
-
-void GuiToc::outlineDown()
-{
- dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
-}
-
-
-void GuiToc::outlineIn()
-{
- dispatch(FuncRequest(LFUN_OUTLINE_IN));
-}
-
-
-void GuiToc::outlineOut()
-{
- dispatch(FuncRequest(LFUN_OUTLINE_OUT));
-}
-
-
-void GuiToc::updateBackend()
-{
- buffer().masterBuffer()->tocBackend().update();
- buffer().structureChanged();
-}
-
-
-TocIterator GuiToc::currentTocItem(int type) const
-{
- LASSERT(bufferview(), /**/);
- ParConstIterator it(bufferview()->cursor());
- return buffer().masterBuffer()->tocBackend().item(fromqstr(types_[type]), it);
-}
-
-
-docstring GuiToc::guiName(string const & type) const
+void GuiToc::dispatchParams()
{
- if (type == "tableofcontents")
- return _("Table of Contents");
- if (type == "child")
- return _("Child Documents");
- if (type == "graphics")
- return _("List of Graphics");
- if (type == "equation")
- return _("List of Equations");
- if (type == "footnote")
- return _("List of Footnotes");
- if (type == "listing")
- return _("List of Listings");
- if (type == "index")
- return _("List of Indexes");
- if (type == "marginalnote")
- return _("List of Marginal notes");
- if (type == "note")
- return _("List of Notes");
- if (type == "citation")
- return _("List of Citations");
- if (type == "label")
- return _("Labels and References");
-
- FloatList const & floats = buffer().params().documentClass().floats();
- if (floats.typeExist(type))
- return _(floats.getType(type).listName());
-
- return _(type);
}
-void GuiToc::dispatchParams()
+void GuiToc::enableView(bool enable)
{
+ widget_->setEnabled(enable);
}
///
bool initialiseParams(std::string const & data);
- ///
void updateView();
- /// Test if outlining operation is possible
- bool canOutline(int type) const;
-
- QStandardItemModel * tocModel(int type);
- ///
- QModelIndex currentIndex(int type) const;
- ///
- void goTo(int type, QModelIndex const & index);
- ///
- int getType();
- ///
- int getTocDepth(int type);
-
-Q_SIGNALS:
- /// Signal that the internal toc_models_ has been reset.
- void modelReset();
-
-private:
- ///
- TocWidget * widget_;
- ///
- std::vector<TocModel *> toc_models_;
- ///
- void clearTocModels();
+ void enableView(bool enable);
public:
- ///
- TocList const & tocs() const;
-
- /// Return the list of types available
- QStringList const & typeNames() const { return type_names_; }
-
- /// Return the first TocItem before the cursor
- TocIterator currentTocItem(int type) const;
-
- /// Apply the selected outlining operation
- void outlineUp();
- ///
- void outlineDown();
- ///
- void outlineIn();
- ///
- void outlineOut();
- ///
- void updateBackend();
-
- /// Return the guiname from a given cmdName of the TOC param
- docstring guiName(std::string const & type) const;
-
/// clean-up on hide.
void clearParams() {}
///
///
bool isBufferDependent() const { return true; }
+private:
///
- QStringList types_;
- ///
- QStringList type_names_;
+ TocWidget * widget_;
};
} // namespace frontend
#include "GuiToolbar.h"
#include "GuiToolbars.h"
#include "Menus.h"
+#include "TocModel.h"
#include "qt_helpers.h"
Timeout autosave_timeout_;
/// flag against a race condition due to multiclicks, see bug #1119
bool in_show_;
+
+ ///
+ TocModels toc_models_;
};
}
+TocModels & GuiView::tocModels()
+{
+ return d.toc_models_;
+}
+
+
void GuiView::setFocus()
{
if (d.current_work_area_)
void GuiView::structureChanged()
{
+ d.toc_models_.reset(view());
updateDialog("toc", "");
}
class GuiToolbar;
class GuiWorkArea;
class TabWorkArea;
+class TocModels;
/**
* GuiView - Qt4 implementation of LyXView
void errors(std::string const &);
void structureChanged();
///@}
+
+ ///
+ TocModels & tocModels();
/// called on timeout
void autoSave();
#include "TocModel.h"
+#include "Buffer.h"
+#include "BufferParams.h"
+#include "BufferView.h"
+#include "Cursor.h"
+#include "FloatList.h"
+#include "FuncRequest.h"
+#include "LyXFunc.h"
+#include "ParIterator.h"
+#include "TextClass.h"
+
+#include "support/convert.h"
#include "support/debug.h"
-
#include "support/lassert.h"
+
#include <climits>
using namespace std;
return maxdepth_ - mindepth_;
}
+
+///////////////////////////////////////////////////////////////////////////////
+// TocModels implementation.
+///////////////////////////////////////////////////////////////////////////////
+void TocModels::clear()
+{
+ types_.clear();
+ type_names_.clear();
+ const unsigned int size = models_.size();
+ for (unsigned int i = 0; i < size; ++i) {
+ delete models_[i];
+ }
+ models_.clear();
+}
+
+
+int TocModels::depth(int type)
+{
+ if (type < 0)
+ return 0;
+ return models_[type]->modelDepth();
+}
+
+
+QStandardItemModel * TocModels::model(int type)
+{
+ if (type < 0)
+ return 0;
+
+ if (models_.empty()) {
+ LYXERR(Debug::GUI, "TocModels::tocModel(): no types available ");
+ return 0;
+ }
+
+ LYXERR(Debug::GUI, "TocModels: type " << type
+ << " models_.size() " << models_.size());
+
+ LASSERT(type >= 0 && type < int(models_.size()), /**/);
+ return models_[type];
+}
+
+
+QModelIndex TocModels::currentIndex(int type) const
+{
+ if (type < 0 || !bv_)
+ return QModelIndex();
+
+ ParConstIterator it(bv_->cursor());
+ return models_[type]->modelIndex(bv_->buffer().masterBuffer()->
+ tocBackend().item(fromqstr(types_[type]), it));
+}
+
+
+void TocModels::goTo(int type, QModelIndex const & index) const
+{
+ if (type < 0 || !index.isValid()
+ || index.model() != models_[type]) {
+ LYXERR(Debug::GUI, "TocModels::goTo(): QModelIndex is invalid!");
+ return;
+ }
+
+ LASSERT(type >= 0 && type < int(models_.size()), /**/);
+
+ TocIterator const it = models_[type]->tocIterator(index);
+
+ LYXERR(Debug::GUI, "TocModels::goTo " << it->str());
+
+ string const tmp = convert<string>(it->id());
+ dispatch(FuncRequest(LFUN_PARAGRAPH_GOTO, tmp));
+}
+
+
+void TocModels::updateBackend() const
+{
+ bv_->buffer().masterBuffer()->tocBackend().update();
+ bv_->buffer().structureChanged();
+}
+
+
+QString TocModels::guiName(string const & type) const
+{
+ if (type == "tableofcontents")
+ return qt_("Table of Contents");
+ if (type == "child")
+ return qt_("Child Documents");
+ if (type == "graphics")
+ return qt_("List of Graphics");
+ if (type == "equation")
+ return qt_("List of Equations");
+ if (type == "footnote")
+ return qt_("List of Footnotes");
+ if (type == "listing")
+ return qt_("List of Listings");
+ if (type == "index")
+ return qt_("List of Indexes");
+ if (type == "marginalnote")
+ return qt_("List of Marginal notes");
+ if (type == "note")
+ return qt_("List of Notes");
+ if (type == "citation")
+ return qt_("List of Citations");
+ if (type == "label")
+ return qt_("Labels and References");
+
+ FloatList const & floats = bv_->buffer().params().documentClass().floats();
+ if (floats.typeExist(type))
+ return qt_(floats.getType(type).listName());
+
+ return qt_(type);
+}
+
+
+void TocModels::reset(BufferView const * bv)
+{
+ bv_ = bv;
+ clear();
+ if (!bv_)
+ return;
+
+ TocList const & tocs = bv_->buffer().masterBuffer()->tocBackend().tocs();
+ TocList::const_iterator it = tocs.begin();
+ TocList::const_iterator end = tocs.end();
+ for (; it != end; ++it) {
+ types_.push_back(toqstr(it->first));
+ type_names_.push_back(guiName(it->first));
+ models_.push_back(new TocModel(it->second));
+ }
+}
+
+
+bool TocModels::canOutline(int type) const
+{
+ if (type < 0 || type >= types_.size())
+ return false;
+ return types_[type] == "tableofcontents";
+}
+
+
+int TocModels::decodeType(QString const & str) const
+{
+ QString new_type;
+ if (str.contains("tableofcontents")) {
+ new_type = "tableofcontents";
+ } else if (str.contains("floatlist")) {
+ if (str.contains("\"figure"))
+ new_type = "figure";
+ else if (str.contains("\"table"))
+ new_type = "table";
+ else if (str.contains("\"algorithm"))
+ new_type = "algorithm";
+ } else if (!str.isEmpty()) {
+ new_type = str;
+ } else {
+ // Default to Outliner.
+ new_type = "tableofcontents";
+ }
+ return types_.indexOf(new_type);
+}
+
} // namespace frontend
} // namespace lyx
#include <map>
namespace lyx {
+
+class BufferView;
+
namespace frontend {
class TocModel : public QStandardItemModel
{
- Q_OBJECT
-
public:
///
TocModel() {}
int mindepth_;
};
+
+class TocModels: public QObject
+{
+ Q_OBJECT
+public:
+ ///
+ TocModels(): bv_(0) {}
+ ///
+ TocModels::~TocModels() { clear(); }
+ ///
+ void reset(BufferView const * bv);
+ ///
+ int depth(int type);
+ ///
+ QStandardItemModel * model(int type);
+ ///
+ QModelIndex TocModels::currentIndex(int type) const;
+ ///
+ void goTo(int type, QModelIndex const & index) const;
+ ///
+ void TocModels::init(Buffer const & buffer);
+ /// Test if outlining operation is possible
+ bool canOutline(int type) const;
+ /// Return the list of types available
+ QStringList const & typeNames() const { return type_names_; }
+ ///
+ void updateBackend() const;
+ ///
+ int decodeType(QString const & str) const;
+
+Q_SIGNALS:
+ /// Signal that the internal toc_models_ has been reset.
+ void modelReset();
+
+private:
+ ///
+ void clear();
+ /// Return the guiname from a given cmdName of the TOC param
+ QString guiName(std::string const & type) const;
+ ///
+ BufferView const * bv_;
+ ///
+ std::vector<TocModel *> models_;
+ ///
+ QStringList types_;
+ ///
+ QStringList type_names_;
+};
+
} // namespace frontend
} // namespace lyx
#include "TocWidget.h"
-#include "GuiToc.h"
+#include "TocModel.h"
#include "qt_helpers.h"
+#include "FuncRequest.h"
+#include "LyXFunc.h"
+
#include "support/debug.h"
#include <QHeaderView>
namespace lyx {
namespace frontend {
-TocWidget::TocWidget(GuiToc & form, QWidget * parent)
- : QWidget(parent), depth_(0), form_(form)
+TocWidget::TocWidget(TocModels & models, QWidget * parent)
+ : QWidget(parent), depth_(0), models_(models)
{
setupUi(this);
LYXERR(Debug::GUI, "selectionChanged index " << current.row()
<< ", " << current.column());
- form_.goTo(typeCO->currentIndex(), current);
+ models_.goTo(typeCO->currentIndex(), current);
}
// The backend update can take some time so we disable
// the controls while waiting.
enableControls(false);
- form_.updateBackend();
+ models_.updateBackend();
}
/* FIXME (Ugras 17/11/06):
QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
if (!list.isEmpty()) {
enableControls(false);
- form_.goTo(typeCO->currentIndex(), list[0]);
- form_.outlineUp();
+ models_.goTo(typeCO->currentIndex(), list[0]);
+ dispatch(FuncRequest(LFUN_OUTLINE_UP));
enableControls(true);
}
}
QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
if (!list.isEmpty()) {
enableControls(false);
- form_.goTo(typeCO->currentIndex(), list[0]);
- form_.outlineDown();
+ models_.goTo(typeCO->currentIndex(), list[0]);
+ dispatch(FuncRequest(LFUN_OUTLINE_DOWN));
enableControls(true);
}
}
QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
if (!list.isEmpty()) {
enableControls(false);
- form_.goTo(typeCO->currentIndex(), list[0]);
- form_.outlineIn();
+ models_.goTo(typeCO->currentIndex(), list[0]);
+ dispatch(FuncRequest(LFUN_OUTLINE_IN));
enableControls(true);
}
}
QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
if (!list.isEmpty()) {
enableControls(false);
- form_.goTo(typeCO->currentIndex(), list[0]);
- form_.outlineOut();
+ models_.goTo(typeCO->currentIndex(), list[0]);
+ dispatch(FuncRequest(LFUN_OUTLINE_OUT));
enableControls(true);
}
}
{
updateTB->setEnabled(enable);
- if (!form_.canOutline(typeCO->currentIndex()))
+ if (!models_.canOutline(typeCO->currentIndex()))
enable = false;
moveUpTB->setEnabled(enable);
{
LYXERR(Debug::GUI, "In TocWidget::updateView()");
setTreeDepth();
- select(form_.currentIndex(typeCO->currentIndex()));
+ select(models_.currentIndex(typeCO->currentIndex()));
}
-void TocWidget::updateGui(int selected_type)
+void TocWidget::init(QString const & str)
{
- QStringList const & type_names = form_.typeNames();
+ QStringList const & type_names = models_.typeNames();
if (type_names.isEmpty()) {
enableControls(false);
typeCO->clear();
return;
}
+ int selected_type = models_.decodeType(str);
+
QString const current_text = typeCO->currentText();
typeCO->blockSignals(true);
typeCO->clear();
for (int i = 0; i != type_names.size(); ++i)
typeCO->addItem(type_names[i]);
- if (selected_type != -1)
+ if (!str.isEmpty())
typeCO->setCurrentIndex(selected_type);
else {
int const new_index = typeCO->findText(current_text);
if (new_index != -1)
typeCO->setCurrentIndex(new_index);
+ else
+ typeCO->setCurrentIndex(selected_type);
}
typeCO->blockSignals(false);
void TocWidget::setTocModel(size_t type)
{
bool controls_enabled = false;
- QStandardItemModel * toc_model = form_.tocModel(type);
+ QStandardItemModel * toc_model = models_.model(type);
if (toc_model) {
controls_enabled = toc_model->rowCount() > 0;
tocTV->setModel(toc_model);
reconnectSelectionModel();
if (controls_enabled) {
- depthSL->setMaximum(form_.getTocDepth(type));
+ depthSL->setMaximum(models_.depth(type));
depthSL->setValue(depth_);
}
LYXERR(Debug::GUI, "In TocWidget::updateGui()");
- select(form_.currentIndex(typeCO->currentIndex()));
+ select(models_.currentIndex(typeCO->currentIndex()));
if (toc_model) {
LYXERR(Debug::GUI, "tocModel()->rowCount "
void TocWidget::reconnectSelectionModel()
{
- connect(tocTV->selectionModel(),
- SIGNAL(currentChanged(const QModelIndex &,
- const QModelIndex &)),
- this,
- SLOT(selectionChanged(const QModelIndex &,
- const QModelIndex &)));
+ connect(tocTV->selectionModel(), SIGNAL(
+ currentChanged(const QModelIndex &, const QModelIndex &)),
+ this, SLOT(selectionChanged(const QModelIndex &, const QModelIndex &)));
}
+
void TocWidget::disconnectSelectionModel()
{
disconnect(tocTV->selectionModel(),
#include "GuiToc.h"
#include "ui_TocUi.h"
+class QString;
namespace lyx {
namespace frontend {
-class GuiToc;
+class TocModels;
class TocWidget : public QWidget, public Ui::TocUi
{
Q_OBJECT
public:
- TocWidget(GuiToc & form, QWidget * parent = 0);
+ TocWidget(TocModels & models, QWidget * parent = 0);
+
+ /// Initialise GUI.
+ void init(QString const & str);
public Q_SLOTS:
/// Update the display of the dialog whilst it is still visible.
void updateView();
- /// Update Gui of the display.
- void updateGui(int selected_type);
-
protected Q_SLOTS:
///
void setTocModel(size_t type);
void on_moveOutTB_clicked();
void setTreeDepth() { setTreeDepth(depth_); }
-protected:
+private:
///
void enableControls(bool enable = true);
///
int getIndexDepth(QModelIndex const & index, int depth = -1);
///
void setTreeDepth(int depth);
-
-private:
/// Reconnects the selection model change signal when TOC changed.
void reconnectSelectionModel();
/// Disconnects the selection model.
/// depth of list shown
int depth_;
///
- GuiToc & form_;
+ TocModels & models_;
};
} // namespace frontend