Quintiq file version 2.0
#parent: #root
Method ApplyConfigurationQuery (
  KpiQuery kpiQuery
) id:Method_FormKpiSnapshots_ApplyConfigurationQuery
{
  #keys: '[146450.3.312562815]'
  Body:
  [*
    // Applies the configuration query from a KpiQuery to radio button groups, List, checkbox and selector.
    // Query parameters
    RadioButtonGroupTimespan.BoundValue( kpiQuery.Timespan() );
    DateTimeSelectorFrom.DateTime( kpiQuery.DateTimeFrom() );
    DateTimeSelectorTo.DateTime( kpiQuery.DateTimeTo() );
    NumberPickerMaxResults.Number( kpiQuery.SnapshotLimit() );
    
    // Other
    CheckboxSelectAllSnapshots.Checked( kpiQuery.IsAllSnapshotSelected() );
    
    // Label filtering
    CheckboxEnableLabelFiltering.Checked( kpiQuery.IsLabelFilteringEnabled() );
    // Reset the selection 
    ListLabelFilter.ClearSelection();
    labelValues := construct( KpiLabelValues );
    traverse( kpiQuery.LabelFilters().Tokenize( "," ), Elements, labelvalue )
    {
      value := select( KpiTracker, Label.Value, lv, lv.Value() = labelvalue );
      if( not isnull( value ) )
      {
        ListLabelFilter.ExtendSelectByKey( value.Key() );
        labelValues.Add( value );
      }
    }
    DataHolderLabelFiltering.Data( labelValues.Copy() );
    
    // Kpi selection
    ListKpiSelection.ClearSelection();
    metaDatas := construct( KpiMetaDatas );
    traverse( kpiQuery.MetaDatas().Tokenize( "," ), Elements, metadata )
    {
      value := select( KpiTracker, MetaData, md, md.DisplayName() = metadata );
      if( not isnull( value ) )
      {
        ListKpiSelection.ExtendSelectByKey( value.Key() );
        metaDatas.Add( value );
      }
    }
    DataHolderKpiSelection.Data( metaDatas.Copy() );
    
    // Series selection
    kpiLabel := select( KpiTracker, Label, label, label.Name() = kpiQuery.SeriesSelection() );
    DropDownSeries.Data( guard( kpiLabel, null( KpiLabel ) ) );
    DataHolderSeriesSelection.Data( guard( kpiLabel, null( KpiLabel ) ) );
    CheckboxLastSnapshots.Checked( kpiQuery.IsOnlyLastSnapshotEnabled() );
    RadioButtonGroupTimeType.BoundValue( kpiQuery.Timetype() );
  *]
}
