7 #include "fwGuiQt/dialog/LoggerDialog.hpp" 9 #include <fwCore/base.hpp> 11 #include <fwGui/registry/macros.hpp> 13 #include <fwRuntime/operations.hpp> 15 #include <boost/foreach.hpp> 17 #include <QApplication> 19 #include <QHBoxLayout> 20 #include <QHeaderView> 22 #include <QPushButton> 23 #include <QTableWidgetItem> 24 #include <QVBoxLayout> 71 QWidget* parent = qApp->activeWindow();
74 QSizePolicy policy(QSizePolicy::Maximum, QSizePolicy::Preferred);
77 m_dialog =
new QDialog(parent);
78 m_dialog->resize(500, 50);
79 m_dialog->setWindowTitle(QString::fromStdString(m_title));
80 QVBoxLayout* mainLayout =
new QVBoxLayout();
81 mainLayout->setAlignment(Qt::AlignTop);
82 m_dialog->setLayout(mainLayout);
85 m_dialog->setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint| Qt::WindowSystemMenuHint);
88 QHBoxLayout* messageLayout =
new QHBoxLayout();
89 QWidget* messageWidget =
new QWidget();
90 messageWidget->setSizePolicy(policy);
91 messageWidget->setLayout(messageLayout);
92 messageLayout->setAlignment(Qt::AlignTop);
95 QLabel* iconLabel =
new QLabel();
96 if(m_logger->count(::fwLog::Log::CRITICAL) > 0)
98 const auto path = ::fwRuntime::getLibraryResourceFilePath(
"fwGuiQt-0.1/critical.png");
99 iconLabel->setPixmap(QIcon(QString::fromStdString(path.string())).pixmap(48, 48));
101 else if(m_logger->count(::fwLog::Log::WARNING) > 0)
103 const auto path = ::fwRuntime::getLibraryResourceFilePath(
"fwGuiQt-0.1/warning.png");
104 iconLabel->setPixmap(QIcon(QString::fromStdString(path.string())).pixmap(48, 48));
108 const auto path = ::fwRuntime::getLibraryResourceFilePath(
"fwGuiQt-0.1/information.png");
109 iconLabel->setPixmap(QIcon(QString::fromStdString(path.string())).pixmap(48, 48));
111 messageLayout->addWidget(iconLabel);
114 std::stringstream ss;
116 "<br><br>" <<
"<b>Log report :</b> " << m_logger->count(::fwLog::Log::CRITICAL) <<
" critical, " <<
117 m_logger->count(::fwLog::Log::WARNING) <<
" warning and " <<
118 m_logger->count(::fwLog::Log::INFORMATION) <<
" information messages.";
120 QLabel* messageLabel =
new QLabel(ss.str().c_str());
121 messageLayout->addWidget(messageLabel);
124 QHBoxLayout* buttonLayout =
new QHBoxLayout();
125 QWidget* buttonWidget =
new QWidget();
126 buttonWidget->setSizePolicy(policy);
127 buttonWidget->setLayout(buttonLayout);
130 QPushButton* okButton =
new QPushButton(tr(
"Ok"));
131 okButton->setSizePolicy(policy);
132 buttonLayout->addWidget(okButton);
135 QPushButton* cancelButton =
new QPushButton(tr(
"Cancel"));
136 cancelButton->setSizePolicy(policy);
137 buttonLayout->addWidget(cancelButton);
140 QCheckBox* checkbox =
new QCheckBox(
"Details");
141 const auto detailshidden = ::fwRuntime::getLibraryResourceFilePath(
"fwGuiQt-0.1/details-hidden.png").string();
142 const auto detailsshown = ::fwRuntime::getLibraryResourceFilePath(
"fwGuiQt-0.1/details-shown.png").string();
143 std::string styleSheet;
144 styleSheet +=
"QCheckBox::indicator:unchecked { image: url(" + detailshidden +
"); }";
145 styleSheet +=
"QCheckBox::indicator:checked { image: url(" + detailsshown +
"); }";
146 checkbox->setStyleSheet(QString::fromStdString(styleSheet));
149 m_logTableWidget =
new QTableWidget(static_cast<int>(m_logger->count()), 2);
150 m_logTableWidget->setHorizontalHeaderItem(0,
new QTableWidgetItem(
"Level"));
151 m_logTableWidget->setHorizontalHeaderItem(1,
new QTableWidgetItem(
"Message"));
152 m_logTableWidget->setColumnWidth(0, 120);
153 m_logTableWidget->horizontalHeader()->setStretchLastSection(
true);
156 ::fwLog::Logger::ConstIteratorType it = m_logger->begin();
158 for(; it != m_logger->end(); ++it, ++row)
160 std::string levelString =
"Unknown";
162 ::fwLog::Log::LevelType level = it->getLevel();
163 if (level == ::fwLog::Log::INFORMATION)
165 levelString =
"Information";
166 const auto path = ::fwRuntime::getLibraryResourceFilePath(
"fwGuiQt-0.1/information.png");
167 levelIcon = QIcon(QString::fromStdString(path.string()));
169 else if (level == ::fwLog::Log::WARNING)
171 levelString =
"Warning";
172 const auto path = ::fwRuntime::getLibraryResourceFilePath(
"fwGuiQt-0.1/warning.png");
173 levelIcon = QIcon(QString::fromStdString(path.string()));
175 else if (level == ::fwLog::Log::CRITICAL)
177 levelString =
"Critical";
178 const auto path = ::fwRuntime::getLibraryResourceFilePath(
"fwGuiQt-0.1/critical.png");
179 levelIcon = QIcon(QString::fromStdString(path.string()));
182 QTableWidgetItem* levelItem =
new QTableWidgetItem(levelIcon, levelString.c_str());
183 levelItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
184 m_logTableWidget->setItem(row, 0, levelItem);
186 QTableWidgetItem* messageItem =
new QTableWidgetItem(it->getMessage().c_str());
187 messageItem->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled);
188 m_logTableWidget->setItem(row, 1, messageItem);
192 mainLayout->addWidget(messageWidget, 0, Qt::AlignLeft);
193 mainLayout->addWidget(checkbox);
194 mainLayout->addWidget(m_logTableWidget);
195 mainLayout->addWidget(buttonWidget, 0, Qt::AlignRight);
198 m_logTableWidget->hide();
201 QObject::connect(okButton, SIGNAL(clicked()), m_dialog, SLOT(accept()));
202 QObject::connect(cancelButton, SIGNAL(clicked()), m_dialog, SLOT(reject()));
203 QObject::connect(checkbox, SIGNAL(stateChanged(
int)),
this, SLOT(
displayLogs(
int)));
206 bool result = m_dialog->exec();
209 QObject::disconnect(checkbox, SIGNAL(stateChanged(
int)),
this, SLOT(
displayLogs(
int)));
218 int width = m_dialog->size().width();
222 m_logTableWidget->show();
226 m_logTableWidget->hide();
229 m_dialog->adjustSize();
230 m_dialog->resize(width, m_dialog->baseSize().height());
FWGUIQT_API LoggerDialog(::fwGui::GuiBaseObject::Key key)
Constructor.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
virtual FWGUIQT_API bool show() override
Show the dialog and return whether the user has selected the Ok or Cancel button. ...
The namespace fwGuiQt contains classes which provide the implementation of the Gui using Qt library...
void displayLogs(int state)
Slot called when the user wants to display the logs.
virtual FWGUIQT_API ~LoggerDialog()
Destructor.
LoggerDialog allowing the choice of an element among severals (_selections)
static FWGUI_API const FactoryRegistryKeyType REGISTRY_KEY
This unique key should be used for all factory for specific Selector(qt,wx,...)
virtual FWGUIQT_API void setMessage(const std::string &message) override
Set the dialog message.
virtual FWGUIQT_API void setTitle(const std::string &title) override
Set the dialog title.
virtual FWGUIQT_API void setLogger(const ::fwLog::Logger::sptr &logger) override
Set the dialog logger.