]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QToc.C
enable Font cache only for MacOSX and inline width() for other platform.
[lyx.git] / src / frontends / qt4 / QToc.C
1 /**
2  * \file QToc.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Abdelrazak Younes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "QToc.h"
15 #include "TocModel.h"
16 #include "Qt2BC.h"
17 #include "qt_helpers.h"
18
19 #include "debug.h"
20
21 #include "controllers/ControlToc.h"
22
23 #include <algorithm>
24
25 using std::endl;
26
27 using std::pair;
28 using std::vector;
29 using std::string;
30
31 namespace lyx {
32 namespace frontend {
33
34
35 QToc::QToc(Dialog & parent)
36         : ControlToc(parent)
37 {
38         update();
39 }
40
41
42 bool QToc::canOutline()
43 {
44         vector<string> const & types = getTypes();
45
46         BOOST_ASSERT(type_ >= 0 && type_ < int(types.size()));
47         return ControlToc::canOutline(types[type_]);
48 }
49
50
51 QStandardItemModel * QToc::tocModel()
52 {
53         lyxerr[Debug::GUI]
54                 << "QToc: type_ " << type_
55                 << "  toc_models_.size() " << toc_models_.size()
56                 << endl;
57
58         BOOST_ASSERT(type_ >= 0 && type_ < int(toc_models_.size()));
59         return toc_models_[type_];
60 }
61
62
63 QStandardItemModel * QToc::setTocModel(int type)
64 {
65         type_ = type;
66
67         lyxerr[Debug::GUI]
68                 << "QToc: type_ " << type_
69                 << "  toc_models_.size() " << toc_models_.size()
70                 << endl;
71
72         BOOST_ASSERT(type_ >= 0 && type_ < int(toc_models_.size()));
73         return toc_models_[type_];
74 }
75
76
77 QModelIndex const QToc::getCurrentIndex()
78 {
79         vector<string> const & types = getTypes();
80         TocIterator const it = getCurrentTocItem(types[type_]);
81         if (!it->isValid()) {
82                 lyxerr[Debug::GUI] << "QToc::getCurrentIndex(): TocItem is invalid!" << endl;
83                 return QModelIndex();
84         }
85
86         return toc_models_[type_]->modelIndex(it);
87 }
88
89
90 void QToc::goTo(QModelIndex const & index)
91 {
92         if (!index.isValid()) {
93                 lyxerr[Debug::GUI]
94                         << "QToc::goTo(): QModelIndex is invalid!"
95                         << endl;
96                 return;
97         }
98
99         TocIterator const it = toc_models_[type_]->tocIterator(index);
100         
101         lyxerr[Debug::GUI]
102                 << "QToc::goTo " << it->str()
103                 << endl;
104
105         it->goTo(kernel().lyxview());
106 }
107
108
109 void QToc::update()
110 {
111         toc_models_.clear();
112
113         QStringList type_list;
114
115         type_ = 0;
116
117         vector<string> const & types = getTypes();
118         string const & selected_type = toc::getType(params().getCmdName());
119         lyxerr[Debug::GUI] << "selected_type " << selected_type << endl;
120
121         QString gui_names_;
122         for (size_t i = 0; i != types.size(); ++i) {
123                 string const & type_str = types[i];
124                 type_list.append(toqstr(getGuiName(type_str)));
125                 if (type_str == selected_type)
126                         type_ = i;
127                 
128                 lyxerr[Debug::GUI]
129                         << "QToc: new type " << type_str
130                         << "\ttoc_models_.size() " << toc_models_.size()
131                         << endl;
132
133                 toc_models_.push_back(new TocModel(getContents(types[i])));
134         }
135         type_model_.setStringList(type_list);
136 }
137
138
139 void QToc::updateToc(int type)
140 {
141         toc_models_[type] = new TocModel(getContents(getTypes()[type]));
142 }
143
144
145 } // namespace frontend
146 } // namespace lyx