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
|
|
|
|
|
|
|
|
#include "qt_helpers.h"
|
|
|
|
|
2008-06-17 16:26:43 +00:00
|
|
|
#include <QHash>
|
2006-04-18 09:57:47 +00:00
|
|
|
#include <QStandardItemModel>
|
2008-09-29 21:53:24 +00:00
|
|
|
|
|
|
|
class QSortFilterProxyModel;
|
2006-04-18 09:57:47 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
2008-05-02 12:09:51 +00:00
|
|
|
|
2008-06-12 15:31:10 +00:00
|
|
|
class Buffer;
|
2008-05-02 12:09:51 +00:00
|
|
|
class BufferView;
|
2008-06-12 15:31:10 +00:00
|
|
|
class DocIterator;
|
|
|
|
class Toc;
|
|
|
|
class TocItem;
|
2008-05-02 12:09:51 +00:00
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
namespace frontend {
|
|
|
|
|
2008-09-30 07:38:34 +00:00
|
|
|
/// A QStandardItemModel that gives access to the reset method.
|
2009-12-11 00:59:10 +00:00
|
|
|
/// This is needed in order to fix http://www.lyx.org/trac/ticket/3740
|
2008-06-17 15:10:03 +00:00
|
|
|
class TocTypeModel : public QStandardItemModel
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
///
|
2008-09-29 21:53:24 +00:00
|
|
|
TocTypeModel(QObject * parent);
|
2008-06-17 15:10:03 +00:00
|
|
|
///
|
|
|
|
void reset();
|
|
|
|
};
|
|
|
|
|
2008-09-30 07:38:34 +00:00
|
|
|
/// A class that adapt the TocBackend of a Buffer into standard Qt models for
|
|
|
|
/// GUI visualisation.
|
|
|
|
/// There is one TocModel per list in the TocBackend.
|
2008-09-28 17:14:29 +00:00
|
|
|
class TocModel
|
2007-11-14 00:21:31 +00:00
|
|
|
{
|
2006-04-18 09:57:47 +00:00
|
|
|
public:
|
|
|
|
///
|
2008-09-29 21:53:24 +00:00
|
|
|
TocModel(QObject * parent);
|
2008-06-17 15:10:03 +00:00
|
|
|
///
|
|
|
|
void reset(Toc const & toc);
|
|
|
|
///
|
|
|
|
void reset();
|
2006-04-18 09:57:47 +00:00
|
|
|
///
|
2008-09-30 09:50:54 +00:00
|
|
|
void updateItem(DocIterator const & dit);
|
|
|
|
///
|
2008-09-28 17:14:29 +00:00
|
|
|
void clear();
|
|
|
|
///
|
|
|
|
QAbstractItemModel * model();
|
|
|
|
///
|
|
|
|
QAbstractItemModel const * model() const;
|
|
|
|
///
|
|
|
|
void sort(bool sort_it);
|
|
|
|
///
|
|
|
|
bool isSorted() const { return is_sorted_; }
|
|
|
|
///
|
2008-06-12 15:31:10 +00:00
|
|
|
TocItem const & tocItem(QModelIndex const & index) const;
|
2006-04-18 09:57:47 +00:00
|
|
|
///
|
2008-06-12 15:31:10 +00:00
|
|
|
QModelIndex modelIndex(DocIterator const & dit) 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:
|
|
|
|
///
|
2008-06-12 17:34:01 +00:00
|
|
|
void populate(unsigned int & index, QModelIndex const & parent);
|
2006-04-18 09:57:47 +00:00
|
|
|
///
|
2008-09-28 17:14:29 +00:00
|
|
|
TocTypeModel * model_;
|
|
|
|
///
|
|
|
|
QSortFilterProxyModel * sorted_model_;
|
|
|
|
///
|
|
|
|
bool is_sorted_;
|
|
|
|
///
|
2008-06-17 15:10:03 +00:00
|
|
|
Toc const * toc_;
|
2006-11-25 22:16:22 +00:00
|
|
|
///
|
|
|
|
int maxdepth_;
|
2008-09-29 21:53:24 +00:00
|
|
|
///
|
2006-11-25 22:16:22 +00:00
|
|
|
int mindepth_;
|
2006-04-18 09:57:47 +00:00
|
|
|
};
|
|
|
|
|
2008-05-02 12:09:51 +00:00
|
|
|
|
2008-09-30 07:38:34 +00:00
|
|
|
/// A container for the different TocModels.
|
2008-09-29 21:53:24 +00:00
|
|
|
class TocModels : public QObject
|
2008-05-02 12:09:51 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
///
|
2008-06-17 15:10:03 +00:00
|
|
|
TocModels();
|
2008-05-02 12:09:51 +00:00
|
|
|
///
|
|
|
|
void reset(BufferView const * bv);
|
|
|
|
///
|
2008-06-17 15:10:03 +00:00
|
|
|
int depth(QString const & type);
|
|
|
|
///
|
2008-09-28 17:14:29 +00:00
|
|
|
QAbstractItemModel * model(QString const & type);
|
2008-05-02 12:09:51 +00:00
|
|
|
///
|
2008-06-18 11:35:24 +00:00
|
|
|
QAbstractItemModel * nameModel();
|
2008-05-02 12:09:51 +00:00
|
|
|
///
|
2008-06-17 15:10:03 +00:00
|
|
|
QModelIndex currentIndex(QString const & type) const;
|
2008-05-02 12:09:51 +00:00
|
|
|
///
|
2008-06-17 15:10:03 +00:00
|
|
|
void goTo(QString const & type, QModelIndex const & index) const;
|
2008-05-02 12:09:51 +00:00
|
|
|
///
|
2008-05-02 15:54:41 +00:00
|
|
|
void init(Buffer const & buffer);
|
2008-05-02 12:09:51 +00:00
|
|
|
///
|
|
|
|
void updateBackend() const;
|
2008-09-28 17:14:29 +00:00
|
|
|
///
|
2008-09-30 09:50:54 +00:00
|
|
|
void updateItem(QString const & type, DocIterator const & dit);
|
|
|
|
///
|
2008-09-28 17:14:29 +00:00
|
|
|
void sort(QString const & type, bool sort_it);
|
|
|
|
///
|
|
|
|
bool isSorted(QString const & type) const;
|
2009-04-08 21:40:42 +00:00
|
|
|
/// the item that is currently selected
|
|
|
|
TocItem const currentItem(QString const & type,
|
|
|
|
QModelIndex const & index) const;
|
2008-05-02 12:09:51 +00:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
/// Signal that the internal toc_models_ has been reset.
|
|
|
|
void modelReset();
|
|
|
|
|
|
|
|
private:
|
2008-06-17 15:18:34 +00:00
|
|
|
typedef QHash<QString, TocModel *>::const_iterator const_iterator;
|
2008-06-17 15:10:03 +00:00
|
|
|
typedef QHash<QString, TocModel *>::iterator iterator;
|
2008-05-02 12:09:51 +00:00
|
|
|
///
|
|
|
|
void clear();
|
|
|
|
///
|
2008-06-17 15:10:03 +00:00
|
|
|
BufferView const * bv_;
|
2008-05-02 12:09:51 +00:00
|
|
|
///
|
2008-06-17 15:10:03 +00:00
|
|
|
QHash<QString, TocModel *> models_;
|
2008-05-02 12:09:51 +00:00
|
|
|
///
|
2008-06-17 15:10:03 +00:00
|
|
|
TocTypeModel * names_;
|
2008-06-18 11:35:24 +00:00
|
|
|
///
|
|
|
|
QSortFilterProxyModel * names_sorted_;
|
2008-05-02 12:09:51 +00:00
|
|
|
};
|
|
|
|
|
2006-04-18 09:57:47 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
|
|
#endif // TOCMODEL_H
|