void TestQgsFields::field() { QgsField original; original.setName( "name" ); original.setType( QVariant::Int ); original.setLength( 5 ); original.setPrecision( 2 ); //test constructors for QgsFields::Field QgsFields::Field fieldConstructor1( original, QgsFields::OriginJoin, 5 ); QCOMPARE( fieldConstructor1.field, original ); QCOMPARE( fieldConstructor1.origin, QgsFields::OriginJoin ); QCOMPARE( fieldConstructor1.originIndex, 5 ); QgsFields::Field fieldConstructor2; QCOMPARE( fieldConstructor2.origin, QgsFields::OriginUnknown ); QCOMPARE( fieldConstructor2.originIndex, -1 ); //test equality operators QgsFields::Field field1( original, QgsFields::OriginJoin, 5 ); QgsFields::Field field2( original, QgsFields::OriginJoin, 5 ); QVERIFY( field1 == field2 ); QgsFields::Field field3( original, QgsFields::OriginEdit, 5 ); QVERIFY( field1 != field3 ); QgsFields::Field field4( original, QgsFields::OriginJoin, 6 ); QVERIFY( field1 != field4 ); }
void tst_QSqlField::setValue() { QSqlField field1 ( "test", QVariant::Int ); QSqlField field2 ( "test", QVariant::String ); QSqlField field3 ( "test", QVariant::Bool ); QSqlField field4 ( "test", QVariant::Double ); field1.clear(); QFETCH( int, ival ); QFETCH( QString, sval ); QFETCH( double, dval ); QFETCH( bool, bval ); field1.setValue( ival ); QCOMPARE( field1.value().toInt(), ival ); // setValue should also reset the NULL flag QVERIFY( !field1.isNull() ); field2.setValue( sval ); QCOMPARE( field2.value().toString(), sval ); field3.setValue( QVariant( bval) ); QVERIFY( field3.value().toBool() == bval ); field4.setValue( dval ); QCOMPARE( field4.value().toDouble(), dval ); field4.setReadOnly( true ); field4.setValue( "Something_that's_not_a_double" ); QCOMPARE( field4.value().toDouble(), dval ); }
void tst_QSqlField::operator_Equal() { QSqlField field1( "test", QVariant::String ); QSqlField field2( "test2", QVariant::String ); QSqlField field3( "test", QVariant::Int ); QSqlField field4("test", QVariant::String, QString("ATable")); QSqlField field5("test2", QVariant::String, QString("ATable")); QSqlField field6("test", QVariant::String, QString("BTable")); QVERIFY( !(field1 == field2) ); QVERIFY( !(field1 == field3) ); QVERIFY(field1 != field4); QVERIFY(field1 != field5); QVERIFY(field1 != field6); QVERIFY(field4 != field5); QVERIFY(field4 != field6); field2.setName( "test" ); QVERIFY( field1 == field2 ); QVERIFY( field1 == field2 ); field1.setValue( "Harry" ); QVERIFY( !(field1 == field2) ); field2.setValue( "Harry" ); QVERIFY( field1 == field2 ); field1.setReadOnly( true ); QVERIFY( !(field1 == field2) ); field2.setReadOnly( true ); QVERIFY( field1 == field2 ); field4.setTableName("BTable"); QCOMPARE(field4, field6); field6.setName("test3"); QVERIFY(field4 != field6); }
void TargetsDialog::createTargetFromSelection() { if (StelApp::getInstance().getStelObjectMgr().getWasSelected()) { QList<StelObjectP> selectedObjects = StelApp::getInstance().getStelObjectMgr().getSelectedObject(); QListIterator<StelObjectP> objectIterator(selectedObjects); StelCore* core = StelApp::getInstance().getCore(); while (objectIterator.hasNext()) { StelObjectP stelObject = objectIterator.next(); QString type = stelObject->getType(); QString englishName = stelObject->getEnglishName(); if (englishName == "") { englishName = "No Name"; } float magnatude = stelObject->getVMagnitude(core); double angularSize = stelObject->getAngularSize(core); Vec3d pos; double ra, dec; // ra/dec in J2000 pos = stelObject->getJ2000EquatorialPos(core); StelUtils::rectToSphe(&ra, &dec, pos); QSqlField field1("name", QVariant::String); QSqlField field2("right_ascension", QVariant::Double); QSqlField field3("declination", QVariant::Double); QSqlField field4("target_type_id", QVariant::Int); QSqlField field5("magnitude", QVariant::Double); QSqlField field6("size", QVariant::Double); field1.setValue(QVariant(englishName)); field2.setValue(QVariant(ra)); field3.setValue(QVariant(dec)); field4.setValue(QVariant(1)); field5.setValue(QVariant(magnatude)); field6.setValue(QVariant(angularSize)); QSqlRecord newRecord = QSqlRecord(); newRecord.append(field1); newRecord.append(field2); newRecord.append(field3); newRecord.append(field4); newRecord.append(field5); newRecord.append(field6); if (tableModel->insertRecord(-1, newRecord)) { ui->targetsListView->setCurrentIndex(tableModel->index(tableModel->rowCount() - 1, 1)); } else { qWarning() << "LogBook: could not insert new target. The error is: " << tableModel->lastError(); } } } else { qDebug() << "====> Nothing selected."; } }
void tst_QSqlField::operator_Assign() { QSqlField field1( "test", QVariant::String ); field1.setValue( "Harry" ); field1.setReadOnly( true ); QSqlField field2 = field1; QVERIFY( field1 == field2 ); QSqlField field3( "test", QVariant::Double ); field3.clear(); field1 = field3; QVERIFY( field1 == field3 ); QSqlField field4("test", QVariant::String, "ATable"); field1 = field4; QVERIFY(field1 == field4); }
void TestQgsFields::extend() { QgsFields destination; QgsField field( "testfield" ); destination.append( field ); QgsField field2( "testfield2" ); destination.append( field2 ); QgsFields source; QgsField field3( "testfield3" ); source.append( field3, QgsFields::OriginJoin, 5 ); QgsField field4( "testfield4" ); source.append( field4 ); QCOMPARE( destination.count(), 2 ); destination.extend( source ); QCOMPARE( destination.count(), 4 ); QCOMPARE( destination.at( 2 ), field3 ); QCOMPARE( destination.at( 3 ), field4 ); }
void TestQgsFields::fieldOriginIndex() { QgsFields fields; QgsField field( QString( "testfield" ) ); fields.append( field , QgsFields::OriginProvider, 5 ); QCOMPARE( fields.fieldOriginIndex( 0 ), 5 ); QgsField field2( QString( "testfield2" ) ); fields.append( field2, QgsFields::OriginProvider, 10 ); QCOMPARE( fields.fieldOriginIndex( 1 ), 10 ); QgsField field3( QString( "testfield3" ) ); //field origin index not specified with OriginProvider, should be automatic fields.append( field3, QgsFields::OriginProvider ); QCOMPARE( fields.fieldOriginIndex( 2 ), 2 ); QgsField field4( QString( "testfield4" ) ); //field origin index not specified with other than OriginProvider, should remain -1 fields.append( field4, QgsFields::OriginEdit ); QCOMPARE( fields.fieldOriginIndex( 3 ), -1 ); }
void TargetsDialog::insertNewTarget() { QSqlField field1("name", QVariant::String); QSqlField field3("right_ascension", QVariant::Double); QSqlField field4("declination", QVariant::Double); QSqlField field6("target_type_id", QVariant::Int); field1.setValue(QVariant("name")); field3.setValue(QVariant(0.0)); field4.setValue(QVariant(0.0)); field6.setValue(QVariant(1)); QSqlRecord newRecord = QSqlRecord(); newRecord.append(field1); newRecord.append(field3); newRecord.append(field4); newRecord.append(field6); if (tableModel->insertRecord(-1, newRecord)) { ui->targetsListView->setCurrentIndex(tableModel->index(tableModel->rowCount() - 1, 1)); } else { qWarning() << "LogBook: could not insert new target. The error is: " << tableModel->lastError(); } }