}
-bool TocBackend::addType(std::string const & type)
-{
- // Is the type already supported?
- TocList::iterator toclist_it = tocs_.find(type);
- if (toclist_it != tocs_.end())
- return false;
-
- tocs_.insert(make_pair(type, Toc()));
- types_.push_back(type);
-
- return true;
-}
-
void TocBackend::updateItem(ParConstIterator const & par_it)
{
BufferParams const & bufparams = buffer_->params();
void TocBackend::update()
{
tocs_.clear();
- types_.clear();
BufferParams const & bufparams = buffer_->params();
const int min_toclevel = bufparams.getLyXTextClass().min_toclevel();
TocItem(pit, toclevel - min_toclevel, tocstring));
}
}
-
- TocList::iterator it = tocs_.begin();
- for (; it != tocs_.end(); ++it)
- types_.push_back(it->first);
}
void setBuffer(Buffer const * buffer)
{ buffer_ = buffer; }
///
- bool addType(std::string const & type);
- ///
void update();
///
void updateItem(ParConstIterator const & pit);
///
TocList const & tocs() const
{ return tocs_; }
- ///
- std::vector<std::string> const & types() const
- { return types_; }
+
///
Toc const & toc(std::string const & type) const;
/// Return the first Toc Item before the cursor
///
TocList tocs_;
///
- std::vector<std::string> types_;
- ///
Buffer const * buffer_;
}; // TocBackend
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
+ * \author Abdelrazak Younes
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "ControlToc.h"
+
#include "buffer.h"
#include "BufferView.h"
#include "bufferparams.h"
}
+TocList const & ControlToc::tocs() const
+{
+ return kernel().buffer().tocBackend().tocs();
+}
+
+
bool ControlToc::initialiseParams(string const & data)
{
+ if (!ControlCommand::initialiseParams(data))
+ return false;
+
+ types_.clear();
+ type_names_.clear();
+ TocList const & tocs = kernel().buffer().tocBackend().tocs();
+ TocList::const_iterator it = tocs.begin();
+ TocList::const_iterator end = tocs.end();
+ for (; it != end; ++it) {
+ types_.push_back(it->first);
+ type_names_.push_back(getGuiName(it->first));
+ }
+
+ string selected_type ;
+ if(params()["type"].empty()) //Then plain toc...
+ selected_type = params().getCmdName();
+ else
+ selected_type = to_ascii(params()["type"]);
+ selected_type_ = -1;
+ for (size_t i = 0; i != types_.size(); ++i) {
+ if (selected_type == types_[i]) {
+ selected_type_ = i;
+ break;
+ }
+ }
+
update();
- return ControlCommand::initialiseParams(data);
+ return true;
}
void ControlToc::goTo(TocItem const & item)
}
-bool ControlToc::canOutline(string const & type)
+bool ControlToc::canOutline(size_t type) const
{
- return type == "tableofcontents";
+ BOOST_ASSERT(type >= 0 && type < int(types_.size()));
+ return types_[type] == "tableofcontents";
}
}
-vector<string> const & ControlToc::getTypes() const
-{
- return kernel().buffer().tocBackend().types();
-}
-
-
void ControlToc::updateBackend()
{
kernel().buffer().tocBackend().update();
}
-TocIterator const ControlToc::getCurrentTocItem(
- string const & type) const
+TocIterator const ControlToc::getCurrentTocItem(size_t type) const
{
BOOST_ASSERT(kernel().bufferview());
-
ParConstIterator it(kernel().bufferview()->cursor());
- return kernel().buffer().tocBackend().item(type, it);
+ return kernel().buffer().tocBackend().item(types_[type], it);
}
return _(type);
}
-
-Toc const empty_list;
-
-Toc const & ControlToc::getContents(string const & type) const
-{
- // This shouldn't be possible...
- if (!kernel().isBufferAvailable()) {
- return empty_list;
- }
-
- return kernel().buffer().tocBackend().toc(type);
-}
-
} // namespace frontend
} // namespace lyx
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
+ * \author Abdelrazak Younes
*
* Full author contact details are available in file CREDITS.
*/
/// \c ControlCommand inherited method.
bool initialiseParams(std::string const & data);
+ ///
+ TocList const & tocs() const;
+
/// Goto this paragraph id
void goTo(TocItem const &);
/// Return the list of types available
- std::vector<std::string> const & getTypes() const;
+ std::vector<docstring> const & typeNames() const
+ { return type_names_; }
- /// Return the guiname from a given cmdName of the TOC param
- docstring const getGuiName(std::string const & type) const;
+ ///
+ int selectedType() { return selected_type_; }
/// Return the first TocItem before the cursor
- TocIterator const getCurrentTocItem(std::string const & type) const;
-
- /// Given a type, returns the contents
- Toc const & getContents(std::string const & type) const;
+ TocIterator const getCurrentTocItem(size_t type) const;
/// Apply the selected outlining operation
void outlineUp();
///
void outlineOut();
/// Test if outlining operation is possible
- bool canOutline(std::string const & type);
+ bool canOutline(size_t type) const;
///
void updateBackend();
public:
/// Update the model data if needed.
virtual void update() = 0;
+
+private:
+ /// Return the guiname from a given cmdName of the TOC param
+ docstring const getGuiName(std::string const & type) const;
+
+ std::vector<std::string> types_;
+ std::vector<docstring> type_names_;
+ int selected_type_;
};
} // namespace frontend
}
-bool QToc::canOutline()
+bool QToc::canOutline(int type) const
{
- vector<string> const & types = getTypes();
-
- if (types.empty())
+ if (type < 0)
return false;
- BOOST_ASSERT(type_ >= 0 && type_ < int(types.size()));
- return ControlToc::canOutline(types[type_]);
+ return ControlToc::canOutline(type);
}
-int QToc::getTocDepth()
+int QToc::getTocDepth(int type)
{
- if (type_ < 0)
+ if (type < 0)
return 0;
- return toc_models_[type_]->modelDepth();
+ return toc_models_[type]->modelDepth();
}
-QStandardItemModel * QToc::tocModel()
+QStandardItemModel * QToc::tocModel(int type)
{
+ if (type < 0)
+ return 0;
+
if (toc_models_.empty()) {
lyxerr[Debug::GUI] << "QToc::tocModel(): no types available " << endl;
return 0;
}
lyxerr[Debug::GUI]
- << "QToc: type_ " << type_
+ << "QToc: type_ " << type
<< " toc_models_.size() " << toc_models_.size()
<< endl;
- BOOST_ASSERT(type_ >= 0 && type_ < int(toc_models_.size()));
- return toc_models_[type_];
+ BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
+ return toc_models_[type];
}
-QStandardItemModel * QToc::setTocModel(int type)
+QModelIndex const QToc::getCurrentIndex(int type) const
{
- type_ = type;
-
- lyxerr[Debug::GUI]
- << "QToc: type_ " << type_
- << " toc_models_.size() " << toc_models_.size()
- << endl;
-
- BOOST_ASSERT(type_ >= 0 && type_ < int(toc_models_.size()));
- return toc_models_[type_];
-}
-
-
-QModelIndex const QToc::getCurrentIndex()
-{
- vector<string> const & types = getTypes();
- if (types.empty() || type_ < 0)
+ if (type < 0)
return QModelIndex();
- TocIterator const it = getCurrentTocItem(types[type_]);
- if (it == getContents(types[type_]).end() || !it->isValid()) {
- lyxerr[Debug::GUI] << "QToc::getCurrentIndex(): TocItem is invalid!" << endl;
- return QModelIndex();
- }
-
- return toc_models_[type_]->modelIndex(it);
+ return toc_models_[type]->modelIndex(getCurrentTocItem(type));
}
-void QToc::goTo(QModelIndex const & index)
+void QToc::goTo(int type, QModelIndex const & index)
{
- if (!index.isValid() || index.model() != tocModel()) {
+ if (type < 0 || !index.isValid()
+ || index.model() != toc_models_[type]) {
lyxerr[Debug::GUI]
<< "QToc::goTo(): QModelIndex is invalid!"
<< endl;
return;
}
- BOOST_ASSERT(type_ >= 0 && type_ < int(toc_models_.size()));
+ BOOST_ASSERT(type >= 0 && type < int(toc_models_.size()));
- TocIterator const it = toc_models_[type_]->tocIterator(index);
+ TocIterator const it = toc_models_[type]->tocIterator(index);
lyxerr[Debug::GUI]
<< "QToc::goTo " << lyx::to_utf8(it->str())
}
-int QToc::getType()
-{
- return type_;
-}
-
-
void QToc::update()
{
updateType();
void QToc::updateType()
{
-
QStringList type_list;
- vector<string> const & types = getTypes();
- if (types.empty()) {
- type_model_.setStringList(type_list);
- toc_models_.clear();
- lyxerr[Debug::GUI] << "QToc::updateType(): no types available " << endl;
- return;
- }
+ vector<docstring> const & type_names = typeNames();
+ BOOST_ASSERT(!type_names.empty());
+ for (size_t i = 0; i != type_names.size(); ++i)
+ type_list.append(toqstr(type_names[i]));
- string selected_type ;
- if(params()["type"].empty()) //Then plain toc...
- selected_type = params().getCmdName();
- else
- selected_type = to_ascii(params()["type"]);
-
- QString gui_names_;
- type_ = -1;
- for (size_t i = 0; i != types.size(); ++i) {
- string const & type_str = types[i];
- type_list.append(toqstr(getGuiName(type_str)));
- if (type_str == selected_type)
- type_ = i;
-
- lyxerr[Debug::GUI]
- << "QToc: new type " << type_str
- << "\ttoc_models_.size() " << toc_models_.size()
- << endl;
-
- }
type_model_.setStringList(type_list);
}
void QToc::updateToc()
{
toc_models_.clear();
- vector<string> const & types = getTypes();
-
- for (size_t i = 0; i != types.size(); ++i) {
-
- toc_models_.push_back(new TocModel(getContents(types[i])));
- }
-
+ TocList::const_iterator it = tocs().begin();
+ TocList::const_iterator end = tocs().end();
+ for (; it != end; ++it)
+ toc_models_.push_back(new TocModel(it->second));
}
///
void updateType();
- bool canOutline();
+ bool canOutline(int type) const;
- QStandardItemModel * tocModel();
- QStandardItemModel * setTocModel(int type);
+ QStandardItemModel * tocModel(int type);
QStringListModel * typeModel()
{ return &type_model_; }
///
- QModelIndex const getCurrentIndex();
+ QModelIndex const getCurrentIndex(int type) const;
///
- void goTo(QModelIndex const & index);
+ void goTo(int type, QModelIndex const & index);
///
int getType();
///
- int getTocDepth();
+ int getTocDepth(int type);
Q_SIGNALS:
/// Signal that the internal toc_models_ has been reset.
<< ", " << current.column()
<< endl;
- form_->goTo(current);
+ form_->goTo(typeCO->currentIndex(), current);
}
// expanding and then collapsing is probably better,
// but my qt 4.1.2 doesn't have expandAll()..
//tocTV->expandAll();
- QModelIndexList indices =
- form_->tocModel()->match(form_->tocModel()->index(0,0),
- Qt::DisplayRole, "*", -1,
- Qt::MatchWildcard|Qt::MatchRecursive);
+ QModelIndexList indices = tocTV->model()->match(
+ tocTV->model()->index(0,0),
+ Qt::DisplayRole, "*", -1,
+ Qt::MatchWildcard|Qt::MatchRecursive);
int size = indices.size();
for (int i = 0; i < size; i++) {
void TocWidget::on_typeCO_activated(int value)
{
- form_->setTocModel(value);
- updateGui();
+ setTocModel(value);
}
QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
if (!list.isEmpty()) {
enableButtons(false);
- form_->goTo(list[0]);
+ form_->goTo(typeCO->currentIndex(), list[0]);
form_->outlineUp();
enableButtons(true);
}
QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
if (!list.isEmpty()) {
enableButtons(false);
- form_->goTo(list[0]);
+ form_->goTo(typeCO->currentIndex(), list[0]);
form_->outlineDown();
enableButtons(true);
}
QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
if (!list.isEmpty()) {
enableButtons(false);
- form_->goTo(list[0]);
+ form_->goTo(typeCO->currentIndex(), list[0]);
form_->outlineIn();
enableButtons(true);
}
QModelIndexList const & list = tocTV->selectionModel()->selectedIndexes();
if (!list.isEmpty()) {
enableButtons(false);
- form_->goTo(list[0]);
+ form_->goTo(typeCO->currentIndex(), list[0]);
form_->outlineOut();
enableButtons(true);
}
{
updatePB->setEnabled(enable);
- if (!form_->canOutline())
+ if (!form_->canOutline(typeCO->currentIndex()))
enable = false;
moveUpPB->setEnabled(enable);
void TocWidget::update()
{
- select(form_->getCurrentIndex());
+ lyxerr[Debug::GUI] << "In TocWidget::update()" << endl;
+ select(form_->getCurrentIndex(typeCO->currentIndex()));
QWidget::update();
}
return;
}
+ QString current_text = typeCO->currentText();
typeCO->setModel(type_model);
- typeCO->setCurrentIndex(form_->getType());
+ int const current_type = typeCO->findText(current_text);
+ if (current_type != -1)
+ typeCO->setCurrentIndex(current_type);
+ else
+ typeCO->setCurrentIndex(form_->selectedType());
+ setTocModel(typeCO->currentIndex());
+}
+
+
+void TocWidget::setTocModel(size_t type)
+{
bool buttons_enabled = false;
- if (form_->tocModel()) {
- buttons_enabled = form_->tocModel()->rowCount() > 0;
- tocTV->setModel(form_->tocModel());
+ QStandardItemModel * toc_model = form_->tocModel(type);
+ if (toc_model) {
+ buttons_enabled = toc_model->rowCount() > 0;
+ tocTV->setModel(toc_model);
tocTV->setEditTriggers(QAbstractItemView::NoEditTriggers);
}
reconnectSelectionModel();
depthSL->setEnabled(true);
- depthSL->setMaximum(form_->getTocDepth());
+ depthSL->setMaximum(form_->getTocDepth(type));
depthSL->setValue(depth_);
- select(form_->getCurrentIndex());
- lyxerr[Debug::GUI]
- << "form_->tocModel()->rowCount " << form_->tocModel()->rowCount()
- << "\nform_->tocModel()->columnCount " << form_->tocModel()->columnCount()
- << endl;
+ lyxerr[Debug::GUI] << "In TocWidget::updateGui()" << endl;
+
+ select(form_->getCurrentIndex(typeCO->currentIndex()));
+
+ if (toc_model) {
+ lyxerr[Debug::GUI]
+ << "form_->tocModel()->rowCount "
+ << toc_model->rowCount()
+ << "\nform_->tocModel()->columnCount "
+ << toc_model->columnCount()
+ << endl;
+ }
}
/// Update Gui of the display.
void updateGui();
///
+ void setTocModel(size_t type);
+ ///
void select(QModelIndex const & index);
///
void selectionChanged(const QModelIndex & current,