Operating system requirements: iOS 5.0 or later.
Mobile device: iPad.
This example displays working with a dashboard data source and its container. After starting the example the following operations are executed:
Dashboard data source object is returned.
Identifier, key, name and number of data source object changes and its identifier in dashboard are determined.
A dictionary with dashboard data source settings is created.
A new object of dashboard data source is created based on the dictionary.
New identifier and key are applied to dashboard data source object.
Executing the example requires to place the following code instead of the executeExample method of the ViewController class (see the Displaying of Dashboard section):
-(void)executeExample { // Get array of dictionaries with settings of data source object container SNArray settings = m_dashboardReport->dataSourceObjects()->generatePlist()->qClass<NArray>(); // Create a container for dashboard data source objects SPPLDashboardDataSourceObjects dataSourceObjects = PPLDashboardDataSourceObjects::dataSourceObjects(settings); // Get first data source object SPPLDashboardDataSourceObject dataSourceObject = [self getDataSourceObjectFromObjects: dataSourceObjects ByIndex: 0]; // Display information about data source object [self showDataSourceObjectInfo: dataSourceObject]; // Try to open data source object with new identifier in dashboard SPPLDashboardDataSourceObject object = dataSourceObjects-> getObjectByDashboardRelatedId(dataSourceObject->dashboardRelatedId()); if (object != NULL) { printf("Data source object with identifier %s in dashboard is found \n", dataSourceObject->dashboardRelatedId()->UTF8String()); } else { printf("Data source object with identifier %s in dashboard it not found \n", dataSourceObject->dashboardRelatedId()->UTF8String()); } // Apply new identifier and key for first data source object [self applyId: NStr("OBJ128") AndKey: (NNumber::numberWithInt(128)) forDataSourceObjects: dataSourceObjects WithIndex: 0]; N_FOREACH(SPPLDashboardDataSourceObject, object, m_dashboardReport->dataSourceObjects()->objects()) { printf("New object identifier: %s \n", object->id()->UTF8String()); printf("New object key: %lld \n", object->key()); break; } } // Returns data source object by index -(SPPLDashboardDataSourceObject) getDataSourceObjectFromObjects: (SPPLDashboardDataSourceObjects) dataSourceObjects ByIndex: (int) index { // Get array of dashboard data source objects SNArray objects = dataSourceObjects->objects(); // Get identifier of first data source object SNString objectId = objects->objectAtIndex(index)->qClass<PPLDashboardDataSourceObject>()->id(); SPPLDashboardDataSourceObject dataSourceObject1 = dataSourceObjects->getObjectById(objectId); // Create a dictionary with settings of container including data source objects SNMutableDictionary plist = dataSourceObject1->generatePlist()->qClass<NMutableDictionary>(); // Set new identifier for first data source object plist->setObjectForKey(NStr("test"), NStr("id")); // Create a second data source object based on dictionary return PPLDashboardDataSourceObject::dataSourceObject(plist); } // Displays information about data source object -(void)showDataSourceObjectInfo: (SPPLDashboardDataSourceObject) dataSourceObject { printf("Data source object identifier: %s \n", dataSourceObject->id()->UTF8String()); printf("Data source object key: %lld \n", dataSourceObject->key()); printf("Data source object name: %s \n", dataSourceObject->name()->UTF8String()); printf("Number of data source object changes: %lld \n", dataSourceObject->changeCounter()); printf("Identifier of dashboard data source object identifier: %s \n", dataSourceObject->dashboardRelatedId()->UTF8String()); } // Apply changes to identifier and key of data source object with specified index -(void)applyId: (SNString) objectId AndKey: (SNNumber) objectKey forDataSourceObjects: (SPPLDashboardDataSourceObjects) dataSourceObjects WithIndex: (int) index { for(int i = 0; i < dataSourceObjects->objects()->count(); i++){ if (i == index) { SPPLDashboardDataSourceObject object = dataSourceObjects->objects()-> objectAtIndex<PPLDashboardDataSourceObject>(index); SNMutableDictionary idMapping = NMutableDictionary::mutableDictionaryWithObjectForKey(objectId, object->id()); SNMutableDictionary keyMapping = NMutableDictionary::mutableDictionaryWithObjectForKey(objectKey, object->id()); dataSourceObjects->applyIdsAndKeysChanges(idMapping, keyMapping); break; } } }
After executing the example the development environment console displays information about dashboard data source object:
Data source object identifier: OBJ9630
Data source object key: 9630
Data source object name: Socio-economic indicators
Number of data source object changes: 0
Identifier of data source object in dashboard: test
Data source object with the "test" identifier in dashboard is not found
New object identifier: OBJ128
New object key: 128
Example execution result remains the same if the code string
dataSourceObjects->applyIdsAndKeysChanges(idMapping, keyMapping);
is replaced with the following string:
m_dashboardReport->applyIdsAndKeysChanges(idMapping, keyMapping);
After executing the example new identifiers and keys are applied to dashboard data source objects.
See also: