Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/21/08 00:44:45 (16 years ago)
Author:
mstoeger
Message:

changed interface between model and view to support full and partial updates as decided in the last meeting (#316)

  • model.Columns property provides access to all values contained within the model for full updates
  • model.DataChanged event notifies the view of partial updates
Location:
trunk/sources/HeuristicLab.Visualization
Files:
2 added
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization/ChartDataRowsModel.cs

    r685 r697  
    77
    88namespace HeuristicLab.Visualization{
    9   public class ChartDataRowsModel : ChartDataModelBase, IChartDataRowsModel{
     9  public class ChartDataRowsModel : ChartDataModelBase, IChartDataRowsModel {
    1010
    1111    private readonly ListDictionary dataRows;
     
    2727    }
    2828
    29     public event ChartDataRowsModelDataChangedHandler DataChanged;
     29    public event ChartDataRowsModelColumnChangedHandler ColumnChanged;
     30
     31    private void RaiseColumnChanged(ChangeType type, long columnId, double[] values) {
     32      if (ColumnChanged != null) {
     33        ColumnChanged(type, columnId, values);
     34      }
     35    }
     36
     37    public List<ChartDataRowsModelColumn> Columns {
     38      get { throw new NotImplementedException(); }
     39    }
    3040  }
    3141}
  • trunk/sources/HeuristicLab.Visualization/HeuristicLab.Visualization.csproj

    r685 r697  
    6161    <Compile Include="ChartDataModelBase.cs" />
    6262    <Compile Include="ChartDataRowsModel.cs" />
    63     <Compile Include="ChartDataRowsModelDataChangedHandler.cs" />
     63    <Compile Include="ChartDataRowsModelColumn.cs" />
     64    <Compile Include="ChartDataRowsModelColumnChangedHandler.cs" />
    6465    <Compile Include="ChartDataRowsModelDummy.cs" />
    6566    <Compile Include="CompositeShape.cs" />
  • trunk/sources/HeuristicLab.Visualization/IChartDataRowsModel.cs

    r685 r697  
    1 namespace HeuristicLab.Visualization {
     1using System.Collections.Generic;
     2
     3namespace HeuristicLab.Visualization {
    24  public interface IChartDataRowsModel {
    3     event ChartDataRowsModelDataChangedHandler DataChanged;
     5    event ChartDataRowsModelColumnChangedHandler ColumnChanged;
     6    List<ChartDataRowsModelColumn> Columns { get; }
    47  }
    58}
  • trunk/sources/HeuristicLab.Visualization/LineChart.cs

    r684 r697  
    11using System;
    2 using System.Windows.Forms;
     2using HeuristicLab.Core;
    33
    44namespace HeuristicLab.Visualization {
    5   public partial class LineChart : UserControl {
    6     private IChartDataRowsModel model;
     5  public partial class LineChart : ViewBase {
     6    private readonly IChartDataRowsModel model;
    77
     8    /// <summary>
     9    /// This constructor shouldn't be called. Only required for the designer.
     10    /// </summary>
    811    public LineChart() {
    912      InitializeComponent();
    1013    }
    1114
    12     public IChartDataRowsModel Model {
    13       get { return model; }
    14       set {
    15         if (value == null) {
    16           throw new NullReferenceException("Model cannot be null.");
    17         }
     15    /// <summary>
     16    /// Initializes the chart.
     17    /// </summary>
     18    /// <param name="model"></param>
     19    public LineChart(IChartDataRowsModel model) : this() {
     20      if (model == null) {
     21        throw new NullReferenceException("Model cannot be null.");
     22      }
    1823
    19         if (model != null) {
    20           throw new InvalidOperationException("Model has already been set.");
    21         }
     24      this.model = model;
    2225
    23         model = value;
     26      Reset();
     27    }
    2428
    25         model.DataChanged += OnDataChanged;
     29    /// <summary>
     30    /// Resets the line chart by deleting all shapes and reloading all data from the model.
     31    /// </summary>
     32    private void Reset() {
     33      BeginUpdate();
     34
     35      // TODO clear existing shapes
     36
     37      // reload data from the model and create shapes
     38      foreach (ChartDataRowsModelColumn column in model.Columns) {
     39        AddColumn(column.ColumnId, column.Values);
     40      }
     41
     42      EndUpdate();
     43    }
     44
     45    /// <summary>
     46    /// Event handler which gets called when data in the model changes.
     47    /// </summary>
     48    /// <param name="type">Type of change</param>
     49    /// <param name="columnId">Id of the changed column</param>
     50    /// <param name="values">Values contained within the changed column</param>
     51    private void OnDataChanged(ChangeType type, long columnId, double[] values) {
     52      switch (type) {
     53        case ChangeType.Add:
     54          AddColumn(columnId, values);
     55          break;
     56        case ChangeType.Modify:
     57          ModifyColumn(columnId, values);
     58          break;
     59        case ChangeType.Remove:
     60          RemoveColumn(columnId);
     61          break;
     62        default:
     63          throw new ArgumentOutOfRangeException("type");
    2664      }
    2765    }
    2866
    29     private void OnDataChanged(ChangeType type, int dataId, double[] values) {
     67    /// <summary>
     68    /// Adds a new column to the chart.
     69    /// </summary>
     70    /// <param name="columnId">Id of the column</param>
     71    /// <param name="values">Values of the column</param>
     72    private void AddColumn(long columnId, double[] values) {
    3073      throw new NotImplementedException();
    3174    }
     75
     76    /// <summary>
     77    /// Modifies an existing column of the chart.
     78    /// </summary>
     79    /// <param name="columnId">Id of the column</param>
     80    /// <param name="values">Values of the column</param>
     81    private void ModifyColumn(long columnId, double[] values) {
     82      throw new NotImplementedException();
     83    }
     84
     85    /// <summary>
     86    /// Removes a column from the chart.
     87    /// </summary>
     88    /// <param name="columnId">Id of the column</param>
     89    private void RemoveColumn(long columnId) {
     90      throw new NotImplementedException();
     91    }
     92
     93    #region Add-/RemoveItemEvents
     94
     95    protected override void AddItemEvents() {
     96      base.AddItemEvents();
     97      model.ColumnChanged += OnDataChanged;
     98    }
     99
     100    protected override void RemoveItemEvents() {
     101      base.RemoveItemEvents();
     102      model.ColumnChanged -= OnDataChanged;
     103    }
     104
     105    #endregion
     106
     107    #region Begin-/EndUpdate
     108
     109    private int beginUpdateCount = 0;
     110
     111    public void BeginUpdate() {
     112      beginUpdateCount++;
     113    }
     114
     115    public void EndUpdate() {
     116      if (beginUpdateCount == 0) {
     117        throw new InvalidOperationException("Too many EndUpdates.");
     118      }
     119
     120      beginUpdateCount--;
     121
     122      if (beginUpdateCount == 0) {
     123        Invalidate();
     124      }
     125    }
     126
     127    #endregion
    32128  }
    33129}
Note: See TracChangeset for help on using the changeset viewer.