8#include "ui_SchemaFileInfo.h"
16#include <QDialogButtonBox>
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;
108 auto item =
new QListWidgetItem(QString::fromStdString(file));
109 item->setToolTip(QString::fromStdString(inc));
110 m_ui->include_list->addItem(item);
111 if (!direct_includes.contains(file)) {
123 m_ui->include_list->update();
129 if (relationships !=
nullptr) {
130 for (
auto rel: *relationships) {
131 auto rel_class = rel->get_class_type();
132 if (rel_class ==
nullptr) {
133 QString warning =
"<b>Warning</b> class <i>"
134 + QString::fromStdString(cls->
get_name())
135 +
"</i> has relationship "
136 + QString::fromStdString(rel->get_name())
137 +
" referring to class <i>"
138 + QString::fromStdString(rel->get_type())
139 +
"</i> which is not loaded<br>";
140 m_ui->textBrowser->insertHtml(warning);
141 m_ui->textBrowser->show();
145 auto file = rel_class->get_file()->get_full_file_name();
148 QString warning =
"<b>Warning</b> class <i>"
149 + QString::fromStdString(cls->
get_name())
150 +
"</i> has relationship "
151 + QString::fromStdString(rel->get_name())
152 +
" referring to class <i>"
153 + QString::fromStdString(rel->get_class_type()->get_name())
154 +
"</i> from " + QString::fromStdString(file)
155 +
" which is not included<br>";
156 m_ui->textBrowser->insertHtml(warning);
157 m_ui->textBrowser->show();
168 if (super_classes !=
nullptr) {
169 for (
auto sc: *super_classes) {
171 if (sclass ==
nullptr) {
172 QString warning =
"<b>Warning</b> class <i>"
173 + QString::fromStdString(cls->
get_name())
174 +
"</i> refers to super class <i>" + QString::fromStdString(*sc)
175 +
"</i> which is not known<br>";
176 m_ui->textBrowser->insertHtml(warning);
177 m_ui->textBrowser->show();
181 auto file = sclass->get_file()->get_full_file_name();
184 QString warning =
"<b>Warning</b> class <i>"
185 + QString::fromStdString(cls->
get_name())
186 +
"</i> refers to super class <i>" + QString::fromStdString(*sc)
187 +
"</i> from " + QString::fromStdString(file)
188 +
" which is not included<br>";
189 m_ui->textBrowser->insertHtml(warning);
190 m_ui->textBrowser->show();
199 std::cout <<
"Removing include file " <<
filename <<
"\n";
206 for (
auto cls: classes) {
208 if (cls->get_file()->get_full_file_name() !=
filename) {
209 auto relationships = cls->direct_relationships();
210 if (relationships !=
nullptr) {
211 for (
auto rel: *relationships) {
212 auto file = rel->get_class_type()->get_file()->get_full_file_name();
213 if (!temp_files.contains(file)) {
214 auto message = QString(
215 "Cannot remove %1 as class %2 has relationship to its %3 class").arg(
216 QString::fromStdString(
filename)).arg(
217 QString::fromStdString(cls->get_name())).arg(
218 QString::fromStdString(rel->get_class_type()->get_name()));
219 QMessageBox::warning ( 0,
"Schema editor", message );
224 auto super_classes = cls->direct_super_classes();
225 if (super_classes !=
nullptr) {
226 for (
auto sc: *super_classes) {
228 auto file = sclass->get_file()->get_full_file_name();
229 if (!temp_files.contains(file)) {
230 auto message = QString(
231 "Cannot remove %1 as class %2 has superclass %3 in %1").arg(
232 QString::fromStdString(
filename)).arg(
233 QString::fromStdString(cls->get_name())).arg(
234 QString::fromStdString(*sc));
235 QMessageBox::warning ( 0,
"Schema editor", message );
248 QMessageBox::warning (0,
"Schema editor", QString::fromStdString(exc.
what()));
257 auto item =
m_ui->include_list->currentItem();
258 std::string fn = item->text().toStdString();
272 if (event->key() == Qt::Key_Escape) {
275 QWidget::keyPressEvent(event);
283 m_ui->class_list->clear();
284 m_ui->textBrowser->clear();
286 for (
auto cls: classes) {
287 auto item =
new QListWidgetItem(QString::fromStdString(cls->get_name()));
302 m_ui->class_list->addItem(item);
304 m_ui->class_summary->setText (
305 QString(
"Total of %1 classes").arg(classes.size()));
317 m_ui->missing_button->setEnabled(
false);
318 m_ui->missing_button->hide();
321 m_ui->missing_button->setEnabled(
true);
322 m_ui->missing_button->show();
340 QMessageBox::warning(0,
342 QString(
"Failed to save file %1" )
344 .append(QString(exc.
what())),
354 status.append(
"Read/Write");
357 status.append(
"Read only");
360 status.append(
" Modified");
362 m_ui->save_button->setEnabled(
true);
365 m_ui->save_button->setEnabled(
false);
369 m_ui->save_button->setEnabled(
false);
373 status.append(
" Active");
374 m_ui->active_button->setEnabled(
false);
377 m_ui->active_button->setEnabled(
true);
379 m_ui->status->setText(status);
383 auto fd =
new QFileDialog (
this, tr (
"Open File" ),
".",
384 tr (
"XML schema files (*.schema.xml)" ) );
385 fd->setFileMode ( QFileDialog::ExistingFiles );
386 fd->setViewMode ( QFileDialog::Detail );
387 fd->setAcceptMode ( QFileDialog::AcceptOpen );
390 auto files = fd->selectedFiles();
391 for (
auto file: files) {
400 std::cout <<
"\nAdding missing include files:\n";
408 m_ui->textBrowser->clear();
409 m_ui->textBrowser->hide();
418 if (file.starts_with(element.toStdString())) {
419 file = file.substr (element.size());
426 std::cout <<
" " << file <<
"\n";
431 catch (std::exception& exc) {
432 QString message = QString(
433 "Failed to add %1 to included files, %2" ).arg(
434 QString::fromStdString(file)).arg(exc.what());
435 QMessageBox::warning ( 0,
"Schema editor", message );
445 QAction* add =
new QAction ( tr (
"Add New Include File" ),
this );
446 connect (add, SIGNAL ( triggered() ),
this, SLOT (
add_include() ) );
447 QAction* remove =
new QAction ( tr (
"Remove Selected Include File" ),
this );
448 connect (remove, SIGNAL ( triggered() ),
this, SLOT (
remove_include() ) );
452 QAction* info =
new QAction ( tr (
"Show file info" ),
this );
453 connect (info, SIGNAL ( triggered() ),
this, SLOT (
show_file_info() ) );
458 if (
m_ui->include_list->currentIndex().isValid()) {
468 QAction * add =
new QAction (tr(
"&Add New Class"),
this );
469 connect (add, SIGNAL (triggered()),
this, SLOT (
add_new_class()));
471 QAction* remove =
new QAction(tr(
"&Remove Selected Class"),
this );
472 connect (remove, SIGNAL(triggered()),
this, SLOT(
remove_class()));
474 QAction* edit =
new QAction(tr(
"&Edit Selected Class"),
this );
475 connect (edit, SIGNAL (triggered()),
this, SLOT (
edit_class()));
477 QAction* move =
new QAction(tr(
"&Move Selected Class"),
this );
478 connect (move, SIGNAL (triggered()),
this, SLOT (
move_class()));
486 if (
m_ui->class_list->currentIndex().isValid()) {
498 m_ui->class_list->currentItem()->text().toStdString());
503 auto item =
m_ui->class_list->currentItem();
504 QString cn = item->text();
508 QMessageBox::warning ( 0,
"Schema editor",
509 QString (
"Cannot delete class because it has sub-classes." ) );
513 QMessageBox::warning (0,
"Schema editor",
514 QString (
"Cannot delete class because some other classes references it."));
523 m_ui->class_list->update();
531 auto qfn = QString::fromStdString(
m_filename);
532 auto text = QString(
"Could not make schema file %1 active!\n\n").arg(qfn);
533 QMessageBox::warning(0,
535 text.append(QString(exc.
what())),
545 auto item =
m_ui->include_list->currentItem();
546 std::string fn = item->text().toStdString();
562 auto item =
new QListWidgetItem(nc);
563 m_ui->class_list->addItem(item);
564 m_ui->class_list->sortItems();
565 m_ui->class_list->setCurrentItem(item);
566 m_ui->class_list->update();
580 bool widget_found =
false;
581 for ( QWidget * widget : QApplication::allWidgets() ) {
583 if ( sfi !=
nullptr ) {
584 if ( (sfi->objectName() ).compare ( fn ) == 0 ) {
586 sfi->setVisible (
true );
587 sfi->activateWindow();
593 if ( !widget_found ) {
static KernelWrapper & GetInstance()
void SetActiveSchema(const std::string &ActiveSchema)
dunedaq::oks::OksClass * FindClass(std::string ClassName) const
void RemoveInclude(std::string schemaFile, std::string IncludeFile) const
void SaveSchema(const std::string &file) const
void PushRemoveClassCommand(dunedaq::oks::OksClass *Class, std::string ClassName, std::string ClassDescription, bool Abstract)
void AddInclude(std::string schemaFile, std::string IncludeFile) const
void get_all_includes(const std::string &FileName, std::set< std::string > &IncludedFiles)
std::vector< dunedaq::oks::OksClass * > get_schema_classes(std::string &filename)
void get_direct_includes(const std::string &FileName, std::set< std::string > &IncludedFiles)
static void launch(QString class_name)
static QString createNewClass()
void new_window(SchemaFileInfo *win)
void add_missing_includes()
std::string prune_path(std::string file)
bool check_relationships(dunedaq::oks::OksClass *cls)
void launch_class_editor(QListWidgetItem *)
bool check_superclasses(dunedaq::oks::OksClass *cls)
std::set< std::string > m_missing_includes
QList< QUrl > m_path_urls
SchemaFileInfo(std::string filename, QWidget *parent=0)
void class_updated(QString class_name)
void show_file_info(QString fn)
void keyPressEvent(QKeyEvent *event) override
void add_file(std::string file)
void activate_include_context_menu(QPoint point)
void set_schemafile_active()
std::set< std::string > m_all_includes
Ui::SchemaFileInfo * m_ui
void activate_class_context_menu(QPoint point)
Failed to set active file.
Cannot remove include file. Such exception is thrown when OKS cannot remove include file.
bool get_is_abstract() const noexcept
const FList * all_sub_classes() const noexcept
const std::string & get_name() const noexcept
const std::list< OksRelationship * > * direct_relationships() const noexcept
const std::string & get_description() const noexcept
const std::list< std::string * > * direct_super_classes() const noexcept
virtual const char * what() const noexcept
static QColor get_color(const QString &item, const QString &group)