ctkCmdLineModuleExplorerShowXmlAction.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #include "ctkCmdLineModuleExplorerShowXmlAction.h"
  16. #include "ctkCmdLineModuleDescription.h"
  17. #include "ctkCmdLineModuleXmlException.h"
  18. #include <QDialog>
  19. #include <QVBoxLayout>
  20. #include <QHBoxLayout>
  21. #include <QPushButton>
  22. #include <QSpacerItem>
  23. #include <QTextEdit>
  24. #include <QUrl>
  25. #include <QLabel>
  26. ctkCmdLineModuleExplorerShowXmlAction::ctkCmdLineModuleExplorerShowXmlAction(QObject *parent)
  27. : QAction(parent)
  28. {
  29. this->setText("Show XML Description");
  30. connect(this, SIGNAL(triggered()), SLOT(run()));
  31. }
  32. void ctkCmdLineModuleExplorerShowXmlAction::setModuleReference(const ctkCmdLineModuleReference& ref)
  33. {
  34. this->ModuleRef = ref;
  35. }
  36. void ctkCmdLineModuleExplorerShowXmlAction::run()
  37. {
  38. QDialog* dialog = new QDialog();
  39. try
  40. {
  41. dialog->setWindowTitle(this->ModuleRef.description().title());
  42. }
  43. catch (const ctkCmdLineModuleXmlException&)
  44. {
  45. dialog->setWindowTitle(this->ModuleRef.location().toString());
  46. }
  47. dialog->setLayout(new QVBoxLayout());
  48. QHBoxLayout* buttonLayout = new QHBoxLayout();
  49. buttonLayout->addStretch(1);
  50. QPushButton* closeButton = new QPushButton(tr("Close"), dialog);
  51. buttonLayout->addWidget(closeButton);
  52. QTextEdit* textEdit = new QTextEdit(dialog);
  53. textEdit->setPlainText(this->ModuleRef.rawXmlDescription().data());
  54. QLabel* statusLabel = new QLabel(dialog);
  55. statusLabel->setWordWrap(true);
  56. if (this->ModuleRef.xmlValidationErrorString().isEmpty())
  57. {
  58. statusLabel->setText(tr("No validation errors."));
  59. }
  60. else
  61. {
  62. statusLabel->setText(this->ModuleRef.xmlValidationErrorString());
  63. }
  64. dialog->layout()->addWidget(statusLabel);
  65. dialog->layout()->addWidget(textEdit);
  66. dialog->layout()->addItem(buttonLayout);
  67. connect(closeButton, SIGNAL(clicked()), dialog, SLOT(close()));
  68. dialog->resize(800, 600);
  69. dialog->show();
  70. }