| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 | 
							- /*=========================================================================
 
-   Library:   CTK
 
-   Copyright (c) Kitware Inc.
 
-   Licensed under the Apache License, Version 2.0 (the "License");
 
-   you may not use this file except in compliance with the License.
 
-   You may obtain a copy of the License at
 
-       http://www.apache.org/licenses/LICENSE-2.0.txt
 
-   Unless required by applicable law or agreed to in writing, software
 
-   distributed under the License is distributed on an "AS IS" BASIS,
 
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
-   See the License for the specific language governing permissions and
 
-   limitations under the License.
 
- =========================================================================*/
 
- // Qt includes
 
- #include <QDebug>
 
- #include <QAbstractItemModel>
 
- #include <QStandardItemModel>
 
- // CTK includes
 
- #include "ctkErrorLogWidget.h"
 
- #include "ui_ctkErrorLogWidget.h"
 
- #include <ctkErrorLogModel.h>
 
- class ctkErrorLogWidgetPrivate : public Ui_ctkErrorLogWidget
 
- {
 
-   Q_DECLARE_PUBLIC(ctkErrorLogWidget);
 
- protected:
 
-   ctkErrorLogWidget* const q_ptr;
 
- public:
 
-   typedef ctkErrorLogWidgetPrivate Self;
 
-   ctkErrorLogWidgetPrivate(ctkErrorLogWidget& object);
 
-   ctkErrorLogLevel::LogLevels ErrorButtonFilter;
 
-   ctkErrorLogLevel::LogLevels WarningButtonFilter;
 
-   ctkErrorLogLevel::LogLevels InfoButtonFilter;
 
-   void init();
 
-   QSharedPointer<QItemSelectionModel> SelectionModel;
 
- };
 
- // --------------------------------------------------------------------------
 
- // ctkErrorLogWidgetPrivate methods
 
- // --------------------------------------------------------------------------
 
- ctkErrorLogWidgetPrivate::ctkErrorLogWidgetPrivate(ctkErrorLogWidget& object)
 
-   : q_ptr(&object)
 
- {
 
-   this->ErrorButtonFilter = ctkErrorLogLevel::Error | ctkErrorLogLevel::Critical | ctkErrorLogLevel::Fatal;
 
-   this->WarningButtonFilter = ctkErrorLogLevel::Warning;
 
-   this->InfoButtonFilter = ctkErrorLogLevel::Info | ctkErrorLogLevel::Debug | ctkErrorLogLevel::Trace | ctkErrorLogLevel::Status;
 
- }
 
- // --------------------------------------------------------------------------
 
- void ctkErrorLogWidgetPrivate::init()
 
- {
 
-   Q_Q(ctkErrorLogWidget);
 
-   // this->ShowAllEntryButton->setIcon();
 
-   this->ShowErrorEntryButton->setIcon(q->style()->standardIcon(QStyle::SP_MessageBoxCritical));
 
-   this->ShowWarningEntryButton->setIcon(q->style()->standardIcon(QStyle::SP_MessageBoxWarning));
 
-   this->ShowInfoEntryButton->setIcon(q->style()->standardIcon(QStyle::SP_MessageBoxInformation));
 
-   this->ClearButton->setIcon(q->style()->standardIcon(QStyle::SP_DialogDiscardButton));
 
-   QObject::connect(this->ShowAllEntryButton, SIGNAL(clicked()),
 
-                    q, SLOT(setAllEntriesVisible()));
 
-   QObject::connect(this->ShowErrorEntryButton, SIGNAL(clicked(bool)),
 
-                    q, SLOT(setErrorEntriesVisible(bool)));
 
-   QObject::connect(this->ShowWarningEntryButton, SIGNAL(clicked(bool)),
 
-                    q, SLOT(setWarningEntriesVisible(bool)));
 
-   QObject::connect(this->ShowInfoEntryButton, SIGNAL(clicked(bool)),
 
-                    q, SLOT(setInfoEntriesVisible(bool)));
 
-   QObject::connect(this->ClearButton, SIGNAL(clicked()),
 
-                    q, SLOT(removeEntries()));
 
-   this->ErrorLogTableView->setColumnHidden(ctkErrorLogModel::ThreadIdColumn, true);
 
- }
 
- // --------------------------------------------------------------------------
 
