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
|
#include <stdio.h>
#include <stdlib.h>
#include <qvbox.h>
#include <qlabel.h>
#include <qmultilineedit.h>
#include <qgroupbox.h>
#include <qtextcodec.h>
#include <qdir.h>
#include "UmlCom.h"
#include "TabDialog.h"
#include "UmlUseCase.h"
const struct {
const char * lbl;
const char * key;
QMultiLineEdit * (TabDialog::* a);
} Tabs[] = {
{ "The summary of the use case '",
"Summary", &TabDialog::summary },
{ "The operational context of the use case '",
"Context", &TabDialog::context },
{ "The pre-conditions of the use case '",
"Pre-Conditions", &TabDialog::precond },
{ "The detailed description of the use case '",
"Description", &TabDialog::description },
{ "The post-conditions of the use case '",
"Post-Conditions", &TabDialog::postcond },
{ "The exceptions of the use case '",
"Exceptions", &TabDialog::exceptions }
};
TabDialog::TabDialog(UmlUseCase * u) : QTabDialog(0, ""), uc(u) {
setCaption(QCString("Properties of the use case '") + u->name() + "'");
setCancelButton();
QString cs;
// note : QFile fp(QDir::home().absFilePath(".boumlrc")) doesn't work
// if the path contains non latin1 characters, for instance cyrillic !
QString s = QDir::home().absFilePath(".boumlrc");
FILE * fp = fopen((const char *) s, "r");
if (fp == 0)
cs = getenv("BOUML_CHARSET");
else {
char line[512];
while (fgets(line, sizeof(line) - 1, fp) != 0) {
if (!strncmp(line, "CHARSET ", 8)) {
int len = strlen(line);
if (len != 0) {
if (line[len - 1] == '\n')
line[--len] = 0;
if ((len != 0) && (line[len - 1] == '\r'))
line[len - 1] = 0;
}
cs = line+8;
break;
}
}
fclose(fp);
}
Codec = 0;
if (!cs.isEmpty() && ((Codec = QTextCodec::codecForName(cs)) == 0)) {
QVBox * vbox = new QVBox(this);
vbox->setMargin(5);
(new QLabel("ERROR : No codec for '" + cs + "'", vbox))
->setAlignment(AlignCenter);
addTab(vbox, "Use case wizard");
setOkButton(QString::null);
}
else {
for (unsigned i = 0; i != sizeof(Tabs)/sizeof(*Tabs); i += 1) {
QVBox * vbox = new QVBox(this);
vbox->setMargin(5);
(new QLabel(QCString(Tabs[i].lbl) + u->name() + "'",
new QGroupBox(1, Horizontal, vbox)))
->setAlignment(AlignCenter);
this->*(Tabs[i]).a = new QMultiLineEdit(vbox);
QCString v;
if (u->propertyValue(Tabs[i].key, v))
(this->*(Tabs[i]).a)->setText(toUnicode(v));
addTab(vbox, Tabs[i].key);
}
}
}
void TabDialog::accept() {
for (unsigned i = 0; i != sizeof(Tabs)/sizeof(*Tabs); i += 1)
uc->set_PropertyValue(Tabs[i].key, fromUnicode((this->*(Tabs[i]).a)->text()));
UmlCom::bye();
QTabDialog::accept();
}
void TabDialog::reject() {
UmlCom::bye();
QTabDialog::reject();
}
QString TabDialog::toUnicode(const char * str) {
if (Codec == 0)
return str;
else if ((str == 0) || (*str == 0))
return QString::null;
else
return Codec->toUnicode(str);
}
void TabDialog::latinize(QString & s) {
unsigned i = s.length();
while (i != 0) {
QChar c = s.at(--i);
if (c.latin1() == 0) {
if (c.unicode() == 8217)
// special case for the pseudo ' returned by microsoft editors
c = '\'';
else
c = ' ';
s.replace(i, 1, &c, 1);
}
}
}
QCString TabDialog::fromUnicode(const QString & s) {
if (Codec == 0) {
QString str = s;
latinize(str);
return QCString(str);
}
else if (s.isEmpty())
return "";
else
return Codec->fromUnicode(s);
}
|