2006-04-18 09:57:47 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file TocModel.h
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Abdelrazak Younes
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TOCMODEL_H
|
|
|
|
#define TOCMODEL_H
|
|
|
|
|
2006-04-22 18:48:28 +00:00
|
|
|
#include "TocBackend.h"
|
2006-04-18 09:57:47 +00:00
|
|
|
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
|
|
|
#include <QStandardItemModel>
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
namespace lyx {
|
2008-05-02 12:09:51 +00:00
|
|
|
|
|
|
|
class BufferView;
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
namespace frontend {
|
|
|
|
|
2007-11-14 00:21:31 +00:00
|
|
|
class TocModel : public QStandardItemModel
|
|
|
|
{
|
2006-04-18 09:57:47 +00:00
|
|
|
public:
|
|
|
|
///
|
|
|
|
TocModel() {}
|
|
|
|
///
|
2008-03-26 22:25:43 +00:00
|
|
|
TocModel(Toc const & toc) { populate(toc); }
|
2006-04-18 09:57:47 +00:00
|
|
|
///
|
|
|
|
void clear();
|
|
|
|
///
|
2006-11-13 16:53:49 +00:00
|
|
|
void populate(Toc const & toc);
|
2006-04-18 09:57:47 +00:00
|
|
|
///
|
2008-03-26 22:25:43 +00:00
|
|
|
TocIterator tocIterator(QModelIndex const & index) const;
|
2006-04-18 09:57:47 +00:00
|
|
|
///
|
2008-03-26 22:25:43 +00:00
|
|
|
QModelIndex modelIndex(TocIterator const & it) const;
|
2006-11-25 22:16:22 +00:00
|
|
|
///
|
2007-11-14 00:21:31 +00:00
|
|
|
int modelDepth() const;
|
2006-04-18 09:57:47 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
///
|
2007-11-14 00:21:31 +00:00
|
|
|
void populate(TocIterator & it, TocIterator const & end,
|
2006-04-28 09:16:48 +00:00
|
|
|
QModelIndex const & parent);
|
2006-04-22 18:48:28 +00:00
|
|
|
///
|
|
|
|
typedef std::map<QModelIndex, TocIterator> TocMap;
|
|
|
|
///
|
|
|
|
typedef std::map<TocIterator, QModelIndex> ModelMap;
|
2006-04-18 09:57:47 +00:00
|
|
|
///
|
2006-04-28 09:16:48 +00:00
|
|
|
TocMap toc_map_;
|
2006-04-18 09:57:47 +00:00
|
|
|
///
|
2006-04-22 18:48:28 +00:00
|
|
|
ModelMap model_map_;
|
2006-11-25 22:16:22 +00:00
|
|
|
///
|
|
|
|
int maxdepth_;
|
|
|
|
int mindepth_;
|
2006-04-18 09:57:47 +00:00
|
|
|
};
|
|
|
|
|
2008-05-02 12:09:51 +00:00
|
|
|
|
|
|
|
class TocModels: public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
TocModels(): bv_(0) {}
|
|
|
|
///
|
2008-05-02 15:54:41 +00:00
|
|
|
~TocModels() { clear(); }
|
2008-05-02 12:09:51 +00:00
|
|
|
///
|
|
|
|
void reset(BufferView const * bv);
|
|
|
|
///
|
|
|
|
int depth(int type);
|
|
|
|
///
|
|
|
|
QStandardItemModel * model(int type);
|
|
|
|
///
|
2008-05-02 15:54:41 +00:00
|
|
|
QModelIndex currentIndex(int type) const;
|
2008-05-02 12:09:51 +00:00
|
|
|
///
|
|
|
|
void goTo(int type, QModelIndex const & index) const;
|
|
|
|
///
|
2008-05-02 15:54:41 +00:00
|
|
|
void init(Buffer const & buffer);
|
2008-05-02 12:09:51 +00:00
|
|
|
/// 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();
|
|
|
|
///
|
|
|
|
BufferView const * bv_;
|
|
|
|
///
|
|
|
|
std::vector<TocModel *> models_;
|
|
|
|
///
|
|
|
|
QStringList types_;
|
|
|
|
///
|
|
|
|
QStringList type_names_;
|
|
|
|
};
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
|
|
#endif // TOCMODEL_H
|