Line data Source code
1 :
2 : #include "dbe/SchemaFileInfo.hpp"
3 : #include "dbe/SchemaClassEditor.hpp"
4 : #include "dbe/SchemaKernelWrapper.hpp"
5 : #include "dbe/SchemaStyle.hpp"
6 : #include "oks/class.hpp"
7 : #include "oks/kernel.hpp" // for CanNotSetActiveFile exception
8 : #include "ui_SchemaFileInfo.h"
9 :
10 : #include <QBrush>
11 : #include <QColor>
12 : #include <QDialogButtonBox>
13 : #include <QFileDialog>
14 : #include <QMessageBox>
15 : #include <QPushButton>
16 : #include <QString>
17 :
18 : namespace dbse {
19 :
20 0 : SchemaFileInfo::SchemaFileInfo(std::string filename, QWidget* /*parent*/)
21 0 : : m_ui(new Ui::SchemaFileInfo)
22 0 : , m_filename(filename)
23 0 : , m_include_menu(nullptr)
24 0 : , m_class_menu(nullptr)
25 : {
26 :
27 0 : QWidget::setAttribute(Qt::WA_DeleteOnClose);
28 :
29 0 : m_ui->setupUi(this);
30 : // m_ui->buttonBox->setStandardButtons(QDialogButtonBox::Ok);
31 0 : m_ui->missing_button->hide();
32 : // m_ui->class_list->setDragEnabled ( true );
33 : // m_ui->class_list->setAcceptDrops ( true );
34 0 : setObjectName(QString::fromStdString(filename));
35 0 : auto sp = filename.find_last_of('/');
36 0 : if (sp == std::string::npos) {
37 : sp = 0;
38 : } else {
39 0 : sp++;
40 : }
41 0 : setWindowTitle(QString("Schema File: %1").arg(QString::fromStdString(filename.substr(sp))));
42 :
43 0 : m_ui->label->setText(QString::fromStdString(filename));
44 0 : if (!KernelWrapper::GetInstance().IsFileWritable(m_filename)) {
45 0 : QPalette pal;
46 0 : pal.setColor(QPalette::Active, QPalette::WindowText, SchemaStyle::get_color("foreground", "readonly"));
47 0 : m_ui->label->setPalette(pal);
48 : // m_ui->label->setStyleSheet("color:rgb(128,0,0);");
49 0 : }
50 0 : show_status();
51 :
52 0 : QString DUNEDAQ_DB_PATH = getenv("DUNEDAQ_DB_PATH");
53 0 : m_path_list = DUNEDAQ_DB_PATH.split(QLatin1Char(':'), Qt::SkipEmptyParts);
54 0 : for (QString& path : m_path_list) {
55 0 : if (!path.endsWith("/")) {
56 0 : path.append("/");
57 : }
58 0 : m_path_urls.append(QUrl::fromLocalFile(path));
59 : }
60 :
61 0 : get_includes();
62 :
63 0 : m_ui->textBrowser->hide();
64 :
65 0 : update_class_list();
66 :
67 0 : m_ui->include_list->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
68 0 : m_ui->class_list->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
69 0 : connect(m_ui->include_list, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(show_file_info(QListWidgetItem*)));
70 0 : connect(
71 0 : m_ui->include_list, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(activate_include_context_menu(QPoint)));
72 :
73 0 : if (KernelWrapper::GetInstance().IsFileWritable(m_filename)) {
74 0 : connect(m_ui->active_button, SIGNAL(pressed()), this, SLOT(set_active()));
75 0 : connect(m_ui->add_button, SIGNAL(pressed()), this, SLOT(add_include()));
76 0 : connect(m_ui->missing_button, SIGNAL(pressed()), this, SLOT(add_missing_includes()));
77 0 : connect(&KernelWrapper::GetInstance(), SIGNAL(ClassUpdated(QString)), this, SLOT(class_updated(QString)));
78 0 : connect(
79 0 : m_ui->class_list, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(activate_class_context_menu(QPoint)));
80 : } else {
81 0 : m_ui->add_button->setEnabled(false);
82 0 : m_ui->active_button->setEnabled(false);
83 0 : m_ui->save_button->setEnabled(false);
84 : }
85 0 : connect(m_ui->save_button, SIGNAL(pressed()), this, SLOT(save_schema()));
86 0 : connect(m_ui->close_button, SIGNAL(pressed()), this, SLOT(close()));
87 0 : connect(&KernelWrapper::GetInstance(), SIGNAL(active_updated()), this, SLOT(show_status()));
88 :
89 0 : connect(m_ui->class_list, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(launch_class_editor(QListWidgetItem*)));
90 0 : }
91 :
92 : void
93 0 : SchemaFileInfo::get_includes()
94 : {
95 0 : m_ui->include_list->clear();
96 0 : m_all_includes.clear();
97 0 : KernelWrapper::GetInstance().get_all_includes(m_filename, m_all_includes);
98 :
99 0 : std::set<std::string> direct_includes;
100 0 : KernelWrapper::GetInstance().get_direct_includes(m_filename, direct_includes);
101 :
102 0 : for (auto inc : m_all_includes) {
103 0 : auto file = prune_path(inc);
104 0 : auto item = new QListWidgetItem(QString::fromStdString(file));
105 0 : item->setToolTip(QString::fromStdString(inc));
106 0 : m_ui->include_list->addItem(item);
107 0 : if (!direct_includes.contains(file)) {
108 0 : item->setForeground(QBrush(SchemaStyle::get_color("foreground", "inherited")));
109 0 : } else if (!KernelWrapper::GetInstance().IsFileWritable(inc)) {
110 0 : item->setForeground(QBrush(SchemaStyle::get_color("foreground", "readonly")));
111 0 : item->setBackground(QBrush(SchemaStyle::get_color("background", "readonly")));
112 : } else {
113 0 : item->setForeground(QBrush(SchemaStyle::get_color("foreground", "default")));
114 0 : item->setBackground(QBrush(SchemaStyle::get_color("background", "default")));
115 : }
116 0 : }
117 0 : m_ui->include_list->update();
118 0 : }
119 :
120 : bool
121 0 : SchemaFileInfo::check_relationships(dunedaq::oks::OksClass* cls)
122 : {
123 0 : bool ok = true;
124 0 : auto relationships = cls->direct_relationships();
125 0 : if (relationships != nullptr) {
126 0 : for (auto rel : *relationships) {
127 0 : auto rel_class = rel->get_class_type();
128 0 : if (rel_class == nullptr) {
129 0 : QString warning = "<b>Warning</b> class <i>" + QString::fromStdString(cls->get_name()) +
130 0 : "</i> has relationship " + QString::fromStdString(rel->get_name()) +
131 0 : " referring to class <i>" + QString::fromStdString(rel->get_type()) +
132 0 : "</i> which is not loaded<br>";
133 0 : m_ui->textBrowser->insertHtml(warning);
134 0 : m_ui->textBrowser->show();
135 0 : ok = false;
136 0 : continue;
137 0 : }
138 0 : auto file = rel_class->get_file()->get_full_file_name();
139 0 : if (file != m_filename && !m_all_includes.contains(file)) {
140 0 : m_missing_includes.insert(file);
141 0 : QString warning = "<b>Warning</b> class <i>" + QString::fromStdString(cls->get_name()) +
142 0 : "</i> has relationship " + QString::fromStdString(rel->get_name()) +
143 0 : " referring to class <i>" + QString::fromStdString(rel->get_class_type()->get_name()) +
144 0 : "</i> from " + QString::fromStdString(file) + " which is not included<br>";
145 0 : m_ui->textBrowser->insertHtml(warning);
146 0 : m_ui->textBrowser->show();
147 0 : ok = false;
148 0 : }
149 0 : }
150 : }
151 0 : return ok;
152 : }
153 :
154 : bool
155 0 : SchemaFileInfo::check_superclasses(dunedaq::oks::OksClass* cls)
156 : {
157 0 : bool ok = true;
158 0 : auto super_classes = cls->direct_super_classes();
159 0 : if (super_classes != nullptr) {
160 0 : for (auto sc : *super_classes) {
161 0 : auto sclass = KernelWrapper::GetInstance().FindClass(*sc);
162 0 : if (sclass == nullptr) {
163 0 : QString warning = "<b>Warning</b> class <i>" + QString::fromStdString(cls->get_name()) +
164 0 : "</i> refers to super class <i>" + QString::fromStdString(*sc) +
165 0 : "</i> which is not known<br>";
166 0 : m_ui->textBrowser->insertHtml(warning);
167 0 : m_ui->textBrowser->show();
168 0 : ok = false;
169 0 : continue;
170 0 : }
171 0 : auto file = sclass->get_file()->get_full_file_name();
172 0 : if (file != m_filename && !m_all_includes.contains(file)) {
173 0 : m_missing_includes.insert(file);
174 0 : QString warning = "<b>Warning</b> class <i>" + QString::fromStdString(cls->get_name()) +
175 0 : "</i> refers to super class <i>" + QString::fromStdString(*sc) + "</i> from " +
176 0 : QString::fromStdString(file) + " which is not included<br>";
177 0 : m_ui->textBrowser->insertHtml(warning);
178 0 : m_ui->textBrowser->show();
179 0 : ok = false;
180 0 : }
181 0 : }
182 : }
183 0 : return ok;
184 : }
185 :
186 : void
187 0 : SchemaFileInfo::remove_include(std::string filename)
188 : {
189 0 : std::cout << "Removing include file " << filename << "\n";
190 :
191 0 : auto temp_files = m_all_includes;
192 0 : temp_files.erase(filename);
193 0 : temp_files.insert(m_filename);
194 :
195 0 : auto classes = KernelWrapper::GetInstance().get_schema_classes(m_filename);
196 0 : for (auto cls : classes) {
197 : // Ignore classes in file we're removing
198 0 : if (cls->get_file()->get_full_file_name() != filename) {
199 0 : auto relationships = cls->direct_relationships();
200 0 : if (relationships != nullptr) {
201 0 : for (auto rel : *relationships) {
202 0 : auto file = rel->get_class_type()->get_file()->get_full_file_name();
203 0 : if (!temp_files.contains(file)) {
204 0 : auto message = QString("Cannot remove %1 as class %2 has relationship to its %3 class")
205 0 : .arg(QString::fromStdString(filename))
206 0 : .arg(QString::fromStdString(cls->get_name()))
207 0 : .arg(QString::fromStdString(rel->get_class_type()->get_name()));
208 0 : QMessageBox::warning(0, "Schema editor", message);
209 0 : return;
210 0 : }
211 0 : }
212 : }
213 0 : auto super_classes = cls->direct_super_classes();
214 0 : if (super_classes != nullptr) {
215 0 : for (auto sc : *super_classes) {
216 0 : auto sclass = KernelWrapper::GetInstance().FindClass(*sc);
217 0 : auto file = sclass->get_file()->get_full_file_name();
218 0 : if (!temp_files.contains(file)) {
219 0 : auto message = QString("Cannot remove %1 as class %2 has superclass %3 in %1")
220 0 : .arg(QString::fromStdString(filename))
221 0 : .arg(QString::fromStdString(cls->get_name()))
222 0 : .arg(QString::fromStdString(*sc));
223 0 : QMessageBox::warning(0, "Schema editor", message);
224 0 : return;
225 0 : }
226 0 : }
227 : }
228 : }
229 : }
230 0 : try {
231 0 : dbse::KernelWrapper::GetInstance().RemoveInclude(m_filename, prune_path(filename));
232 0 : m_all_includes.erase(filename);
233 0 : } catch (dunedaq::oks::FailedRemoveInclude& exc) {
234 0 : QMessageBox::warning(0, "Schema editor", QString::fromStdString(exc.what()));
235 0 : }
236 :
237 0 : get_includes();
238 0 : update_class_list();
239 0 : show_status();
240 0 : }
241 :
242 : void
243 0 : dbse::SchemaFileInfo::remove_include()
244 : {
245 0 : auto item = m_ui->include_list->currentItem();
246 0 : std::string fn = item->text().toStdString();
247 0 : remove_include(fn);
248 0 : }
249 :
250 : void
251 0 : SchemaFileInfo::accept()
252 : {
253 0 : close();
254 0 : }
255 :
256 : void
257 0 : SchemaFileInfo::reject()
258 : {
259 0 : close();
260 0 : }
261 :
262 : void
263 0 : dbse::SchemaFileInfo::keyPressEvent(QKeyEvent* event)
264 : {
265 0 : if (event->key() == Qt::Key_Escape) {
266 0 : close();
267 : }
268 0 : QWidget::keyPressEvent(event);
269 0 : }
270 :
271 : void
272 0 : SchemaFileInfo::launch_class_editor(QListWidgetItem* item)
273 : {
274 0 : SchemaClassEditor::launch(item->text());
275 0 : }
276 :
277 : void
278 0 : SchemaFileInfo::update_class_list()
279 : {
280 0 : m_ui->class_list->clear();
281 0 : m_ui->textBrowser->clear();
282 0 : auto classes = KernelWrapper::GetInstance().get_schema_classes(m_filename);
283 0 : for (auto cls : classes) {
284 0 : auto item = new QListWidgetItem(QString::fromStdString(cls->get_name()));
285 :
286 0 : if (!KernelWrapper::GetInstance().IsFileWritable(m_filename)) {
287 0 : item->setForeground(QBrush(SchemaStyle::get_color("foreground", "readonly")));
288 0 : item->setBackground(QBrush(SchemaStyle::get_color("background", "readonly")));
289 : }
290 0 : if (!check_relationships(cls)) {
291 0 : item->setForeground(QBrush(SchemaStyle::get_color("foreground", "error")));
292 0 : item->setBackground(QBrush(SchemaStyle::get_color("background", "error")));
293 : }
294 0 : if (!check_superclasses(cls)) {
295 0 : item->setForeground(QBrush(SchemaStyle::get_color("foreground", "error")));
296 0 : item->setBackground(QBrush(SchemaStyle::get_color("background", "error")));
297 : }
298 :
299 0 : m_ui->class_list->addItem(item);
300 : }
301 0 : m_ui->class_summary->setText(QString("Total of %1 classes").arg(classes.size()));
302 :
303 : // if (!m_missing_includes.empty() && m_missing_button == nullptr) {
304 : // m_missing_button = m_ui->buttonBox->addButton("Add missing includes", QDialogButtonBox::ApplyRole);
305 : // if (m_missing_button != nullptr) {
306 : // connect ( m_missing_button, SIGNAL (pressed()), this, SLOT(add_missing_includes()));
307 : // }
308 : // else {
309 : // std::cout << "Failed to add button\n";
310 : // }
311 : // }
312 0 : if (m_missing_includes.empty()) {
313 0 : m_ui->missing_button->setEnabled(false);
314 0 : m_ui->missing_button->hide();
315 : } else {
316 0 : m_ui->missing_button->setEnabled(true);
317 0 : m_ui->missing_button->show();
318 : }
319 0 : }
320 :
321 : void
322 0 : SchemaFileInfo::class_updated(QString /*class_name*/)
323 : {
324 : // auto cls = KernelWrapper::GetInstance().FindClass(class_name.toStdString());
325 : // auto file = cls->get_file()->get_full_file_name();
326 : // if (file == m_filename) {
327 0 : show_status();
328 0 : update_class_list();
329 : // }
330 0 : }
331 :
332 : void
333 0 : SchemaFileInfo::save_schema()
334 : {
335 0 : try {
336 0 : KernelWrapper::GetInstance().SaveSchema(m_filename);
337 0 : } catch (const dunedaq::oks::exception& exc) {
338 0 : QMessageBox::warning(0,
339 : "Save Schema",
340 0 : QString("Failed to save file %1").arg(m_filename.c_str()).append(QString(exc.what())),
341 : QMessageBox::Ok);
342 0 : }
343 0 : show_status();
344 0 : emit files_updated();
345 0 : }
346 :
347 : void
348 0 : SchemaFileInfo::show_status()
349 : {
350 0 : QString status;
351 0 : if (KernelWrapper::GetInstance().IsFileWritable(m_filename)) {
352 0 : status.append("Read/Write");
353 : } else {
354 0 : status.append("Read only");
355 : }
356 0 : if (KernelWrapper::GetInstance().is_file_modified(m_filename)) {
357 0 : status.append(" Modified");
358 0 : if (m_missing_includes.empty()) {
359 0 : m_ui->save_button->setEnabled(true);
360 : } else {
361 0 : m_ui->save_button->setEnabled(false);
362 : }
363 : } else {
364 0 : m_ui->save_button->setEnabled(false);
365 : }
366 :
367 0 : if (m_filename == KernelWrapper::GetInstance().GetActiveSchema()) {
368 0 : status.append(" Active");
369 0 : m_ui->active_button->setEnabled(false);
370 0 : } else if (KernelWrapper::GetInstance().IsFileWritable(m_filename)) {
371 0 : m_ui->active_button->setEnabled(true);
372 : }
373 0 : m_ui->status->setText(status);
374 0 : }
375 :
376 : void
377 0 : SchemaFileInfo::add_include()
378 : {
379 0 : auto fd = new QFileDialog(this, tr("Open File"), ".", tr("XML schema files (*.schema.xml)"));
380 0 : fd->setFileMode(QFileDialog::ExistingFiles);
381 0 : fd->setViewMode(QFileDialog::Detail);
382 0 : fd->setAcceptMode(QFileDialog::AcceptOpen);
383 0 : fd->setSidebarUrls(m_path_urls);
384 0 : fd->exec();
385 0 : auto files = fd->selectedFiles();
386 0 : for (auto file : files) {
387 0 : add_file(file.toStdString());
388 0 : }
389 0 : get_includes();
390 0 : update_class_list();
391 0 : show_status();
392 0 : }
393 :
394 : void
395 0 : SchemaFileInfo::add_missing_includes()
396 : {
397 0 : std::cout << "\nAdding missing include files:\n";
398 :
399 0 : for (auto file : m_missing_includes) {
400 0 : add_file(file);
401 0 : }
402 0 : m_missing_includes.clear();
403 :
404 0 : get_includes();
405 0 : m_ui->textBrowser->clear();
406 0 : m_ui->textBrowser->hide();
407 :
408 0 : get_includes();
409 0 : update_class_list();
410 0 : show_status();
411 0 : }
412 :
413 : std::string
414 0 : SchemaFileInfo::prune_path(std::string file)
415 : {
416 0 : for (QString& element : m_path_list) {
417 0 : if (file.starts_with(element.toStdString())) {
418 0 : file = file.substr(element.size());
419 0 : break;
420 : }
421 : }
422 0 : return file;
423 : }
424 : void
425 0 : dbse::SchemaFileInfo::add_file(std::string file)
426 : {
427 0 : std::cout << " " << file << "\n";
428 0 : try {
429 0 : KernelWrapper::GetInstance().AddInclude(m_filename, prune_path(file));
430 0 : emit files_updated();
431 0 : } catch (std::exception& exc) {
432 0 : QString message =
433 0 : QString("Failed to add %1 to included files, %2").arg(QString::fromStdString(file)).arg(exc.what());
434 0 : QMessageBox::warning(0, "Schema editor", message);
435 0 : }
436 0 : }
437 :
438 : void
439 0 : dbse::SchemaFileInfo::activate_include_context_menu(QPoint pos)
440 : {
441 0 : if (m_include_menu == nullptr) {
442 0 : m_include_menu = new QMenu(this);
443 :
444 0 : if (KernelWrapper::GetInstance().IsFileWritable(m_filename)) {
445 0 : QAction* add = new QAction(tr("Add New Include File"), this);
446 0 : connect(add, SIGNAL(triggered()), this, SLOT(add_include()));
447 0 : QAction* remove = new QAction(tr("Remove Selected Include File"), this);
448 0 : connect(remove, SIGNAL(triggered()), this, SLOT(remove_include()));
449 0 : m_include_menu->addAction(add);
450 0 : m_include_menu->addAction(remove);
451 : }
452 0 : QAction* info = new QAction(tr("Show file info"), this);
453 0 : connect(info, SIGNAL(triggered()), this, SLOT(show_file_info()));
454 :
455 0 : m_include_menu->addAction(info);
456 : }
457 :
458 0 : if (m_ui->include_list->currentIndex().isValid()) {
459 0 : m_include_menu->exec(m_ui->include_list->mapToGlobal(pos));
460 : }
461 0 : }
462 :
463 : void
464 0 : dbse::SchemaFileInfo::activate_class_context_menu(QPoint pos)
465 : {
466 0 : if (m_class_menu == nullptr) {
467 0 : m_class_menu = new QMenu(this);
468 :
469 0 : QAction* add = new QAction(tr("&Add New Class"), this);
470 0 : connect(add, SIGNAL(triggered()), this, SLOT(add_new_class()));
471 :
472 0 : QAction* remove = new QAction(tr("&Remove Selected Class"), this);
473 0 : connect(remove, SIGNAL(triggered()), this, SLOT(remove_class()));
474 :
475 0 : QAction* edit = new QAction(tr("&Edit Selected Class"), this);
476 0 : connect(edit, SIGNAL(triggered()), this, SLOT(edit_class()));
477 :
478 0 : QAction* move = new QAction(tr("&Move Selected Class"), this);
479 0 : connect(move, SIGNAL(triggered()), this, SLOT(move_class()));
480 :
481 0 : m_class_menu->addAction(add);
482 0 : m_class_menu->addAction(edit);
483 0 : m_class_menu->addAction(move);
484 0 : m_class_menu->addAction(remove);
485 : }
486 :
487 0 : if (m_ui->class_list->currentIndex().isValid()) {
488 0 : m_class_menu->exec(m_ui->class_list->mapToGlobal(pos));
489 : }
490 0 : }
491 :
492 : void
493 0 : dbse::SchemaFileInfo::edit_class()
494 : {
495 0 : SchemaClassEditor::launch(m_ui->class_list->currentItem()->text());
496 0 : }
497 : void
498 0 : dbse::SchemaFileInfo::move_class()
499 : {
500 0 : auto oks_class = KernelWrapper::GetInstance().FindClass(m_ui->class_list->currentItem()->text().toStdString());
501 0 : SchemaClassEditor::move_class(oks_class, this);
502 0 : }
503 : void
504 0 : dbse::SchemaFileInfo::remove_class()
505 : {
506 0 : auto item = m_ui->class_list->currentItem();
507 0 : QString cn = item->text();
508 0 : dunedaq::oks::OksClass* schema_class = KernelWrapper::GetInstance().FindClass(cn.toStdString());
509 0 : if (schema_class->all_sub_classes()->size() != 0) {
510 0 : QMessageBox::warning(0, "Schema editor", QString("Cannot delete class because it has sub-classes."));
511 0 : return;
512 0 : } else if (KernelWrapper::GetInstance().AnyClassReferenceThis(schema_class)) {
513 0 : QMessageBox::warning(0, "Schema editor", QString("Cannot delete class because some other classes references it."));
514 0 : return;
515 : }
516 :
517 0 : KernelWrapper::GetInstance().PushRemoveClassCommand(
518 0 : schema_class, schema_class->get_name(), schema_class->get_description(), schema_class->get_is_abstract());
519 0 : delete item;
520 0 : m_ui->class_list->update();
521 0 : }
522 :
523 : bool
524 0 : dbse::SchemaFileInfo::set_active(std::string filename)
525 : {
526 0 : try {
527 0 : KernelWrapper::GetInstance().SetActiveSchema(filename);
528 0 : } catch (dunedaq::oks::CanNotSetActiveFile& exc) {
529 0 : auto qfn = QString::fromStdString(m_filename);
530 0 : auto text = QString("Could not make schema file %1 active!\n\n").arg(qfn);
531 0 : QMessageBox::warning(0, "Set Active Schema", text.append(QString(exc.what())), QMessageBox::Ok);
532 0 : return false;
533 0 : }
534 0 : show_status();
535 0 : return true;
536 : }
537 :
538 : void
539 0 : dbse::SchemaFileInfo::set_schemafile_active()
540 : {
541 0 : auto item = m_ui->include_list->currentItem();
542 0 : std::string fn = item->text().toStdString();
543 0 : set_active(fn);
544 0 : show_status();
545 0 : }
546 :
547 : void
548 0 : dbse::SchemaFileInfo::set_active()
549 : {
550 0 : set_active(m_filename);
551 0 : show_status();
552 0 : }
553 :
554 : void
555 0 : dbse::SchemaFileInfo::add_new_class()
556 : {
557 0 : if (set_active(m_filename)) {
558 0 : auto nc = SchemaClassEditor::createNewClass();
559 0 : if (!nc.isEmpty()) {
560 0 : auto item = new QListWidgetItem(nc);
561 0 : m_ui->class_list->addItem(item);
562 0 : m_ui->class_list->sortItems();
563 0 : m_ui->class_list->setCurrentItem(item);
564 0 : m_ui->class_list->update();
565 : }
566 0 : }
567 0 : }
568 :
569 : void
570 0 : dbse::SchemaFileInfo::show_file_info()
571 : {
572 0 : show_file_info(m_ui->include_list->currentItem());
573 0 : }
574 : void
575 0 : dbse::SchemaFileInfo::show_file_info(QListWidgetItem* item)
576 : {
577 0 : show_file_info(item->text());
578 0 : }
579 : void
580 0 : dbse::SchemaFileInfo::show_file_info(QString fn)
581 : {
582 0 : bool widget_found = false;
583 0 : for (QWidget* widget : QApplication::allWidgets()) {
584 0 : auto sfi = dynamic_cast<SchemaFileInfo*>(widget);
585 0 : if (sfi != nullptr) {
586 0 : if ((sfi->objectName()).compare(fn) == 0) {
587 0 : sfi->raise();
588 0 : sfi->setVisible(true);
589 0 : sfi->activateWindow();
590 : widget_found = true;
591 : break;
592 : }
593 : }
594 0 : }
595 0 : if (!widget_found) {
596 0 : auto info = new SchemaFileInfo(fn.toStdString());
597 : // connect (info, &SchemaFileInfo::files_updated,
598 : // this, &SchemaMainWindow::update_models);
599 0 : emit new_window(this);
600 0 : info->show();
601 : }
602 0 : }
603 : } // namespace dbse
|