- // ctkErrorLogWidget methods
 
- //------------------------------------------------------------------------------
 
- ctkErrorLogWidget::ctkErrorLogWidget(QWidget * newParent)
 
-   : Superclass(newParent)
 
-   , d_ptr(new ctkErrorLogWidgetPrivate(*this))
 
- {
 
-   Q_D(ctkErrorLogWidget);
 
-   d->setupUi(this);
 
-   d->init();
 
-   this->setErrorLogModel(new ctkErrorLogModel(d->ErrorLogTableView));
 
- }
 
- //------------------------------------------------------------------------------
 
- ctkErrorLogWidget::~ctkErrorLogWidget()
 
- {
 
- }
 
- //------------------------------------------------------------------------------
 
- ctkErrorLogModel* ctkErrorLogWidget::errorLogModel()const
 
- {
 
-   Q_D(const ctkErrorLogWidget);
 
-   QAbstractItemModel* model = d->ErrorLogTableView->model();
 
-   ctkErrorLogModel * errorLogModel = qobject_cast<ctkErrorLogModel*>(model);
 
-   Q_ASSERT(model ? errorLogModel != 0 : true);
 
-   return errorLogModel;
 
- }
 
- //------------------------------------------------------------------------------
 
- void ctkErrorLogWidget::setErrorLogModel(ctkErrorLogModel * newErrorLogModel)
 
