33 #include <config-kleopatra.h>
37 #include "ui_selftestdialog.h"
43 #include <QAbstractTableModel>
44 #include <QHeaderView>
45 #include <QSortFilterProxyModel>
47 #include <boost/shared_ptr.hpp>
53 using namespace Kleo::Dialogs;
54 using namespace boost;
61 explicit Model( QObject * parent=0 )
76 const unsigned int row = idx.row();
77 if ( row < m_tests.size() )
83 int rowCount(
const QModelIndex & idx )
const {
return idx.isValid() ? 0 : m_tests.size() ; }
84 int columnCount(
const QModelIndex & )
const {
return NumColumns; }
86 QVariant data(
const QModelIndex & idx,
int role )
const {
87 const unsigned int row = idx.row();
88 if ( idx.isValid() && row < m_tests.size() )
92 switch ( idx.column() ) {
94 return m_tests[row]->name();
97 m_tests[row]->skipped() ? i18n(
"Skipped") :
98 m_tests[row]->passed() ? i18n(
"Passed") :
99 m_tests[row]->shortError();
102 case Qt::BackgroundRole:
103 return QColor( m_tests[row]->skipped() ? Qt::yellow :
104 m_tests[row]->passed() ? Qt::green :
110 QVariant headerData(
int section, Qt::Orientation o,
int role )
const {
111 if ( o == Qt::Horizontal &&
112 section >= 0 && section < NumColumns &&
113 role == Qt::DisplayRole )
115 case TestName:
return i18n(
"Test Name");
116 case TestResult:
return i18n(
"Result");
122 if ( m_tests.empty() )
124 beginRemoveRows( QModelIndex(), 0, m_tests.size() - 1 );
132 beginInsertRows( QModelIndex(), m_tests.size(), m_tests.size() + tests.size() );
133 m_tests.insert( m_tests.end(), tests.begin(), tests.end() );
138 if ( !m_tests.empty() )
139 emit dataChanged( index( 0, 0 ), index( m_tests.size() - 1, NumColumns - 1 ) );
143 return m_tests.at( idx );
147 std::vector< shared_ptr<SelfTest> > m_tests;
153 explicit Proxy( QObject * parent=0 )
156 setDynamicSortFilter(
true );
159 bool showAll()
const {
return m_showAll; }
162 void showAllChanged(
bool );
165 void setShowAll(
bool on ) {
166 if ( on == m_showAll )
170 emit showAllChanged( on );
174 bool filterAcceptsRow(
int src_row,
const QModelIndex & src_parent )
const
179 if (
const Model *
const model = qobject_cast<Model*>( sourceModel() ) ) {
180 if ( !src_parent.isValid() && src_row >= 0 &&
181 src_row < model->rowCount( src_parent ) ) {
183 return !t->passed() ;
185 kWarning() <<
"NULL test??";
188 if ( src_parent.isValid() ) {
189 kWarning() <<
"view asks for subitems!";
191 kWarning() <<
"index " << src_row
192 <<
" is out of range [" << 0
193 <<
"," << model->rowCount( src_parent )
198 kWarning() <<
"expected a ::Model, got ";
199 if ( !sourceModel() ) {
200 kWarning() <<
"a null pointer";
202 kWarning() << sourceModel()->metaObject()->className();
215 class SelfTestDialog::Private {
216 friend class ::Kleo::Dialogs::SelfTestDialog;
225 proxy.setSourceModel( &model );
226 ui.resultsTV->setModel( &proxy );
228 ui.detailsGB->hide();
229 ui.proposedCorrectiveActionGB->hide();
231 connect( ui.resultsTV->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
232 q, SLOT(slotSelectionChanged()) );
233 connect( ui.showAllCB, SIGNAL(toggled(
bool)),
234 &proxy, SLOT(setShowAll(
bool)) );
238 void slotSelectionChanged() {
239 const int row = selectedRowIndex();
241 ui.detailsLB->setText( i18n(
"(select test first)") );
242 ui.detailsGB->hide();
243 ui.proposedCorrectiveActionGB->hide();
246 ui.detailsLB->setText( t->longError() );
247 ui.detailsGB->setVisible( !t->passed() );
248 const QString action = t->proposedFix();
249 ui.proposedCorrectiveActionGB->setVisible( !t->passed() && !action.isEmpty() );
250 ui.proposedCorrectiveActionLB->setText( action );
251 ui.doItPB->setVisible( !t->passed() && t->canFixAutomatically() );
254 void slotDoItClicked() {
261 void updateColumnSizes() {
262 ui.resultsTV->header()->resizeSections( QHeaderView::ResizeToContents );
266 QModelIndex selectedRow()
const {
267 const QItemSelectionModel *
const ism = ui.resultsTV->selectionModel();
269 return QModelIndex();
270 const QModelIndexList mil = ism->selectedRows();
271 return mil.empty() ? QModelIndex() : proxy.mapToSource( mil.front() ) ;
273 int selectedRowIndex()
const {
274 return selectedRow().row();
281 struct UI :
public Ui_SelfTestDialog {
283 QPushButton * rerunPB;
286 : Ui_SelfTestDialog(),
287 rerunPB( new QPushButton( i18n(
"Rerun Tests") ) )
291 buttonBox->addButton( rerunPB, QDialogButtonBox::ActionRole );
294 connect( rerunPB, SIGNAL(clicked()),
295 qq, SIGNAL(updateRequested()) );
301 :
QDialog( p, f ),
d( new Private( this ) )
307 :
QDialog( p, f ),
d( new Private( this ) )
321 d->updateColumnSizes();
325 d->model.append( tests );
326 d->updateColumnSizes();
330 d->ui.runAtStartUpCB->setChecked( on );
334 return d->ui.runAtStartUpCB->isChecked();
339 d->ui.buttonBox->button( QDialogButtonBox::Cancel )->setVisible( automatic );
340 d->ui.buttonBox->button( QDialogButtonBox::Close )->setVisible( !automatic );
343 #include "selftestdialog.moc"
344 #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)
void addSelfTests(const std::vector< boost::shared_ptr< SelfTest > > &tests)
void setRunAtStartUp(bool run)