summaryrefslogtreecommitdiffstats
path: root/languages/fortran/ftnchekconfigwidget.cpp
blob: 8acc9985aee178c247e3fcdccdc83ba68fcbc929 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/***************************************************************************
 *   Copyright (C) 2001 by Bernd Gehrmann                                  *
 *   bernd@tdevelop.org                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "ftnchekconfigwidget.h"

#include <tqcheckbox.h>
#include <tqbuttongroup.h>
#include <tqheader.h>
#include <tqlistview.h>
#include <tqradiobutton.h>
#include <tqtooltip.h>
#include <klocale.h>

#include "domutil.h"


class FtnchekItem : public TQCheckListItem
{
public:
    FtnchekItem(TQListView *parent, const TQString &flagstr,
                const TQString &description)
        : TQCheckListItem(parent, flagstr, TQCheckListItem::CheckBox),
          flag(flagstr), desc(description)
    {
        setText(1, desc);
    }

    static void readFlagsToListView(TQListView *listview, TQStringList *list);
    static void writeFlagsFromListView(TQListView *listview, TQStringList *list);

private:
    TQString flag;
    TQString desc;
    friend class FtnchekToolTip;
};


void FtnchekItem::readFlagsToListView(TQListView *listview, TQStringList *list)
{
    TQListViewItem *item = listview->firstChild();
    for (; item; item = item->nextSibling()) {
        FtnchekItem *flitem = static_cast<FtnchekItem*>(item);
        TQStringList::Iterator sli = list->find(flitem->flag);
        if (sli != list->end()) {
            flitem->setOn(true);
            list->remove(sli);
        }
    }
}


void FtnchekItem::writeFlagsFromListView(TQListView *listview, TQStringList *list)
{
    (*list).clear();

    TQListViewItem *item = listview->firstChild();
    for (; item; item = item->nextSibling()) {
        FtnchekItem *flitem = static_cast<FtnchekItem*>(item);
        if (flitem->isOn())
            (*list) << flitem->flag;
    }
}


class FtnchekToolTip : public TQToolTip
{
public:
    FtnchekToolTip(TQWidget *parent)
        : TQToolTip(parent)
    {}
protected:
    void maybeTip(const TQPoint &pos)
    {
        TQListView *listview = static_cast<TQListView*>(parentWidget());
        TQListViewItem *item = listview->itemAt(pos);
        FtnchekItem *flitem = static_cast<FtnchekItem*>(item);

        if (item)
            tip(listview->itemRect(item), flitem->desc);
    }
};


const char *arguments_flags[] = {
    "arrayness",     I18N_NOOP("Warn about inconsistent use of arguments that use arrays"),
    "type",          I18N_NOOP("Warn about dummy arguments of a data type different from "
                               "the actual arguments"),
    "function-type", I18N_NOOP("Warn if the invocation assumes a different data type for the return type, "
                               "different from the actual return type"),
    "number",        I18N_NOOP("Warn about invoking a subprogram with an incorrect number of arguments"),
    0,               0
};


const char *common_flags[] = {
    "dimension", I18N_NOOP("Corresponding arrays in each declaration of a block must agree in size "
                           "and number of dimensions"),
    "exact",     I18N_NOOP("The comparison of two blocks is done variable-by-variable"),
    "length",    I18N_NOOP("Warn if different declarations of the same block are not equal in total length"),
    "type",      I18N_NOOP("In each declaration of a block, corresponding memory locations "
                           "must agree in data type"),
    0,           0
};


const char *truncation_flags[] = {
    "int-div-exponent", I18N_NOOP("Use of the result of integer division as an exponent"),
    "int-div-real",     I18N_NOOP("Conversion of an expression involving an integer division to real"),
    "int-div-zero",     I18N_NOOP("Division in an integer constant expression that yields a result of zero"),
    0,                  0
};


const char *usage_flags[] = {
    "arg-alias",        I18N_NOOP("A scalar dummy argument is actually the same as another "
                                  "and is (or may be) modified"),
    "arg-array-alias",  I18N_NOOP("A dummy argument which is an array or array element "
                                  "is the same array as another and is modified"),
    "arg-common-alias", I18N_NOOP("A scalar dummy argument is the same as a common variable in "
                                  "the subprogram, and either is modified"),
    0,                  0
};


const char *f77_flags[] = {
    "accept-type",     I18N_NOOP("ACCEPT and TYPE I/O statements"),
    "array-bounds",    I18N_NOOP("Expressions defining array bounds that contain array "
                                 "elements or function references"),
    "assignment-stmt", I18N_NOOP("Assignment statements involving arrays"),
    0,                 0
};


const char *portability_flags[] = {
    "backslash",        I18N_NOOP("Backslash characters in strings"),
    "common-alignment", I18N_NOOP("COMMON block variables not in descending order of storage sizes"),
    "hollerith",        I18N_NOOP("Hollerith constants"),
    0,                  0
};


FtnchekConfigWidget::FtnchekConfigWidget(TQDomDocument &projectDom, TQWidget *parent, const char *name)
    : FtnchekConfigWidgetBase(parent, name), dom(projectDom)
{
    arguments_group = new TQButtonGroup;
    arguments_group->insert(argumentsall_button);
    arguments_group->insert(argumentsonly_button);
    common_group = new TQButtonGroup;
    common_group->insert(commonall_button);
    common_group->insert(commononly_button);
    truncation_group = new TQButtonGroup;
    truncation_group->insert(truncationall_button);
    truncation_group->insert(truncationonly_button);
    usage_group = new TQButtonGroup;
    usage_group->insert(usageall_button);
    usage_group->insert(usageonly_button);
    f77_group = new TQButtonGroup;
    f77_group->insert(f77all_button);
    f77_group->insert(f77only_button);
    portability_group = new TQButtonGroup;
    portability_group->insert(portabilityall_button);
    portability_group->insert(portabilityonly_button);

    arguments_listview->header()->hide();
    new FtnchekToolTip(arguments_listview);

    common_listview->header()->hide();
    new FtnchekToolTip(common_listview);

    truncation_listview->header()->hide();
    new FtnchekToolTip(truncation_listview);

    usage_listview->header()->hide();
    new FtnchekToolTip(usage_listview);

    f77_listview->header()->hide();
    new FtnchekToolTip(f77_listview);

    portability_listview->header()->hide();
    new FtnchekToolTip(portability_listview);

    for (const char **p = arguments_flags; *p; p += 2)
        new FtnchekItem(arguments_listview, TQString::fromUtf8(*p), i18n(*(p+1)));

    for (const char **p = common_flags; *p; p += 2)
        new FtnchekItem(common_listview, TQString::fromUtf8(*p), i18n(*(p+1)));

    for (const char **p = truncation_flags; *p; p += 2)
        new FtnchekItem(truncation_listview, TQString::fromUtf8(*p), i18n(*(p+1)));

    for (const char **p = usage_flags; *p; p += 2)
        new FtnchekItem(usage_listview, TQString::fromUtf8(*p), i18n(*(p+1)));

    for (const char **p = f77_flags; *p; p += 2)
        new FtnchekItem(f77_listview, TQString::fromUtf8(*p), i18n(*(p+1)));

    for (const char **p = portability_flags; *p; p += 2)
        new FtnchekItem(portability_listview, TQString::fromUtf8(*p), i18n(*(p+1)));

    readConfig();
}


FtnchekConfigWidget::~FtnchekConfigWidget()
{
    delete arguments_group;
    delete common_group;
    delete truncation_group;
    delete usage_group;
    delete f77_group;
    delete portability_group;
}


void FtnchekConfigWidget::accept()
{
    storeConfig();
}


void FtnchekConfigWidget::readConfig()
{
    division_box->setChecked(DomUtil::readBoolEntry(dom,          "/kdevfortransupport/ftnchek/division"));
    extern_box->setChecked(DomUtil::readBoolEntry(dom,            "/kdevfortransupport/ftnchek/extern"));
    declare_box->setChecked(DomUtil::readBoolEntry(dom,           "/kdevfortransupport/ftnchek/declare"));
    pure_box->setChecked(DomUtil::readBoolEntry(dom,              "/kdevfortransupport/ftnchek/pure"));

    argumentsall_button->setChecked(DomUtil::readBoolEntry(dom,   "/kdevfortransupport/ftnchek/argumentsall"));
    commonall_button->setChecked(DomUtil::readBoolEntry(dom,      "/kdevfortransupport/ftnchek/commonall"));
    truncationall_button->setChecked(DomUtil::readBoolEntry(dom,  "/kdevfortransupport/ftnchek/truncationall"));
    usageall_button->setChecked(DomUtil::readBoolEntry(dom,       "/kdevfortransupport/ftnchek/usageall"));
    f77all_button->setChecked(DomUtil::readBoolEntry(dom,         "/kdevfortransupport/ftnchek/f77all"));
    portabilityall_button->setChecked(DomUtil::readBoolEntry(dom, "/kdevfortransupport/ftnchek/portabilityall"));

    TQStringList list;

    list = TQStringList::split(',', DomUtil::readEntry(dom, "/kdevfortransupport/ftnchek/argumentsonly"));
    FtnchekItem::readFlagsToListView(arguments_listview, &list);
    list = TQStringList::split(',', DomUtil::readEntry(dom, "/kdevfortransupport/ftnchek/commononly"));
    FtnchekItem::readFlagsToListView(common_listview, &list);
    list = TQStringList::split(',', DomUtil::readEntry(dom, "/kdevfortransupport/ftnchek/truncationonly"));
    FtnchekItem::readFlagsToListView(truncation_listview, &list);
    list = TQStringList::split(',', DomUtil::readEntry(dom, "/kdevfortransupport/ftnchek/usageonly"));
    FtnchekItem::readFlagsToListView(usage_listview, &list);
    list = TQStringList::split(',', DomUtil::readEntry(dom, "/kdevfortransupport/ftnchek/f77only"));
    FtnchekItem::readFlagsToListView(f77_listview, &list);
    list = TQStringList::split(',', DomUtil::readEntry(dom, "/kdevfortransupport/ftnchek/portabilityonly"));
    FtnchekItem::readFlagsToListView(portability_listview, &list);
}


void FtnchekConfigWidget::storeConfig()
{
    DomUtil::writeBoolEntry(dom, "/kdevfortransupport/ftnchek/division",       division_box->isChecked());
    DomUtil::writeBoolEntry(dom, "/kdevfortransupport/ftnchek/extern",         extern_box->isChecked());
    DomUtil::writeBoolEntry(dom, "/kdevfortransupport/ftnchek/declare",        declare_box->isChecked());
    DomUtil::writeBoolEntry(dom, "/kdevfortransupport/ftnchek/pure",           pure_box->isChecked());

    DomUtil::writeBoolEntry(dom, "/kdevfortransupport/ftnchek/argumentsall",   argumentsall_button->isChecked());
    DomUtil::writeBoolEntry(dom, "/kdevfortransupport/ftnchek/commonall",      commonall_button->isChecked());
    DomUtil::writeBoolEntry(dom, "/kdevfortransupport/ftnchek/truncationall",  truncationall_button->isChecked());
    DomUtil::writeBoolEntry(dom, "/kdevfortransupport/ftnchek/usageall",       usageall_button->isChecked());
    DomUtil::writeBoolEntry(dom, "/kdevfortransupport/ftnchek/f77all",         f77all_button->isChecked());
    DomUtil::writeBoolEntry(dom, "/kdevfortransupport/ftnchek/portabilityall", portabilityall_button->isChecked());

    TQStringList list;

    FtnchekItem::writeFlagsFromListView(arguments_listview, &list);
    DomUtil::writeEntry(dom, "/kdevfortransupport/ftnchek/argumentsonly",   list.join(","));
    FtnchekItem::writeFlagsFromListView(common_listview, &list);
    DomUtil::writeEntry(dom, "/kdevfortransupport/ftnchek/commononly",      list.join(","));
    FtnchekItem::writeFlagsFromListView(truncation_listview, &list);
    DomUtil::writeEntry(dom, "/kdevfortransupport/ftnchek/truncationonly",  list.join(","));
    FtnchekItem::writeFlagsFromListView(usage_listview, &list);
    DomUtil::writeEntry(dom, "/kdevfortransupport/ftnchek/usageonly",       list.join(","));
    FtnchekItem::writeFlagsFromListView(f77_listview, &list);
    DomUtil::writeEntry(dom, "/kdevfortransupport/ftnchek/f77only",         list.join(","));
    FtnchekItem::writeFlagsFromListView(portability_listview, &list);
    DomUtil::writeEntry(dom, "/kdevfortransupport/ftnchek/portabilityonly", list.join(","));
}

#include "ftnchekconfigwidget.moc"