void MainWindow::connectUser() { QString serverIp = ""; if ( ipCheck(serverIpEdt->text()) ) { statLbl->setText(""); serverIp = serverIpEdt->text(); settings->setValue("serverIp", serverIp ); const QPixmap *avatar = loginAvatarLbl->pixmap(); QImage resizedAvatar; if (avatar != NULL) { resizedAvatar = avatar->scaled(WORK_SIZE, WORK_SIZE).toImage(); } if ( checkFields() ) { Socket::sock().login( serverIp, loginUserEdt->text(), loginPasswordEdt->text(), QImage2Mat( resizedAvatar ) ); } } else { statLbl->setText("Adresse IP incorrecte"); } }
bool ScytaleUI::doAction() { if (!checkFields()) return false; prepareUndo(); algo.setLetterOnDiameter(letterNbBox->value()); algo.setCleanText(cleanTextOpt->isChecked()); return true; }
CaseInfo getCaseInfo(const std::string &casedir, double mintime, double maxtime, int skipfactor, bool exact) { CaseInfo info; info.valid = checkCaseDirectory(info, casedir, false, mintime, maxtime, skipfactor, exact); std::cerr << " " << "casedir: " << casedir << " " << std::endl << "Number of processors: " << info.numblocks << std::endl << "Number of time directories found: " << info.timedirs.size() << std::endl << "Number of fields: " << info.constantFields.size() + info.varyingFields.size() << std::endl; int np = info.numblocks > 0 ? info.numblocks : 1; std::cerr << " constant:"; checkFields(info.constantFields, np, exact); std::cerr << " varying: "; checkFields(info.varyingFields, np * info.timedirs.size(), exact); return info; }
void MainWindow::on_pushButton_OK_clicked() { // check for every field is correctly filled if (checkFields()) { createClassDefintionObject(); _writer.setClassDefinition(_definition); if (ui->checkBox_TwoFiles->isChecked()) _writer.write(); else _writer.writeHPP(); } }
/*! * \en Creates property editor dialog window. \_en * \ru Создает диалоговое окно редактора свойств. \_ru */ void wDBTable::OpenEditor() { //getBindList(); setAvailableTables(); eDBTable e( this->topLevelWidget()); checkFields(); e.setData(this,md); if ( e.exec()==QDialog::Accepted ) { e.getData(this); //updateProp(); } }
void run() { ReplPair rp1( "foo", "bar" ); checkFields( rp1, "foo", "foo", CmdLine::DefaultDBPort, "bar" ); ReplPair rp2( "foo:1", "bar" ); checkFields( rp2, "foo:1", "foo", 1, "bar" ); // FIXME Should we accept this input? ReplPair rp3( "", "bar" ); checkFields( rp3, "", "", CmdLine::DefaultDBPort, "bar" ); ASSERT_EXCEPTION( ReplPair( "foo:", "bar" ), UserException ); ASSERT_EXCEPTION( ReplPair( "foo:0", "bar" ), UserException ); ASSERT_EXCEPTION( ReplPair( "foo:10000000", "bar" ), UserException ); ASSERT_EXCEPTION( ReplPair( "foo", "" ), UserException ); }
void ScytaleUI::onCrackRequest() { if (!checkFields()) return; if ((text->toPlainText().length() % 2)) { QMessageBox::warning(this, tr("Error"), tr("Scytale ciphered message must be odd")); return; } prepareUndo(); algo.setCipherMsg(text->toPlainText()); algo.setLetterOnDiameter(algo.crack()); algo.setCleanText(cleanTextOpt->isChecked()); algo.decipher(); text->setText(algo.getClearMsg()); }
void ReportProblemDialog::SendReport() { if (checkFields()) { QApplication::setOverrideCursor(Qt::WaitCursor); QtJson::JsonObject postData; postData["name"] = nameEdit->text(); postData["email"] = emailEdit->text(); if (sendOSInfoCheckBox->isChecked()) { QProcess dxDiagProcess; QStringList arguments; QString reportFileName = QString("dxdiagReport.%1.txt").arg(QApplication::applicationPid()); QString dxDiagReportFilePath = StaticHelpers::CombinePathes(QDesktopServices::storageLocation(QDesktopServices::TempLocation), reportFileName); arguments << "/whql:on" << QString("/t%1").arg(dxDiagReportFilePath); dxDiagProcess.start("dxdiag.exe", arguments); dxDiagProcess.waitForFinished(); QFile reportFile(dxDiagReportFilePath); if (reportFile.open(QIODevice::ReadOnly)) { QString reportData = QString::fromLocal8Bit(reportFile.readAll()); postData["problem"] = problemDescriptionEdit->toPlainText().append("\n").append(reportData); reportFile.close(); QFile::remove(dxDiagReportFilePath); } else { QApplication::restoreOverrideCursor(); CustomMessageBox::critical(this, "Windows Info creation failed", "Failed to create DxDaig Report.\nError: " + reportFile.errorString()); return; } } else { postData["problem"] = problemDescriptionEdit->toPlainText(); } QByteArray data = QtJson::serialize(postData); qDebug() << "Sending JSON:" << QString(data); QNetworkRequest request(QUrl("http://integration.cutetorrent.info/report.php")); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); m_pNetManager->post(request, data); } }
void MethodView::on_pushButton_OK_clicked() { if (checkFields()) { Method m; m.Name = ui->lineEdit_Name->text().toStdString(); m.ReturnedValue = ui->lineEdit_ReturnType->text().toStdString(); m.isAbstract = ui->checkBox_Abstract->isChecked(); m.isConst = ui->checkBox_Const->isChecked(); m.isStatic = ui->checkBox_Static->isChecked(); m.isVirtual = ui->checkBox_Virtual->isChecked(); m.isInline = ui->checkBox_Inline->isChecked(); m.Parameters = _params; m.Range = (RANGE) ui->comboBox_Range->currentIndex(); MainWindow * mw = dynamic_cast<MainWindow*>(parent()); mw->addMethod(m); close(); } }
void FieldMemberWindow::on_pushButton_OK_clicked() { // check everything is ok if (checkFields()) { FieldMember fm; fm.Name = ui->lineEdit_Name->text().toStdString(); fm.Type = ui->lineEdit_Type->text().toStdString(); fm.Default = ui->lineEdit_Default->text().toStdString(); fm.isConst = ui->checkBox_Const->isChecked(); fm.isStatic = ui->checkBox_Static->isChecked(); fm.hasGet = ui->checkBox_Get->isChecked(); fm.hasSet = ui->checkBox_Set->isChecked(); fm.Range = (RANGE) ui->comboBox_Range->currentIndex(); MainWindow * mw = dynamic_cast<MainWindow*>(parent()); mw->addFieldMember(fm); close(); } }
OsmRelationEditorDialog::OsmRelationEditorDialog( OsmPlacemarkData *relationData, QWidget *parent ) : QDialog( parent ) { m_relationData = relationData; QVBoxLayout *layout = new QVBoxLayout( this ); // Name input area QHBoxLayout *nameLayout = new QHBoxLayout(); QLabel *nameLabel = new QLabel( tr( "Name" ), this ); m_nameLineEdit = new QLineEdit( this ); m_nameLineEdit->setText(relationData->tagValue(QStringLiteral("name"))); nameLayout->addWidget( nameLabel ); nameLayout->addWidget( m_nameLineEdit ); layout->addLayout( nameLayout ); // Tag editor area // A dummy placemark is needed because the OsmTagEditorWidget works with placemarks m_dummyPlacemark = new GeoDataPlacemark(); // "osmRelaation=yes" entry is added to its ExtendedData to let the widget know // its special relation status GeoDataExtendedData extendedData; extendedData.addValue(GeoDataData(QStringLiteral("osmRelation"), QStringLiteral("yes"))); m_dummyPlacemark->setExtendedData( extendedData ); m_dummyPlacemark->setOsmData( *m_relationData ); OsmObjectManager::initializeOsmData( m_dummyPlacemark ); m_tagEditor = new OsmTagEditorWidget( m_dummyPlacemark, this ); layout->addWidget( m_tagEditor ); // Button box area m_buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this ); layout->addWidget( m_buttonBox ); QObject::connect( m_buttonBox, SIGNAL( accepted() ), this, SLOT( checkFields() ) ); connect(m_buttonBox, SIGNAL(rejected()), SLOT(reject())); }
/* * addSensor( type, val1, val2, val3, val4) - add sensor to frame * * Parameters: * type : Refers to the type of sensor data * val1 : indicates the sensor value as an uint8_t * val2 : indicates the sensor value as an uint8_t * val2 : indicates the sensor value as an uint8_t * val2 : indicates the sensor value as an int * * Returns: * 'length' of the composed frame when ok * -1 when the maximum length of the frame is reached * * This function prototype is only thought for SENSOR_TIME field * */ int8_t WaspFrame::addSensor(uint8_t type, uint8_t val1, uint8_t val2, uint8_t val3, int val4) { char str1[10]; char str2[10]; char str3[10]; char str4[10]; if(_mode == ASCII) { /// ASCII // get name of sensor from table char name[10]; strcpy_P(name, (char*)pgm_read_word(&(SENSOR_TABLE[type]))); // convert from integer to string itoa( val1, str1, 10); itoa( val2, str2, 10); itoa( val3, str3, 10); itoa( val4, str4, 10); // check if new sensor value fits in the frame or not // in the case the maximum length is reached, exit with error // if not, then add the new sensor length to the total length if(!checkLength( strlen(name) + strlen(":") + strlen(str1) + strlen("-") + strlen(str2) + strlen("-") + strlen(str3) + strlen("+") + strlen(str4) + strlen("#") )) { return -1; } // concatenate sensor name to frame string strncat((char*)buffer, name, strlen(name)); strcat((char*)buffer, ":"); // concatenate sensor value to frame string strncat((char*)buffer, str1, strlen(str1)); strcat((char*)buffer, "-"); strncat((char*)buffer, str2, strlen(str2)); strcat((char*)buffer, "-"); strncat((char*)buffer, str3, strlen(str3)); if( val4>= 0 ) { // if GMT is positive it is necessary to append a '+' character strcat((char*)buffer, "+"); } strncat((char*)buffer, str4, strlen(str4)); strcat((char*)buffer, "#\0"); // increment sensor fields counter numFields++; // set sensor fields counter buffer[4]=numFields; } else { /// BINARY // As SENSOR_TIME is thought to be a 3-value field. This function permits to // add teh GMT value at the end of the time. But "checkFields" function must // expect 3 values because it is the original composition. if(checkFields(type, TYPE_UINT8, 3) == -1 ) return -1; // check if new sensor value fits 1+1+1+1 if(!checkLength(4)) { return -1; } // concatenate sensor name to frame string buffer[length-4] = (char)type; buffer[length-3] = val1; buffer[length-2] = val2; buffer[length-1] = val3; buffer[length] = '\0'; // increment sensor fields counter numFields++; // set sensor fields counter buffer[4]=numFields; } return length; }
void EGS_PegsPage::startPegs() { #ifdef PP_DEBUG qDebug("In EGS_PegsPage::startPegs()"); #endif if( !checkFields() ) return; if( !config_reader ) config_reader = new EGS_ConfigReader; QString executable = config_reader->getVariable("HEN_HOUSE",true); executable += "bin"; executable += QDir::separator(); executable += config_reader->getVariable("my_machine"); executable += QDir::separator(); executable += "pegs4.exe"; QFileInfo fi(executable); if( !fi.exists() ) { QMessageBox::critical(this,"Error", QString("%1 does not exist ?").arg(executable),QMessageBox::Ok,0); return; } if( !fi.isExecutable() ) { QMessageBox::critical(this,"Error", QString("%1 is not executable ?").arg(executable),QMessageBox::Ok,0); return; } // process arguments QStringList args; //pegs_process->clearArguments(); //pegs_process->addArgument(executable); args << "-e";//pegs_process->addArgument("-e"); args << config_reader->getVariable("EGS_HOME",true);//pegs_process->addArgument(); args << "-h";//pegs_process->addArgument("-h"); args << config_reader->getVariable("HEN_HOUSE",true);//pegs_process->addArgument(); args << "-o";//pegs_process->addArgument("-o"); args << ofile_le->text();//pegs_process->addArgument(); run_output->setOutputFile(ofile_le->text()); if( append_to_datafile->isChecked() ) args << "-a";//pegs_process->addArgument("-a"); if( dc_icru_check->isChecked() ) { args << "-d";//pegs_process->addArgument("-d"); args << dc_file->text();//pegs_process->addArgument(); } //QStringList list = pegs_process->arguments(); #ifdef PP_DEBUG qDebug("Executing: <%s>",args.join(" ").toLatin1().data()); #endif // PEGS input QString input; QTextStream ts( &input, QIODevice::WriteOnly ); ts << "ENER\n &INP AE=" << ae << ",UE=" << ue << ",AP=" << ap << ",UP=" << up << " &END\n"; if( medtype_cbox->currentText() == "Element" ) { ts << "ELEM\n &INP "; } else { if( medtype_cbox->currentText() == "Compound" ) { ts << "COMP\n &INP NE=" << nelem << ",PZ="; } else { ts << "MIXT\n &INP NE=" << nelem << ",RHOZ="; } for(int j=0; j<nelem; j++) { bool is_ok; double w = composition_table->item(j,1)->text().toDouble(&is_ok); if( !is_ok ) { QString err = QString("Wrong input in row %1, column 1").arg(j); QMessageBox::critical(this,"Error",err,QMessageBox::Ok,0); return; } ts << w << ","; } } ts << "RHO="; bool is_ok; double rho = rho_le->text().toDouble(&is_ok); if( !is_ok ) { QString err = QString("Wrong mass density input"); QMessageBox::critical(this,"Error",err,QMessageBox::Ok,0); return; } if( comboBox2->currentText() == "kg/m**3" ) rho *= 0.001;//convert to g/cm**3 ts << rho; if( is_gas->isChecked() ) ts << ",GASP=1.0"; ts << ",EPSTFL=" << dc_icru_check->isChecked() << ",IAPRIM=" << rad_icru_check->isChecked() << ",IRAYL=" << rayleigh_check->isChecked() << " &END\n"; ts << medname_le->text() << "\n"; for(int j=0; j<nelem; j++) { QString e = composition_table->item(j,0)->text().toUpper(); if( j > 0 ) ts << " "; ts << e; if( e.length() == 1 ) ts << " "; } ts << "\n"; ts << "PWLF\n &INP &END\nDECK\n &INP &END\n"; #ifdef PP_DEBUG qDebug("Input string:\n%s",input.toLatin1().data()); #endif run_output->clearOutput(); //pegs_process->launch(input); pegs_process->start(executable,args); if (!pegs_process->waitForStarted()){ QMessageBox::critical(this,"Error", QString("PEGS failed, exit status was %1").arg(pegs_process->exitStatus()), QMessageBox::Ok,0); go_button->setEnabled(true); cancel_button->setEnabled(false); return; } pegs_process->write(input.toLatin1()); pegs_process->closeWriteChannel(); go_button->setEnabled(false); cancel_button->setEnabled(true); }
UpdateCameraDialog::UpdateCameraDialog(const Camera& camera, QWidget *parent) : QDialog(parent) { _observerXEdit = new QLineEdit(QString::number(camera._observer[0]), this); _observerXEdit->setFixedWidth(50); _observerYEdit = new QLineEdit(QString::number(camera._observer[1]), this); _observerYEdit->setFixedWidth(50); _observerZEdit = new QLineEdit(QString::number(camera._observer[2]), this); _observerZEdit->setFixedWidth(50); QFormLayout* observerXLayout = new QFormLayout; observerXLayout->addRow("X:", _observerXEdit); QFormLayout* observerYLayout = new QFormLayout; observerYLayout->addRow("Y:", _observerYEdit); QFormLayout* observerZLayout = new QFormLayout; observerZLayout->addRow("Z:", _observerZEdit); QHBoxLayout* observerLayout = new QHBoxLayout; observerLayout->addLayout(observerXLayout); observerLayout->addLayout(observerYLayout); observerLayout->addLayout(observerZLayout); QGroupBox* observerGroupBox = new QGroupBox("observer", this); observerGroupBox->setFixedWidth(250); observerGroupBox->setLayout(observerLayout); _aimedPointXEdit = new QLineEdit(QString::number(camera._aimedPoint[0]), this); _aimedPointXEdit->setFixedWidth(50); _aimedPointYEdit = new QLineEdit(QString::number(camera._aimedPoint[1]), this); _aimedPointYEdit->setFixedWidth(50); _aimedPointZEdit = new QLineEdit(QString::number(camera._aimedPoint[2]), this); _aimedPointZEdit->setFixedWidth(50); QFormLayout* aimedPointXLayout = new QFormLayout; aimedPointXLayout->addRow("X:", _aimedPointXEdit); QFormLayout* aimedPointYLayout = new QFormLayout; aimedPointYLayout->addRow("Y:", _aimedPointYEdit); QFormLayout* aimedPointZLayout = new QFormLayout; aimedPointZLayout->addRow("Z:", _aimedPointZEdit); QHBoxLayout* aimedPointLayout = new QHBoxLayout; aimedPointLayout->addLayout(aimedPointXLayout); aimedPointLayout->addLayout(aimedPointYLayout); aimedPointLayout->addLayout(aimedPointZLayout); QGroupBox* aimedPointGroupBox = new QGroupBox("aimedPoint", this); aimedPointGroupBox->setFixedWidth(250); aimedPointGroupBox->setLayout(aimedPointLayout); _viewAngleEdit = new QLineEdit(QString::number(camera._viewAngle), this); _viewAngleEdit->setFixedWidth(50); QFormLayout* viewAngleLayout = new QFormLayout; viewAngleLayout->addRow("Value:", _viewAngleEdit); QGroupBox* viewAngleGroupBox = new QGroupBox("View angle", this); viewAngleGroupBox->setLayout(viewAngleLayout); _distanceScreenEdit = new QLineEdit(QString::number(camera._distScreen), this); _distanceScreenEdit->setFixedWidth(50); QFormLayout* distanceScreenLayout = new QFormLayout; distanceScreenLayout->addRow("Value:", _distanceScreenEdit); QGroupBox* distanceScreenGroupBox = new QGroupBox("Distance to screen", this); distanceScreenGroupBox->setLayout(distanceScreenLayout); QVBoxLayout* fieldsLayout = new QVBoxLayout; fieldsLayout->setAlignment(Qt::AlignTop); fieldsLayout->addWidget(observerGroupBox); fieldsLayout->addWidget(aimedPointGroupBox); fieldsLayout->addWidget(viewAngleGroupBox); fieldsLayout->addWidget(distanceScreenGroupBox); _okButton = new QPushButton("Update"); connect(_okButton, SIGNAL(clicked()), this, SLOT(checkFields())); _cancelButton = new QPushButton("Cancel"); connect(_cancelButton, SIGNAL(clicked()), this, SLOT(reject())); QVBoxLayout* buttonsLayout = new QVBoxLayout; buttonsLayout->setAlignment(Qt::AlignTop); buttonsLayout->addWidget(_okButton); buttonsLayout->addWidget(_cancelButton); QHBoxLayout* mainLayout = new QHBoxLayout; mainLayout->setAlignment(Qt::AlignTop); mainLayout->addLayout(fieldsLayout); mainLayout->addLayout(buttonsLayout); setLayout(mainLayout); }
/* * addSensor (type, value) - add sensor value to frame * * Parameters: * type : Refers to the type of sensor data * value : indicates the sensor value as a float * * Returns: * 'length' of the composed frame when ok * -1 when the maximum length of the frame is reached * */ int8_t WaspFrame::addSensor(uint8_t type, char* str) { if(_mode == ASCII) { // get name of sensor from table char name[10]; strcpy_P(name, (char*)pgm_read_word(&(SENSOR_TABLE[type]))); // check if new sensor value fits in the frame or not // in the case the maximum length is reached, exit with error // if not, then add the new sensor length to the total length if(!checkLength( strlen(name) + strlen(str) + strlen(":") + strlen("#") )) { return -1; } // concatenate sensor name to frame string strncat((char*)buffer, name, strlen(name)); strcat((char*)buffer, ":"); // concatenate sensor value to frame string strncat((char*)buffer, str, strlen(str)); strcat((char*)buffer, "#\0"); // increment sensor fields counter numFields++; // set sensor fields counter buffer[4]=numFields; } else { // check if the data input type corresponds to the sensor if(checkFields(type, TYPE_CHAR, 1) == -1 ) return -1; // set data bytes (in this case, string, one byte per char) & length (1 byte) int8_t lng = strlen(str); // check if new sensor value fits (id + nbytes + str) if(!checkLength(2+strlen(str))) { return -1; } // concatenate sensor name to frame string int len = length-2-strlen(str); buffer[len] = (char)type; buffer[len+1] = lng; for (int j=len+2;j<length;j++) { buffer[j] = str[j-2-len]; } buffer[length] = '\0'; // increment sensor fields counter numFields++; // set sensor fields counter buffer[4]=numFields; } return length; }
/* * addSensor (type, value, N) - add sensor value to frame * * Parameters: * type : Refers to the type of sensor data * value : indicates the sensor value as a float * N : number of decimals * * Returns: * 'length' of the composed frame when ok * -1 when the maximum length of the frame is reached * */ int8_t WaspFrame::addSensor(uint8_t type, double value, int N) { char str[20]; if(_mode == ASCII) { // convert from integer to string Utils.float2String(value, str, N); // get name of sensor from table char name[10]; strcpy_P(name, (char*)pgm_read_word(&(SENSOR_TABLE[type]))); // check if new sensor value fits in the frame or not // in the case the maximum length is reached, exit with error // if not, then add the new sensor length to the total length if(!checkLength( strlen(name) + strlen(str) + strlen(":") + strlen("#") )) { return -1; } // concatenate sensor name to frame string strncat((char*)buffer, name, strlen(name)); strcat((char*)buffer, ":"); // concatenate sensor value to frame string strncat((char*)buffer, str, strlen(str)); strcat((char*)buffer, "#\0"); // increment sensor fields counter numFields++; // set sensor fields counter buffer[4]=numFields; } else { // check if the data input type corresponds to the sensor if(checkFields(type, TYPE_FLOAT, 1) == -1 ) return -1; // set data bytes (in this case, double is 4...) char val[4]; memcpy(val,&value,4); /* Check correct copy union { float f; char b[4]; } u; u.b[3] = val[3]; u.b[2] = val[2]; u.b[1] = val[1]; u.b[0] = val[0]; delay(1); USB.println(u.f);*/ // check if new sensor value fits /1+4/ if(!checkLength(5)) { return -1; } // concatenate sensor name to frame string buffer[length-5] = (char)type; buffer[length-4] = val[0]; buffer[length-3] = val[1]; buffer[length-2] = val[2]; buffer[length-1] = val[3]; buffer[length] = '\0'; // increment sensor fields counter numFields++; // set sensor fields counter buffer[4]=numFields; } return length; }
/* * addSensor (type, value) - add sensor value to frame * * Parameters: * type : Refers to the type of sensor data * value : indicates the sensor value as a float * * Returns: * 'length' of the composed frame when ok * -1 when the maximum length of the frame is reached * */ int8_t WaspFrame::addSensor(uint8_t type, int value) { char str[10]; if(_mode == ASCII) { // get name of sensor from table char name[10]; strcpy_P(name, (char*)pgm_read_word(&(SENSOR_TABLE[type]))); // convert from integer to string itoa( value, str, 10); // check if new sensor value fits in the frame or not // in the case the maximum length is reached, exit with error // if not, then add the new sensor length to the total length if(!checkLength( strlen(name) + strlen(str) + strlen(":") + strlen("#") )) { return -1; } // concatenate sensor name to frame string strncat((char*)buffer, name, strlen(name)); strcat((char*)buffer, ":"); // concatenate sensor value to frame string strncat((char*)buffer, str, strlen(str)); strcat((char*)buffer, "#\0"); // increment sensor fields counter numFields++; // set sensor fields counter buffer[4]=numFields; } else { // check if the data input type corresponds to the sensor if (value<=255) { if( checkFields(type, TYPE_UINT8, 1) == -1 ) return -1; } else { if( checkFields(type, TYPE_INT, 1) == -1 ) return -1; } // set data bytes (in this case, int is two bytes) char val[2]; memcpy(val,&value,2); /*char val1 = value &0xFF; char val2 = (value >> 8) &0xFF; */ //Check again (1 byte or 2 bytes) uint8_t config; config =(uint8_t)pgm_read_word(&(SENSOR_TYPE_TABLE[type])); if (config == TYPE_INT) { // check if new sensor value fits if(!checkLength(3)) { return -1; } // concatenate sensor name to frame string buffer[length-3] = (char)type; buffer[length-2] = val[0]; buffer[length-1] = val[1]; buffer[length] = '\0'; } else { // check if new sensor value fits if(!checkLength(2)) { return -1; } // concatenate sensor name to frame string buffer[length-2] = (char)type; buffer[length-1] = val[0]; buffer[length] = '\0'; } // increment sensor fields counter numFields++; // set sensor fields counter buffer[4]=numFields; } return length; }
int8_t WaspFrame::addSensor(uint8_t type, double val1,double val2,double val3) { char str1[20]; char str2[20]; char str3[20]; if(_mode == ASCII) { // get name of sensor from table char numDecimals; numDecimals =(uint8_t)pgm_read_word(&(DECIMAL_TABLE[type])); // convert from integer to string Utils.float2String(val1, str1, numDecimals); Utils.float2String(val2, str2, numDecimals); Utils.float2String(val3, str3, numDecimals); // get name of sensor from table char name[10]; strcpy_P(name, (char*)pgm_read_word(&(SENSOR_TABLE[type]))); // check if new sensor value fits in the frame or not // in the case the maximum length is reached, exit with error // if not, then add the new sensor length to the total length if(!checkLength( strlen(name) + strlen(str1) + strlen(str2) + strlen(str3) + strlen(";") + strlen(";") + strlen(":") + strlen("#") )) { return -1; } // concatenate sensor name to frame string strncat((char*)buffer, name, strlen(name)); strcat((char*)buffer, ":"); // concatenate sensor value to frame string strncat((char*)buffer, str1, strlen(str1)); strcat((char *)buffer, ";"); strncat((char*)buffer, str2, strlen(str2)); strcat((char *)buffer, ";"); strncat((char*)buffer, str3, strlen(str3)); strcat((char*)buffer, "#\0"); // increment sensor fields counter numFields++; // set sensor fields counter buffer[4]=numFields; } else { // check if the data input type corresponds to the sensor if( checkFields(type, TYPE_FLOAT, 3) == -1 ) return -1; // set data bytes (in this case, double is 4...) char valB1[4]; char valB2[4]; char valB3[4]; memcpy(valB1,&val1,4); memcpy(valB2,&val2,4); memcpy(valB3,&val3,4); /* union { float f; char b[4]; } u; u.b[3] = val[3]; u.b[2] = val[2]; u.b[1] = val[1]; u.b[0] = val[0]; USB.println(u.f); */ // check if new sensor value fits /1+4+4+4/ if(!checkLength(13)) { return -1; } // concatenate sensor name to frame string buffer[length-13] = (char)type; buffer[length-12] = valB1[0]; buffer[length-11] = valB1[1]; buffer[length-10] = valB1[2]; buffer[length-9] = valB1[3]; buffer[length-8] = valB2[0]; buffer[length-7] = valB2[1]; buffer[length-6] = valB2[2]; buffer[length-5] = valB2[3]; buffer[length-4] = valB3[0]; buffer[length-3] = valB3[1]; buffer[length-2] = valB3[2]; buffer[length-1] = valB3[3]; buffer[length] = '\0'; // increment sensor fields counter numFields++; // set sensor fields counter buffer[4]=numFields; } return length; }
EditPlacemarkDialog::EditPlacemarkDialog( GeoDataPlacemark *placemark, const QHash<qint64, OsmPlacemarkData> *relations, QWidget *parent ) : QDialog( parent ), d( new Private( placemark ) ) { d->setupUi( this ); // Store initial style so that it can be restored if the 'Cancel' button is pressed. d->m_initialStyle = *placemark->style(); d->m_initialVisualCategory = placemark->visualCategory(); d->m_hadInitialOsmData = placemark->hasOsmData(); if ( d->m_hadInitialOsmData ) { d->m_initialOsmData = placemark->osmData(); } // If the placemark has just been created, assign it a default name. if ( placemark->name().isNull() ) { placemark->setName( tr("Untitled Placemark") ); } // Setup id, name, icon link and latitude/longitude values. d->m_header->setId( placemark->id() ); d->m_initialId = placemark->id(); d->m_header->setName( placemark->name() ); d->m_initialName = placemark->name(); d->m_isPlacemarkVisible->setChecked( placemark->isVisible() ); d->m_initialIsPlacemarkVisible = placemark->isVisible(); d->m_header->setIconLink( placemark->style()->iconStyle().iconPath() ); d->m_header->setTargetId( placemark->targetId() ); d->m_initialTargetId = placemark->targetId(); MarbleWidget* marbleWidget = dynamic_cast<MarbleWidget*>( parent ); if( marbleWidget != 0 ) { const AngleUnit defaultAngleUnit = marbleWidget->defaultAngleUnit(); const GeoDataCoordinates::Notation notation = (defaultAngleUnit == DecimalDegree) ? GeoDataCoordinates::Decimal : (defaultAngleUnit == DMSDegree) ? GeoDataCoordinates::DMS : /* else, UTM */ GeoDataCoordinates::DMS; d->m_header->setNotation( notation ); } connect( d->m_header, SIGNAL(valueChanged()), this, SLOT( updateTextAnnotation()) ); d->m_formattedTextWidget->setText( placemark->description() ); d->m_initialDescription = placemark->description(); d->m_initialDescriptionIsCDATA = placemark->descriptionIsCDATA(); d->m_isBalloonVisible->setChecked( placemark->isBalloonVisible() ); d->m_initialIsBaloonVisible = placemark->isBalloonVisible(); d->m_header->setLatitude( placemark->coordinate().latitude( GeoDataCoordinates::Degree ) ); d->m_header->setLongitude( placemark->coordinate().longitude( GeoDataCoordinates::Degree ) ); d->m_initialCoords = GeoDataCoordinates( d->m_header->longitude(), d->m_header->latitude(), 0, GeoDataCoordinates::Degree ); // There's no point showing Relations and Tags tabs if the editor was not // loaded from the annotate plugin ( loaded from tourWidget.. ) if ( relations ) { // Adding the osm tag editor widget tab d->m_osmTagEditorWidget = new OsmTagEditorWidget( placemark, this ); d->tabWidget->addTab( d->m_osmTagEditorWidget, tr( "Tags" ) ); QObject::connect( d->m_osmTagEditorWidget, SIGNAL( placemarkChanged( GeoDataFeature* ) ), this, SLOT( updateTextAnnotation() ) ); // Adding the osm relation editor widget tab d->m_osmRelationManagerWidget = new OsmRelationManagerWidget( placemark, relations, this ); d->tabWidget->addTab( d->m_osmRelationManagerWidget, tr( "Relations" ) ); QObject::connect( d->m_osmRelationManagerWidget, SIGNAL( relationCreated( const OsmPlacemarkData& ) ), this, SIGNAL( relationCreated( const OsmPlacemarkData& ) ) ); } // Adding the elevation widget tab d->m_elevationWidget = new Ui::ElevationWidget; QWidget *elevationTab = new QWidget; d->m_elevationWidget->setupUi( elevationTab ); d->tabWidget->addTab( elevationTab, tr("Elevation") ); qreal altitude = d->m_placemark->coordinate().altitude(); MarbleLocale *locale = MarbleGlobal::getInstance()->locale(); if ( altitude == 0.0 ) { switch ( locale->measurementSystem() ) { case MarbleLocale::MetricSystem: d->m_elevationUnit = MarbleLocale::Meter; break; case MarbleLocale::ImperialSystem: d->m_elevationUnit = MarbleLocale::Foot; break; case MarbleLocale::NauticalSystem: d->m_elevationUnit = MarbleLocale::NauticalMile; break; } d->m_elevationWidget->elevationSpinBox->setSuffix( locale->unitAbbreviation((d->m_elevationUnit)) ); } else { qreal convertedAltitude; const MarbleLocale::MeasurementSystem currentSystem = locale->measurementSystem(); locale->meterToTargetUnit( altitude, currentSystem, convertedAltitude, d->m_elevationUnit ); d->m_elevationWidget->elevationSpinBox->setValue( convertedAltitude ); d->m_elevationWidget->elevationSpinBox->setSuffix( locale->unitAbbreviation(d->m_elevationUnit) ); } // Adjust icon and label scales. d->m_iconScale->setValue( placemark->style()->iconStyle().scale() ); connect( d->m_iconScale, SIGNAL(valueChanged(double)), this, SLOT(updateTextAnnotation()) ); d->m_labelScale->setValue( placemark->style()->labelStyle().scale() ); connect( d->m_labelScale, SIGNAL(valueChanged(double)), this, SLOT(updateTextAnnotation()) ); // Adjust the current color of the two push buttons' pixmap to resemble the label and icon colors. const GeoDataLabelStyle labelStyle = placemark->style()->labelStyle(); const GeoDataIconStyle iconStyle = placemark->style()->iconStyle(); QPixmap labelPixmap( d->m_labelButton->iconSize().width(), d->m_labelButton->iconSize().height() ); labelPixmap.fill( labelStyle.color() ); d->m_labelButton->setIcon( QIcon( labelPixmap ) ); QPixmap iconPixmap( d->m_iconButton->iconSize().width(), d->m_iconButton->iconSize().height() ); iconPixmap.fill( iconStyle.color() ); d->m_iconButton->setIcon( QIcon( iconPixmap ) ); // Setup the color dialogs. d->m_labelColorDialog = new QColorDialog( this ); d->m_labelColorDialog->setOption( QColorDialog::ShowAlphaChannel ); d->m_labelColorDialog->setCurrentColor( labelStyle.color() ); connect( d->m_labelButton, SIGNAL(clicked()), d->m_labelColorDialog, SLOT(exec()) ); connect( d->m_labelColorDialog, SIGNAL(colorSelected(QColor)), this, SLOT(updateLabelDialog(QColor)) ); connect( d->m_labelColorDialog, SIGNAL(colorSelected(QColor)), this, SLOT(updateTextAnnotation()) ); d->m_iconColorDialog = new QColorDialog( this ); d->m_iconColorDialog->setOption( QColorDialog::ShowAlphaChannel ); d->m_iconColorDialog->setCurrentColor( iconStyle.color() ); connect( d->m_iconButton, SIGNAL(clicked()), d->m_iconColorDialog, SLOT(exec()) ); connect( d->m_iconColorDialog, SIGNAL(colorSelected(QColor)), this, SLOT(updateIconDialog(QColor)) ); connect( d->m_iconColorDialog, SIGNAL(colorSelected(QColor)), this, SLOT(updateTextAnnotation()) ); connect( d->m_isBalloonVisible, SIGNAL(toggled(bool)), this, SLOT(updateTextAnnotation()) ); // Promote "Ok" button to default button. d->buttonBox->button( QDialogButtonBox::Ok )->setDefault( true ); connect( d->buttonBox->button( QDialogButtonBox::Ok ), SIGNAL(pressed()), this, SLOT(checkFields()) ); connect( this, SIGNAL(accepted()), SLOT(updateTextAnnotation()) ); connect( this, SIGNAL(accepted()), SLOT(updatePlacemarkAltitude()) ); connect( this, SIGNAL(finished(int)), SLOT(restoreInitial(int)) ); // Ensure that the dialog gets deleted when closing it (either when clicking OK or // Close). connect( this, SIGNAL(finished(int)), SLOT(deleteLater()) ); }
AddLinkDialog::AddLinkDialog( QWidget *parent ) : QDialog( parent ), d( new Private() ) { d->setupUi( this ); d->buttonBox->button( QDialogButtonBox::Ok )->setDefault( true ); connect( d->buttonBox->button( QDialogButtonBox::Ok ), SIGNAL(pressed()), this, SLOT(checkFields()) ); connect( this, SIGNAL(finished(int)), SLOT(deleteLater()) ); }
/* * addSensor( type, val1, val2, val3) - add sensor to frame * * Parameters: * type : Refers to the type of sensor data * val1 : indicates the sensor value as an int (int16_t) * val2 : indicates the sensor value as an int (int16_t) * val2 : indicates the sensor value as an int (int16_t) * * Returns: * 'length' of the composed frame when ok * -1 when the maximum length of the frame is reached * */ int8_t WaspFrame::addSensor(uint8_t type, int val1,int val2,int val3) { char str1[10]; char str2[10]; char str3[10]; if(_mode == ASCII) { // get name of sensor from table char name[10]; strcpy_P(name, (char*)pgm_read_word(&(SENSOR_TABLE[type]))); // convert from integer to string itoa( val1, str1, 10); itoa( val2, str2, 10); itoa( val3, str3, 10); // check if new sensor value fits in the frame or not // in the case the maximum length is reached, exit with error // if not, then add the new sensor length to the total length if(!checkLength( strlen(name) + strlen(":") + strlen(str1) + strlen(";") + strlen(str2) + strlen(";") + strlen(str3) + strlen("#") )) { return -1; } // concatenate sensor name to frame string strncat((char*)buffer, name, strlen(name)); strcat((char*)buffer, ":"); // concatenate sensor value to frame string strncat((char*)buffer, str1, strlen(str1)); strcat((char*)buffer, ";"); strncat((char*)buffer, str2, strlen(str2)); strcat((char*)buffer, ";"); strncat((char*)buffer, str3, strlen(str3)); strcat((char*)buffer, "#\0"); // increment sensor fields counter numFields++; // set sensor fields counter buffer[4]=numFields; } else { // check if the data input type corresponds to the sensor if( checkFields(type, TYPE_INT, 3) == -1 ) return -1; // set data bytes (in this case, int is two bytes) char valC1[2]; char valC2[2]; char valC3[2]; memcpy(valC1,&val1,2); memcpy(valC2,&val2,2); memcpy(valC3,&val3,2); // check if new sensor value fits 1+2+2+2 if(!checkLength(7)) { return -1; } // concatenate sensor name to frame string buffer[length-7] = (char)type; buffer[length-6] = valC1[0]; buffer[length-5] = valC1[1]; buffer[length-4] = valC2[0]; buffer[length-3] = valC2[1]; buffer[length-2] = valC3[0]; buffer[length-1] = valC3[1]; buffer[length] = '\0'; // increment sensor fields counter numFields++; // set sensor fields counter buffer[4]=numFields; } return length; }