33 #include <config-kleopatra.h>
37 #include "ui_selftestdialog.h"
43 #include <QAbstractTableModel>
44 #include <QHeaderView>
45 #include <QSortFilterProxyModel>
48 #include <boost/shared_ptr.hpp>
55 using namespace Kleo::Dialogs;
56 using namespace boost;
63 explicit Model(
QObject * parent=0 )
78 const unsigned int row = idx.
row();
79 if ( row < m_tests.size() )
85 int rowCount(
const QModelIndex & idx )
const {
return idx.
isValid() ? 0 : m_tests.size() ; }
86 int columnCount(
const QModelIndex & )
const {
return NumColumns; }
89 const unsigned int row = idx.
row();
90 if ( idx.
isValid() && row < m_tests.size() )
96 return m_tests[row]->name();
99 m_tests[row]->skipped() ? i18n(
"Skipped") :
100 m_tests[row]->passed() ? i18n(
"Passed") :
101 m_tests[row]->shortError();
104 case Qt::BackgroundRole:
105 return QColor( m_tests[row]->skipped() ? Qt::yellow :
106 m_tests[row]->passed() ? Qt::green :
112 QVariant headerData(
int section, Qt::Orientation o,
int role )
const {
113 if ( o == Qt::Horizontal &&
114 section >= 0 && section < NumColumns &&
115 role == Qt::DisplayRole )
117 case TestName:
return i18n(
"Test Name");
118 case TestResult:
return i18n(
"Result");
124 if ( m_tests.empty() )
126 beginRemoveRows(
QModelIndex(), 0, m_tests.size() - 1 );
134 beginInsertRows(
QModelIndex(), m_tests.size(), m_tests.size() + tests.size() );
135 m_tests.insert( m_tests.end(), tests.begin(), tests.end() );
140 if ( !m_tests.empty() )
141 emit dataChanged( index( 0, 0 ), index( m_tests.size() - 1, NumColumns - 1 ) );
145 return m_tests.at( idx );
149 std::vector< shared_ptr<SelfTest> > m_tests;
155 explicit Proxy(
QObject * parent=0 )
158 setDynamicSortFilter(
true );
161 bool showAll()
const {
return m_showAll; }
164 void showAllChanged(
bool );
167 void setShowAll(
bool on ) {
168 if ( on == m_showAll )
172 emit showAllChanged( on );
176 bool filterAcceptsRow(
int src_row,
const QModelIndex & src_parent )
const
181 if (
const Model *
const model = qobject_cast<Model*>( sourceModel() ) ) {
182 if ( !src_parent.
isValid() && src_row >= 0 &&
183 src_row < model->rowCount( src_parent ) ) {
185 return !t->passed() ;
187 kWarning() <<
"NULL test??";
191 kWarning() <<
"view asks for subitems!";
193 kWarning() <<
"index " << src_row
194 <<
" is out of range [" << 0
195 <<
"," << model->rowCount( src_parent )
200 kWarning() <<
"expected a ::Model, got ";
201 if ( !sourceModel() ) {
202 kWarning() <<
"a null pointer";
204 kWarning() << sourceModel()->metaObject()->className();
217 class SelfTestDialog::Private {
218 friend class ::Kleo::Dialogs::SelfTestDialog;
227 proxy.setSourceModel( &model );
228 ui.resultsTV->setModel( &proxy );
230 ui.detailsGB->hide();
231 ui.proposedCorrectiveActionGB->hide();
234 q, SLOT(slotSelectionChanged()) );
235 connect( ui.showAllCB, SIGNAL(toggled(
bool)),
236 &proxy, SLOT(setShowAll(
bool)) );
240 void slotSelectionChanged() {
241 const int row = selectedRowIndex();
243 ui.detailsLB->setText( i18n(
"(select test first)") );
244 ui.detailsGB->hide();
245 ui.proposedCorrectiveActionGB->hide();
248 ui.detailsLB->setText( t->longError() );
249 ui.detailsGB->setVisible( !t->passed() );
250 const QString action = t->proposedFix();
251 ui.proposedCorrectiveActionGB->setVisible( !t->passed() && !action.
isEmpty() );
252 ui.proposedCorrectiveActionLB->setText( action );
253 ui.doItPB->setVisible( !t->passed() && t->canFixAutomatically() );
256 void slotDoItClicked() {
263 void updateColumnSizes() {
264 ui.resultsTV->header()->resizeSections( QHeaderView::ResizeToContents );
273 return mil.empty() ?
QModelIndex() : proxy.mapToSource( mil.front() ) ;
275 int selectedRowIndex()
const {
276 return selectedRow().row();
283 struct UI :
public Ui_SelfTestDialog {
288 : Ui_SelfTestDialog(),
293 buttonBox->addButton( rerunPB, QDialogButtonBox::ActionRole );
296 connect( rerunPB, SIGNAL(clicked()),
297 qq, SIGNAL(updateRequested()) );
303 :
QDialog( p, f ),
d( new Private( this ) )
309 :
QDialog( p, f ),
d( new Private( this ) )
323 d->updateColumnSizes();
327 d->model.append( tests );
328 d->updateColumnSizes();
332 d->ui.runAtStartUpCB->setChecked( on );
336 return d->ui.runAtStartUpCB->isChecked();
341 d->ui.buttonBox->button( QDialogButtonBox::Cancel )->setVisible( automatic );
342 d->ui.buttonBox->button( QDialogButtonBox::Close )->setVisible( !automatic );
345 #include "selftestdialog.moc"
346 #include "moc_selftestdialog.cpp"
bool runAtStartUp() const
SelfTestDialog(QWidget *parent=0, Qt::WindowFlags f=0)
void setAutomaticMode(bool automatic)
void addSelfTest(const boost::shared_ptr< SelfTest > &test)
QModelIndexList selectedRows(int column) const
void addSelfTests(const std::vector< boost::shared_ptr< SelfTest > > &tests)
void setRunAtStartUp(bool run)