testfwuis/symbianunittestui/qt/dialogaddtests.cpp
changeset 2 453d490c84a5
equal deleted inserted replaced
1:753e33780645 2:453d490c84a5
       
     1 /*
       
     2  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description: Dialog class to add test dll files.
       
    15  *
       
    16  */
       
    17 
       
    18 #include <QDialog>
       
    19 #include <QTextEdit>
       
    20 #include <QPushButton>
       
    21 #include <QGridLayout>
       
    22 #include <QLabel>
       
    23 #include "dialogaddtests.h"
       
    24 
       
    25 static const QString filter = "[\n \t\r;]";
       
    26 static const QChar separator = ',';
       
    27 
       
    28 DialogAddTests::DialogAddTests(QWidget* parent) :
       
    29     QDialog(parent)
       
    30     {
       
    31     setContextMenuPolicy(Qt::NoContextMenu);
       
    32     setWindowTitle(tr("Add Tests"));
       
    33     load();
       
    34     setLayout();
       
    35     clear();
       
    36     }
       
    37 
       
    38 DialogAddTests::~DialogAddTests()
       
    39     {
       
    40     }
       
    41 
       
    42 void DialogAddTests::clear()
       
    43     {
       
    44     txtTests->clear();
       
    45     }
       
    46 
       
    47 void DialogAddTests::saveTests()
       
    48     {
       
    49     QString text = txtTests->toPlainText();
       
    50     if (!text.isNull() && !text.isEmpty())
       
    51         {
       
    52         text.remove(QRegExp(filter));
       
    53         emit this->testsSaved(text.split(separator));
       
    54         this->close();
       
    55         }
       
    56     }
       
    57 
       
    58 void DialogAddTests::load()
       
    59     {
       
    60     txtTests = new QTextEdit(this);
       
    61     txtTests->setToolTip(tr("enter file names without dll extension, comma separated."));
       
    62     connect(txtTests, SIGNAL(textChanged()), this, SLOT(changeText()));
       
    63     
       
    64     btnOk = new QPushButton(tr("OK"), this);
       
    65     connect(btnOk, SIGNAL(clicked()), this, SLOT(saveTests()));
       
    66     
       
    67     btnCancel = new QPushButton(tr("Cancel"), this);
       
    68     connect(btnCancel, SIGNAL(clicked()), this, SLOT(close()));
       
    69     
       
    70     btnOk->setEnabled(false);
       
    71     }
       
    72 
       
    73 void DialogAddTests::changeText()
       
    74     {
       
    75     QString text = txtTests->toPlainText();
       
    76     if (text.isNull() || text.isEmpty())
       
    77         {
       
    78         btnOk->setEnabled(false);
       
    79         }
       
    80     else
       
    81         {
       
    82         btnOk->setEnabled(true);
       
    83         }
       
    84     }
       
    85 
       
    86 void DialogAddTests::setLayout()
       
    87     {    
       
    88     QGridLayout* layout = new QGridLayout(this);
       
    89     layout->setSpacing(2);
       
    90     layout->setMargin(2);
       
    91     layout->addWidget(txtTests, 0, 0, 1, 2);
       
    92     layout->addWidget(btnOk, 1, 0, 1, 1);
       
    93     layout->addWidget(btnCancel, 1, 1, 1, 1);
       
    94     }
       
    95