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