#include <HYDROData_StricklerTable.h>
#include <HYDROData_Tool.h>
+#include <HYDROData_Iterator.h>
#include <TDataStd_NamedData.hxx>
}
return QString();}
-void HYDROData_StricklerTable::SetAttrName( const QString& theAttrName ) const
+bool HYDROData_StricklerTable::SetAttrName( const QString& theAttrName ) const
{
+ HYDROData_Iterator anIt( HYDROData_Document::Document( myLab ), KIND_STRICKLER_TABLE );
+ for( ; anIt.More(); anIt.Next() )
+ {
+ Handle( HYDROData_StricklerTable ) aTable =
+ Handle( HYDROData_StricklerTable )::DownCast( anIt.Current() );
+ if( aTable->Label()==myLab )
+ continue;
+
+ if( theAttrName==aTable->GetAttrName() )
+ return false;
+ }
+
TDataStd_AsciiString::Set( myLab.FindChild( DataTag_AttrName ), HYDROData_Tool::toExtString( theAttrName ) );
+ return true;
}
QString HYDROData_StricklerTable::GetAttrValue( const QString& theType ) const
QString HYDROData_StricklerTable::GetType( const QString& theAttrValue ) const
{
+ if( theAttrValue.isEmpty() )
+ return "";
+
Handle( TDataStd_NamedData ) aMap = Map();
TCollection_ExtendedString anAttrValue = HYDROData_Tool::toExtString( theAttrValue );
for( TDataStd_DataMapIteratorOfDataMapOfStringString it( aMap->GetStringsContainer() ); it.More(); it.Next() )
int b = theColor.blue();
int aColorInt = ( r<<16 ) + ( g<<8 ) + b;
aMap->SetInteger( aType, aColorInt );
+
+ // synchronize the color for the same type in other maps
+ HYDROData_Iterator anIt( HYDROData_Document::Document( myLab ), KIND_STRICKLER_TABLE );
+ for( ; anIt.More(); anIt.Next() )
+ {
+ Handle( HYDROData_StricklerTable ) aTable =
+ Handle( HYDROData_StricklerTable )::DownCast( anIt.Current() );
+ if( aTable->Label()==myLab )
+ continue;
+
+ if( aTable->HasType( theType ) )
+ aTable->Map()->SetInteger( aType, aColorInt );
+ }
}
aDoc->Close();
}
+void test_HYDROData_StricklerTable::test_type_by_attr()
+{
+ Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+
+ Handle(HYDROData_StricklerTable) aTable =
+ Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
+
+ CPPUNIT_ASSERT_EQUAL( true, aTable->Import( DEF_STR_PATH ) );
+
+ CPPUNIT_ASSERT_EQUAL( QString( "Zones de champs cultivé à végétation basse" ), aTable->GetType( "512" ) );
+ CPPUNIT_ASSERT_EQUAL( QString( "" ), aTable->GetType( "123" ) );
+ CPPUNIT_ASSERT_EQUAL( QString( "" ), aTable->GetType( "" ) );
+
+ aDoc->Close();
+}
+
+void test_HYDROData_StricklerTable::test_unique_attr_name()
+{
+ Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+
+ Handle(HYDROData_StricklerTable) aTable1 =
+ Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
+ Handle(HYDROData_StricklerTable) aTable2 =
+ Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
+
+ CPPUNIT_ASSERT_EQUAL( true, aTable1->SetAttrName( "CODE_06" ) );
+ CPPUNIT_ASSERT_EQUAL( QString( "CODE_06" ), aTable1->GetAttrName() );
+ CPPUNIT_ASSERT_EQUAL( QString( "" ), aTable2->GetAttrName() );
+
+ CPPUNIT_ASSERT_EQUAL( false, aTable2->SetAttrName( "CODE_06" ) );
+ CPPUNIT_ASSERT_EQUAL( QString( "CODE_06" ), aTable1->GetAttrName() );
+ CPPUNIT_ASSERT_EQUAL( QString( "" ), aTable2->GetAttrName() );
+
+ CPPUNIT_ASSERT_EQUAL( true, aTable2->SetAttrName( "CODE_07" ) );
+ CPPUNIT_ASSERT_EQUAL( QString( "CODE_06" ), aTable1->GetAttrName() );
+ CPPUNIT_ASSERT_EQUAL( QString( "CODE_07" ), aTable2->GetAttrName() );
+
+ CPPUNIT_ASSERT_EQUAL( false, aTable1->SetAttrName( "CODE_07" ) );
+ CPPUNIT_ASSERT_EQUAL( QString( "CODE_06" ), aTable1->GetAttrName() );
+ CPPUNIT_ASSERT_EQUAL( QString( "CODE_07" ), aTable2->GetAttrName() );
+
+ aDoc->Close();
+}
+
+void test_HYDROData_StricklerTable::test_colors_sync()
+{
+ Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1);
+
+ Handle(HYDROData_StricklerTable) aTable1 =
+ Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
+ Handle(HYDROData_StricklerTable) aTable2 =
+ Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) );
+
+ aTable1->Set( "test1", 10 );
+ aTable1->Set( "test2", 20 );
+ aTable1->SetColor( "test1", QColor( 255, 0, 0 ) );
+ aTable1->SetColor( "test2", QColor( 255, 0, 1 ) );
+ CPPUNIT_ASSERT_EQUAL( QColor( 255, 0, 0 ), aTable1->GetColor( "test1" ) );
+ CPPUNIT_ASSERT_EQUAL( QColor( 255, 0, 1 ), aTable1->GetColor( "test2" ) );
+
+ aTable2->Set( "test1", 15 );
+ aTable2->SetColor( "test1", QColor( 255, 255, 0 ) );
+ CPPUNIT_ASSERT_EQUAL( QColor( 255, 255, 0 ), aTable1->GetColor( "test1" ) );
+ CPPUNIT_ASSERT_EQUAL( QColor( 255, 255, 0 ), aTable2->GetColor( "test1" ) );
+
+ aDoc->Close();
+}