]> git.lyx.org Git - features.git/blob - src/frontends/qt/GuiIndex.cpp
Guard against possible referencing null.
[features.git] / src / frontends / qt / GuiIndex.cpp
1 /**
2  * \file GuiIndex.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  * \author Martin Vermeer
8  * \author Jürgen Spitzmüller
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "GuiIndex.h"
16
17 #include "qt_helpers.h"
18
19 #include "Buffer.h"
20 #include "BufferParams.h"
21 #include "FuncRequest.h"
22 #include "IndicesList.h"
23
24 #include <QPushButton>
25
26 using namespace std;
27
28 namespace lyx {
29 namespace frontend {
30
31 GuiIndex::GuiIndex(GuiView & lv)
32         : GuiDialog(lv, "index", qt_("Index Entry Settings"))
33 {
34         setupUi(this);
35
36         connect(buttonBox, SIGNAL(clicked(QAbstractButton *)),
37                 this, SLOT(slotButtonBox(QAbstractButton *)));
38         connect(indicesCO, SIGNAL(activated(int)), this, SLOT(change_adaptor()));
39
40         bc().setPolicy(ButtonPolicy::NoRepeatedApplyReadOnlyPolicy);
41         bc().setOK(buttonBox->button(QDialogButtonBox::Ok));
42         bc().setCancel(buttonBox->button(QDialogButtonBox::Cancel));
43 }
44
45
46 void GuiIndex::change_adaptor()
47 {
48         changed();
49 }
50
51
52 void GuiIndex::updateContents()
53 {
54         typedef IndicesList::const_iterator const_iterator;
55
56         IndicesList const & indiceslist = buffer().params().indiceslist();
57         docstring const cur_index = params_.index;
58
59         indicesCO->clear();
60
61         const_iterator const begin = indiceslist.begin();
62         const_iterator const end = indiceslist.end();
63         for (const_iterator it = begin; it != end; ++it)
64                 indicesCO->addItem(toqstr(it->index()),
65                         QVariant(toqstr(it->shortcut())));
66
67         int const pos = indicesCO->findData(toqstr(cur_index));
68         indicesCO->setCurrentIndex(pos);
69 }
70
71
72 void GuiIndex::applyView()
73 {
74         QString const index = indicesCO->itemData(
75                 indicesCO->currentIndex()).toString();
76         params_.index = qstring_to_ucs4(index);
77 }
78
79
80 bool GuiIndex::initialiseParams(string const & sdata)
81 {
82         InsetIndex::string2params(sdata, params_);
83         return true;
84 }
85
86
87 void GuiIndex::clearParams()
88 {
89         params_ = InsetIndexParams();
90 }
91
92
93 void GuiIndex::dispatchParams()
94 {
95         dispatch(FuncRequest(getLfun(), InsetIndex::params2string(params_)));
96 }
97
98
99 } // namespace frontend
100 } // namespace lyx
101
102 #include "moc_GuiIndex.cpp"