22 m_include_menu(nullptr), m_class_menu(nullptr) {
24 QWidget::setAttribute(Qt::WA_DeleteOnClose);
28 m_ui->missing_button->hide();
31 setObjectName(QString::fromStdString(
filename));
32 auto sp =
filename.find_last_of(
'/');
33 if (sp == std::string::npos) {
40 QString(
"Schema File: %1").arg(QString::fromStdString(
filename.substr(sp))));
46 m_ui->label->setPalette(pal);
52 QString DUNEDAQ_DB_PATH = getenv (
"DUNEDAQ_DB_PATH" );
53 m_path_list = DUNEDAQ_DB_PATH.split (QLatin1Char(
':'), Qt::SkipEmptyParts );
55 if ( !path.endsWith (
"/" ) ) {
63 m_ui->textBrowser->hide();
67 m_ui->include_list->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
68 m_ui->class_list->setContextMenuPolicy ( Qt::ContextMenuPolicy::CustomContextMenu );
69 connect (
m_ui->include_list, SIGNAL (itemActivated(QListWidgetItem*)),
71 connect (
m_ui->include_list, SIGNAL (customContextMenuRequested(QPoint)),
76 connect (
m_ui->active_button, SIGNAL(pressed()),
this, SLOT(
set_active()));
77 connect (
m_ui->add_button, SIGNAL(pressed()),
this, SLOT(
add_include()));
81 connect (
m_ui->class_list, SIGNAL (customContextMenuRequested(QPoint)),
85 m_ui->add_button->setEnabled(
false);
86 m_ui->active_button->setEnabled(
false);
87 m_ui->save_button->setEnabled(
false);
89 connect (
m_ui->save_button, SIGNAL(pressed()),
this, SLOT(
save_schema()));
90 connect (
m_ui->close_button, SIGNAL(pressed()),
this, SLOT(close()));
94 connect (
m_ui->class_list, SIGNAL (itemActivated(QListWidgetItem*)),
99 m_ui->include_list->clear();
103 std::set<std::string> direct_includes;
107 auto item =
new QListWidgetItem(QString::fromStdString(inc));
108 m_ui->include_list->addItem(item);
109 if (!direct_includes.contains(
prune_path(inc))) {
121 m_ui->include_list->update();
127 if (relationships !=
nullptr) {
128 for (
auto rel: *relationships) {
129 auto rel_class = rel->get_class_type();
130 if (rel_class ==
nullptr) {
131 QString warning =
"<b>Warning</b> class <i>"
132 + QString::fromStdString(cls->
get_name())
133 +
"</i> has relationship "
134 + QString::fromStdString(rel->get_name())
135 +
" referring to class <i>"
136 + QString::fromStdString(rel->get_type())
137 +
"</i> which is not loaded<br>";
138 m_ui->textBrowser->insertHtml(warning);
139 m_ui->textBrowser->show();
143 auto file = rel_class->get_file()->get_full_file_name();
146 QString warning =
"<b>Warning</b> class <i>"
147 + QString::fromStdString(cls->
get_name())
148 +
"</i> has relationship "
149 + QString::fromStdString(rel->get_name())
150 +
" referring to class <i>"
151 + QString::fromStdString(rel->get_class_type()->get_name())
152 +
"</i> from " + QString::fromStdString(file)
153 +
" which is not included<br>";
154 m_ui->textBrowser->insertHtml(warning);
155 m_ui->textBrowser->show();
166 if (super_classes !=
nullptr) {
167 for (
auto sc: *super_classes) {
169 if (sclass ==
nullptr) {
170 QString warning =
"<b>Warning</b> class <i>"
171 + QString::fromStdString(cls->
get_name())
172 +
"</i> refers to super class <i>" + QString::fromStdString(*sc)
173 +
"</i> which is not known<br>";
174 m_ui->textBrowser->insertHtml(warning);
175 m_ui->textBrowser->show();
179 auto file = sclass->get_file()->get_full_file_name();
182 QString warning =
"<b>Warning</b> class <i>"
183 + QString::fromStdString(cls->
get_name())
184 +
"</i> refers to super class <i>" + QString::fromStdString(*sc)
185 +
"</i> from " + QString::fromStdString(file)
186 +
" which is not included<br>";
187 m_ui->textBrowser->insertHtml(warning);
188 m_ui->textBrowser->show();
197 std::cout <<
"Removing include file " <<
filename <<
"\n";
204 for (
auto cls: classes) {
206 if (cls->get_file()->get_full_file_name() !=
filename) {
207 auto relationships = cls->direct_relationships();
208 if (relationships !=
nullptr) {
209 for (
auto rel: *relationships) {
210 auto file = rel->get_class_type()->get_file()->get_full_file_name();
211 if (!temp_files.contains(file)) {
212 auto message = QString(
213 "Cannot remove %1 as class %2 has relationship to its %3 class").arg(
214 QString::fromStdString(
filename)).arg(
215 QString::fromStdString(cls->get_name())).arg(
216 QString::fromStdString(rel->get_class_type()->get_name()));
217 QMessageBox::warning ( 0,
"Schema editor", message );
222 auto super_classes = cls->direct_super_classes();
223 if (super_classes !=
nullptr) {
224 for (
auto sc: *super_classes) {
226 auto file = sclass->get_file()->get_full_file_name();
227 if (!temp_files.contains(file)) {
228 auto message = QString(
229 "Cannot remove %1 as class %2 has superclass %3 in %1").arg(
230 QString::fromStdString(
filename)).arg(
231 QString::fromStdString(cls->get_name())).arg(
232 QString::fromStdString(*sc));
233 QMessageBox::warning ( 0,
"Schema editor", message );
246 QMessageBox::warning (0,
"Schema editor", QString::fromStdString(exc.
what()));
281 m_ui->class_list->clear();
282 m_ui->textBrowser->clear();
284 for (
auto cls: classes) {
285 auto item =
new QListWidgetItem(QString::fromStdString(cls->get_name()));
300 m_ui->class_list->addItem(item);
302 m_ui->class_summary->setText (
303 QString(
"Total of %1 classes").arg(classes.size()));
315 m_ui->missing_button->setEnabled(
false);
316 m_ui->missing_button->hide();
319 m_ui->missing_button->setEnabled(
true);
320 m_ui->missing_button->show();
434 if (m_include_menu ==
nullptr) {
435 m_include_menu =
new QMenu (
this);
438 QAction* add =
new QAction ( tr (
"Add New Include File" ),
this );
439 connect (add, SIGNAL ( triggered() ),
this, SLOT ( add_include() ) );
440 QAction* remove =
new QAction ( tr (
"Remove Selected Include File" ),
this );
441 connect (remove, SIGNAL ( triggered() ),
this, SLOT ( remove_include() ) );
442 m_include_menu->addAction ( add );
443 m_include_menu->addAction ( remove );
445 QAction* info =
new QAction ( tr (
"Show file info" ),
this );
446 connect (info, SIGNAL ( triggered() ),
this, SLOT ( show_file_info() ) );
448 m_include_menu->addAction ( info );
451 if (m_ui->include_list->currentIndex().isValid()) {
452 m_include_menu->exec (m_ui->include_list->mapToGlobal(pos));
458 if (m_class_menu ==
nullptr) {
459 m_class_menu =
new QMenu (
this);
461 QAction * add =
new QAction (tr(
"&Add New Class"),
this );
462 connect (add, SIGNAL (triggered()),
this, SLOT (add_new_class()));
464 QAction* remove =
new QAction(tr(
"&Remove Selected Class"),
this );
465 connect (remove, SIGNAL(triggered()),
this, SLOT(remove_class()));
467 QAction* edit =
new QAction(tr(
"&Edit Selected Class"),
this );
468 connect (edit, SIGNAL (triggered()),
this, SLOT (edit_class()));
470 QAction* move =
new QAction(tr(
"&Move Selected Class"),
this );
471 connect (move, SIGNAL (triggered()),
this, SLOT (move_class()));
473 m_class_menu->addAction (add);
474 m_class_menu->addAction (edit);
475 m_class_menu->addAction (move);
476 m_class_menu->addAction (remove);
479 if (m_ui->class_list->currentIndex().isValid()) {
480 m_class_menu->exec (m_ui->class_list->mapToGlobal(pos));