#include "radarConfig.h" RadarConfig::RadarConfig( QWidget* parent ) : QMainWindow( parent ) { setObjectName( "Initial Configuration" ); setWindowTitle( "Initial Configuration" ); // Create the box around the parameters. paramBox = new QGroupBox( tr( "Radar Parameters" ) ); QGridLayout* paramLayout = new QGridLayout; // Create the parameter labels. paramLabels[0] = new QLabel( tr( "Radar #: " ) ); paramLabels[1] = new QLabel( tr( "# of Channels: " ) ); // Load in default values for the parameters if the file can be opened. QString param0 = "1"; QString param1 = "8"; QFile params( "config.start" ); if( params.open( QFile::ReadOnly ) ) { QTextStream p( ¶ms ); p >> param0; p >> param1; } // Create the parameter boxes. paramLines[0] = new QLineEdit( param0 ); paramLines[1] = new QLineEdit( param1 ); // Whenever a parameter box loses focus, save the params to file. connect( paramLines[0], SIGNAL( editingFinished() ), this, SLOT( saveParamFile() ) ); connect( paramLines[1], SIGNAL( editingFinished() ), this, SLOT( saveParamFile() )); // Add the elements to the layout. paramLayout->addWidget( paramLabels[0], 1, 0 ); paramLayout->addWidget( paramLines[0], 1, 1 ); paramLayout->addWidget( paramLabels[1], 2, 0 ); paramLayout->addWidget( paramLines[1], 2, 1 ); // Create the accept button and connect the output. accept = new QPushButton( tr( "Accept Values" ) ); connect( accept, SIGNAL( clicked() ), this, SLOT( acceptValues() ) ); // Set the layout. paramBox->setFixedHeight( 100 ); paramBox->setLayout( paramLayout ); QVBoxLayout* mainLayout = new QVBoxLayout; mainLayout->addWidget( paramBox ); mainLayout->addWidget( accept ); setCentralWidget( new QWidget() ); centralWidget()->setLayout( mainLayout ); // Ensure the accept button has the focus. accept->setAutoDefault( true ); accept->setDefault( true ); accept->setFocus(); } RadarConfig::~RadarConfig() { } void RadarConfig::saveParamFile() { // Open the file and save the parameter values. QFile paramFile( "config.start" ); if( paramFile.open( QFile::WriteOnly | QIODevice::Truncate ) && checkValidParams() ) { QTextStream paramText( ¶mFile ); QString param; param = paramLines[0]->text(); radarNumber = param.toInt(); paramText << param; paramText << "\n"; param = paramLines[1]->text(); channelNumber = param.toInt(); paramText << param; } paramFile.close(); } bool RadarConfig::checkValidParams() { bool t1, t2; int rNum, cNum; rNum = paramLines[0]->text().toInt( &t1 ); cNum = paramLines[1]->text().toInt( &t2 ); if( t1 && t2 ) { if( ( ( ( rNum <= 4 ) && ( rNum > 0 ) ) || ( rNum == 253 ) ) && ( cNum <= 8 ) && ( cNum > 0 ) ) { radarNumber = rNum; channelNumber = cNum; return true; } else { return false; } } else { return false; } } void RadarConfig::closeEvent( QCloseEvent* event ) { event->accept(); } void RadarConfig::acceptValues() { if( checkValidParams() ) { emit configWindowAccepted( radarNumber, channelNumber ); } else { QErrorMessage* msgD = new QErrorMessage( this ); msgD->showMessage( "Incorrect parameter value(s). Check values and try again." ); } }