]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QToc.C
* ControlToc.[Ch]
[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 QToc::QToc(Dialog & parent)
35         : ControlToc(parent)
36 {
37         update();
38 }
39
40
41 bool QToc::canOutline()
42 {
43         vector<string> const & types = getTypes();
44
45         BOOST_ASSERT(type_ >= 0 && type_ < int(types.size()));
46         return ControlToc::canOutline(types[type_]);
47 }
48
49
50 QStandardItemModel * QToc::tocModel()
51 {
52         lyxerr[Debug::GUI]
53                 << "QToc: type_ " << type_
54                 << "  toc_models_.size() " << toc_models_.size()
55                 << endl;
56
57         BOOST_ASSERT(type_ >= 0 && type_ < int(toc_models_.size()));
58         return toc_models_[type_];
59 }
60
61
62 QStandardItemModel * QToc::setTocModel(int type)
63 {
64         type_ = type;
65
66         lyxerr[Debug::GUI]
67                 << "QToc: type_ " << type_
68                 << "  toc_models_.size() " << toc_models_.size()
69                 << endl;
70
71         BOOST_ASSERT(type_ >= 0 && type_ < int(toc_models_.size()));
72         return toc_models_[type_];
73 }
74
75
76 void QToc::goTo(QModelIndex const & index)
77 {
78         if (!index.isValid()) {
79                 lyxerr[Debug::GUI]
80                         << "QToc::goTo(): QModelIndex is invalid!"
81                         << endl;
82                 return;
83         }
84         
85         lyxerr[Debug::GUI]
86                 << "QToc::goTo " << toc_models_[type_]->item(index).str
87                 << endl;
88
89         ControlToc::goTo(toc_models_[type_]->item(index));
90 }
91
92
93 void QToc::update()
94 {
95         toc_models_.clear();
96
97         QStringList type_list;
98
99         type_ = 0;
100
101         vector<string> const & types = getTypes();
102         string const & selected_type = toc::getType(params().getCmdName());
103         lyxerr[Debug::GUI] << "selected_type " << selected_type << endl;
104
105         QString gui_names_;
106         for (size_t i = 0; i != types.size(); ++i) {
107                 string const & type_str = types[i];
108                 type_list.append(toqstr(getGuiName(type_str)));
109                 if (type_str == selected_type)
110                         type_ = i;
111                 
112                 lyxerr[Debug::GUI]
113                         << "QToc: new type " << type_str
114                         << "\ttoc_models_.size() " << toc_models_.size()
115                         << endl;
116
117                 toc_models_.push_back(new TocModel(getContents(types[i])));
118         }
119         type_model_.setStringList(type_list);
120 }
121
122
123 void QToc::updateToc(int type)
124 {
125         vector<string> const & choice = getTypes();
126
127         toc_models_[type] = new TocModel(getContents(choice[type]));
128 }
129
130
131 void QToc::move(toc::OutlineOp const operation, QModelIndex & index)
132 {
133         int toc_id = toc_models_[type_]->item(index).id_;
134         string toc_str = toc_models_[type_]->item(index).str;
135         toc_str.erase(0, toc_str.find(' ') + 1);
136
137         outline(operation);
138         updateToc(type_);
139
140         lyxerr[Debug::GUI]
141                 << "Toc id " << toc_id
142                 << "  Toc str " << toc_str
143                 << endl;
144
145         index = toc_models_[type_]->index(toc_str);
146 }
147
148 } // namespace frontend
149 } // namespace lyx