tests/auto/xmlpatternsview/view/TestCaseView.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the test suite of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include <QDate>
       
    43 #include <QtDebug>
       
    44 
       
    45 #include "UserTestCase.h"
       
    46 #include "ui_ui_BaseLinePage.h"
       
    47 
       
    48 #include "TestCaseView.h"
       
    49 
       
    50 using namespace QPatternistSDK;
       
    51 
       
    52 /**
       
    53  * Removes all tabs in @p widget, and deletes its page widgets.
       
    54  */
       
    55 static void clearTabWidget(QTabWidget *const widget)
       
    56 {
       
    57     Q_ASSERT(widget);
       
    58 
       
    59     /* Very annoying, we can't cache count(). */
       
    60     /* Idea: QTabWidget::clear(bool deletePageWidgets = false); */
       
    61     while(widget->count() != 0)
       
    62     {
       
    63         delete widget->widget(0);
       
    64         widget->removeTab(0);
       
    65     }
       
    66 
       
    67     Q_ASSERT(widget->count() == 0);
       
    68 }
       
    69 
       
    70 TestCaseView::TestCaseView(QWidget *const p) : QDockWidget(QLatin1String("Test Case View"), p)
       
    71 {
       
    72     setObjectName(QLatin1String("TestCaseView"));
       
    73     setWidget(new QWidget());
       
    74     setupUi(widget());
       
    75     displayNone();
       
    76     clearTabWidget(baselinesTabs);
       
    77 }
       
    78 
       
    79 void TestCaseView::displayNone()
       
    80 {
       
    81     stackedWidget->setCurrentIndex(1);
       
    82 }
       
    83 
       
    84 void TestCaseView::displayTestCase(TestCase *const tc)
       
    85 {
       
    86     if(!tc)
       
    87     {
       
    88         displayNone();
       
    89         return;
       
    90     }
       
    91 
       
    92     name->setText(tc->title());
       
    93     description->setText(tc->description());
       
    94     isXPath->setText(tc->isXPath() ? QLatin1String("yes") : QLatin1String("no"));
       
    95     author->setText(tc->creator());
       
    96     type->setText(TestCase::displayName(tc->scenario()));
       
    97     if(tc->lastModified().isNull())
       
    98         lastModified->setText(QLatin1String("Not specified."));
       
    99     else
       
   100         lastModified->setText(tc->lastModified().toString());
       
   101 
       
   102     if(tc->contextItemSource().isValid())
       
   103         focusDocument->setText(tc->contextItemSource().toLocalFile());
       
   104 
       
   105     /* Not used. */
       
   106     bool ok = false;
       
   107 
       
   108     const QString sourceCode(tc->sourceCode(ok));
       
   109 
       
   110     if(sourceCode.isEmpty())
       
   111         sourceEdit->setPlainText(QLatin1String("No source code available."));
       
   112     else
       
   113         sourceEdit->setPlainText(sourceCode);
       
   114 
       
   115     stackedWidget->setCurrentIndex(0);
       
   116 
       
   117     displayBaseLines(tc);
       
   118 }
       
   119 
       
   120 void TestCaseView::displayBaseLines(const TestCase *const tc)
       
   121 {
       
   122     clearTabWidget(baselinesTabs);
       
   123     Q_ASSERT(tc);
       
   124     const TestBaseLine::List bs(tc->baseLines());
       
   125     const TestBaseLine::List::const_iterator end(bs.constEnd());
       
   126     TestBaseLine::List::const_iterator it(bs.constBegin());
       
   127 
       
   128     for(; it != end; ++it)
       
   129     {
       
   130         const TestBaseLine *const bl = *it;
       
   131         Q_ASSERT(bl);
       
   132         const TestBaseLine::Type t = bl->type();
       
   133 
       
   134         QString title(TestBaseLine::displayName(t));
       
   135         const QString details(bl->details());
       
   136 
       
   137         QWidget *const currPage = new QWidget();
       
   138         Ui::BaseLinePage setupPage;
       
   139         setupPage.setupUi(currPage);
       
   140 
       
   141         /* Make this title a bit better: "ExpectedError: XPTY0004", for example. */
       
   142         switch(t)
       
   143         {
       
   144             case TestBaseLine::ExpectedError:
       
   145             {
       
   146                 title += (QLatin1String(": ") + details);
       
   147                 /* Fallthrough. */
       
   148             }
       
   149             case TestBaseLine::Ignore:
       
   150             {
       
   151                 setupPage.contentEdit->setEnabled(false);
       
   152                 break;
       
   153             }
       
   154             default:
       
   155             {
       
   156                 setupPage.contentEdit->setPlainText(details);
       
   157                 break;
       
   158             }
       
   159         }
       
   160 
       
   161         baselinesTabs->addTab(currPage, title);
       
   162     }
       
   163 
       
   164     int tabIndex = baselinesTabs->count(); /* The tab we're about to add. */
       
   165     baselinesTabs->addTab(new QWidget(), QLatin1String("AST Baseline"));
       
   166     baselinesTabs->setTabToolTip(tabIndex,
       
   167                                  QLatin1String("Expected AST baselines are not yet implemented."));
       
   168     baselinesTabs->setTabEnabled(tabIndex, false);
       
   169 
       
   170     ++tabIndex; /* Again, the tab we're about to add. */
       
   171     baselinesTabs->addTab(new QWidget(), QLatin1String("Message Baseline"));
       
   172     baselinesTabs->setTabToolTip(tabIndex,
       
   173                                  QLatin1String("Expected Message baselines are not yet implemented."));
       
   174     baselinesTabs->setTabEnabled(tabIndex, false);
       
   175 
       
   176     baselinesTabs->setCurrentIndex(0);
       
   177 }
       
   178 
       
   179 // vim: et:ts=4:sw=4:sts=4