- {
 
-   Q_D(ctkErrorLogWidget);
 
-   if (newErrorLogModel == this->errorLogModel())
 
-     {
 
-     return;
 
-     }
 
-   if (this->errorLogModel())
 
-     {
 
-     disconnect(this->errorLogModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
 
-                this, SLOT(onRowsInserted(QModelIndex,int,int)));
 
-     disconnect(this->errorLogModel(), SIGNAL(logLevelFilterChanged()),
 
-                this, SLOT(onLogLevelFilterChanged()));
 
-     disconnect(d->SelectionModel.data(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
 
-                this, SLOT(onSelectionChanged(QItemSelection,QItemSelection)));
 
-     d->SelectionModel.clear();
 
-     }
 
-   d->ErrorLogTableView->setModel(newErrorLogModel);
 
-   if (newErrorLogModel)
 
-     {
 
-     connect(this->errorLogModel(), SIGNAL(rowsInserted(QModelIndex,int,int)),
 
-             this, SLOT(onRowsInserted(QModelIndex,int,int)));
 
-     connect(this->errorLogModel(), SIGNAL(logLevelFilterChanged()),
 
-             this, SLOT(onLogLevelFilterChanged()));
 
-     ctkErrorLogLevel::LogLevels logLevelFilter = newErrorLogModel->logLevelFilter();
 
-     this->setErrorEntriesVisible(logLevelFilter & d->ErrorButtonFilter);
 
-     this->setWarningEntriesVisible(logLevelFilter & d->WarningButtonFilter);
 
-     this->setInfoEntriesVisible(logLevelFilter & d->InfoButtonFilter);
 
-     this->errorLogModel()->filterEntry(logLevelFilter & ctkErrorLogLevel::Unknown);
 
-     // Setup selection model
 
-     d->SelectionModel = QSharedPointer<QItemSelectionModel>(new QItemSelectionModel(this->errorLogModel()));
 
-     d->SelectionModel->reset();
 
-     connect(d->SelectionModel.data(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
 
-             this, SLOT(onSelectionChanged(QItemSelection,QItemSelection)));
 
-     d->ErrorLogTableView->setSelectionModel(d->SelectionModel.data());
 
-     // Resize time column only if there are rows
 
-     if (this->errorLogModel()->rowCount() > 0)
 
-       {
 
-       d->ErrorLogTableView->resizeColumnToContents(ctkErrorLogModel::TimeColumn);
 
-       }
 
-     }
 
-   else
 
-     {
 
-     this->setAllEntriesVisible(0);
 
-     }
 
- }
 
- // --------------------------------------------------------------------------
 
- void ctkErrorLogWidget::setAllEntriesVisible(bool visibility)
 
- {
 
-   this->setErrorEntriesVisible(visibility);
 
-   this->setWarningEntriesVisible(visibility);
 
-   this->setInfoEntriesVisible(visibility);
 
-   this->setUnknownEntriesVisible(visibility);
 
- }
 
- // --------------------------------------------------------------------------
 
- void ctkErrorLogWidget::setErrorEntriesVisible(bool visibility)
 
- {
 
-   Q_D(ctkErrorLogWidget);
 
-   if (!this->errorLogModel())
 
-     {
 
-     return;
 
-     }
 
-   this->errorLogModel()->filterEntry(d->ErrorButtonFilter, /* disableFilter= */ !visibility);
 
- }
 
- // --------------------------------------------------------------------------
 
- void ctkErrorLogWidget::setWarningEntriesVisible(bool visibility)
 
- {
 
-   Q_D(ctkErrorLogWidget);
 
-   if (!this->errorLogModel())
 
-     {
 
-     return;
 
-     }
 
-   this->errorLogModel()->filterEntry(d->WarningButtonFilter, /* disableFilter= */ !visibility);
 
- }
 
- // --------------------------------------------------------------------------
 
- void ctkErrorLogWidget::setInfoEntriesVisible(bool visibility)
 
- {
 
-   Q_D(ctkErrorLogWidget);
 
-   if (!this->errorLogModel())
 
-     {
 
-     return;
 
-     }
 
-   this->errorLogModel()->filterEntry(d->InfoButtonFilter, /* disableFilter= */ !visibility);
 
- }
 
- // --------------------------------------------------------------------------
 
- void ctkErrorLogWidget::setUnknownEntriesVisible(bool visibility)
 
- {
 
-   if (!this->errorLogModel())
 
-     {
 
-     return;
 
-     }
 
-   this->errorLogModel()->filterEntry(ctkErrorLogLevel::Unknown,
 
-       /* disableFilter= */ !visibility);
 
- }
 
- // --------------------------------------------------------------------------
 
- void ctkErrorLogWidget::onRowsInserted(const QModelIndex &/*parent*/, int /*first*/, int /*last*/)
 
- {
 
-   Q_D(ctkErrorLogWidget);
 
-   if (d->ErrorLogTableView->model()->rowCount() == 1)
 
-     {
 
-     // For performance reason, resize first column only when first entry is added
 
-     d->ErrorLogTableView->resizeColumnToContents(ctkErrorLogModel::TimeColumn);
 
-     }
 
- }
 
- // --------------------------------------------------------------------------
 
- void ctkErrorLogWidget::onLogLevelFilterChanged()
 
- {
 
-   Q_D(ctkErrorLogWidget);
 
-   Q_ASSERT(this->errorLogModel());
 
-   ctkErrorLogLevel::LogLevels logLevelFilter = this->errorLogModel()->logLevelFilter();
 
-   d->ShowErrorEntryButton->setChecked(logLevelFilter & d->ErrorButtonFilter);
 
-   d->ShowWarningEntryButton->setChecked(logLevelFilter & d->WarningButtonFilter);
 
-   d->ShowInfoEntryButton->setChecked(logLevelFilter & d->InfoButtonFilter);
 
- }
 
- // --------------------------------------------------------------------------
 
- void ctkErrorLogWidget::removeEntries()
 
- {
 
-   Q_ASSERT(this->errorLogModel());
 
-   this->errorLogModel()->clear();
 
- }
 
- // --------------------------------------------------------------------------
 
- void ctkErrorLogWidget::onSelectionChanged(const QItemSelection & selected,
 
-                                            const QItemSelection & deselected)
 
- {
 
-   // QTime start = QTime::currentTime();
 
-   Q_D(ctkErrorLogWidget);
 
-   Q_UNUSED(selected);
 
-   Q_UNUSED(deselected);
 
-   QModelIndexList selectedRows =
 
-       d->SelectionModel->selectedRows(ctkErrorLogModel::DescriptionColumn);
 
-   qSort(selectedRows.begin(), selectedRows.end());
 
-   QStringList descriptions;
 
-   foreach(const QModelIndex& index, selectedRows)
 
-     {
 
-     descriptions << index.data(ctkErrorLogModel::DescriptionTextRole).toString();
 
-     }
 
-   d->ErrorLogDescription->setText(descriptions.join("\n"));
 
-   // fprintf(stdout, "onSelectionChanged: %d\n", start.msecsTo(QTime::currentTime()));
 
- }
 
 
  |