#20 [svn] Indicator columns not treated as numbers

closed-fixed
Indicators (7)
5
2006-08-01
2006-07-25
No

Version: svn
Contact: mswilliamson@uwaterloo.ca

Columns that have indicators on them are not treated as numbers.

Discussion

  • Logged In: YES
    user_id=1281708

    Fixed with svn commit #228. Indicator columns are now right
    aligned like all other numeric columns.

    Index: src/libawf/variant.h

    --- src/libawf/variant.h (revision 209)
    +++ src/libawf/variant.h (working copy)
    @@ -88,6 +88,9 @@

    bool numeric() const;
    bool is_string() const;
    +
    + bool format_numeric() const;
    + void format_numeric(bool val);

    std::string format() const;
    void set_decimals(unsigned long val);
    @@ -130,6 +133,7 @@
    } _data;
    _variant_type _type;
    unsigned long _decimals;
    + bool _format_numeric;
    };

    class variant_test : public test
    Index: src/libawf/variant.cc
    ===================================================================
    --- src/libawf/variant.cc (revision 209)
    +++ src/libawf/variant.cc (working copy)
    @@ -22,42 +22,42 @@
    #include "debug.h"
    #include "stringutil.h"

    -libawf::variant::variant( const std::string & val ) :
    _decimals(2)
    +libawf::variant::variant( const std::string & val ) :
    _decimals(2), _format_numeric(false)
    {
    set_from(val);
    }

    -libawf::variant::variant( const char * str ) : _decimals(2)
    +libawf::variant::variant( const char * str ) :
    _decimals(2), _format_numeric(false)
    {
    set_from( std::string(str) );
    }

    -libawf::variant::variant( const double & val ) :
    _decimals(2)
    +libawf::variant::variant( const double & val ) :
    _decimals(2), _format_numeric(false)
    {
    set_from(val);
    }

    -libawf::variant::variant( unsigned long val ) :
    _decimals(2)
    +libawf::variant::variant( unsigned long val ) :
    _decimals(2), _format_numeric(false)
    {
    set_from(val);
    }

    -libawf::variant::variant( long val ) : _decimals(2)
    +libawf::variant::variant( long val ) : _decimals(2),
    _format_numeric(false)
    {
    set_from(val);
    }

    -libawf::variant::variant( float val ) : _decimals(2)
    +libawf::variant::variant( float val ) : _decimals(2),
    _format_numeric(false)
    {
    set_from(val);
    }

    -libawf::variant::variant( int val ) : _decimals(2)
    +libawf::variant::variant( int val ) : _decimals(2),
    _format_numeric(false)
    {
    set_from((long)val);
    }

    -libawf::variant::variant( ) : _decimals(2)
    +libawf::variant::variant( ) : _decimals(2),
    _format_numeric(false)
    {
    set_from(0L);
    }
    @@ -597,3 +597,13 @@
    {
    set_from( std::string(other) );
    }
    +
    +bool libawf::variant::format_numeric() const
    +{
    + return numeric() || _format_numeric;
    +}
    +
    +void libawf::variant::format_numeric(bool val)
    +{
    + _format_numeric = val;
    +}
    Index: src/libawf/dataeditconfview.h
    ===================================================================
    --- src/libawf/dataeditconfview.h (revision 209)
    +++ src/libawf/dataeditconfview.h (working copy)
    @@ -106,6 +106,7 @@
    virtual ~colour_indicator_transformation();
    virtual libawf::variant transform(const
    libawf::variant& v, const variable_table& v);
    virtual bool numeric() const;
    + virtual bool keep_numeric() const;
    private:
    expression* _e[2];
    std::string _colour[3];
    @@ -118,6 +119,7 @@
    virtual ~image_indicator_transformation();
    virtual libawf::variant transform(const
    libawf::variant& v, const variable_table& v);
    virtual bool numeric() const;
    + virtual bool keep_numeric() const;
    private:
    expression* _e[2];
    std::string _image[3];
    @@ -130,6 +132,7 @@
    virtual ~calculation_indicator_transformation();
    virtual libawf::variant transform(const
    libawf::variant& v, const variable_table& v);
    virtual bool numeric() const;
    + virtual bool keep_numeric() const;
    private:
    expression* _e;
    std::string _pre;
    Index: src/libawf/recordview.cc
    ===================================================================
    --- src/libawf/recordview.cc (revision 209)
    +++ src/libawf/recordview.cc (working copy)
    @@ -234,7 +234,20 @@
    // for example, totals may depend on them.
    if( numtrans[i] != NULL )
    {
    - r.set_column( i, numtrans[i]->transform(
    r.get_value(i), r ) );
    + if( numtrans[i]->keep_numeric() )
    + {
    + // In this case, if a column is formatted as
    a number
    + // it should stay formatted as a number under
    this trans-
    + // formation.
    + const variant& in = r.get_value(i);
    + variant v = numtrans[i]->transform( in, r );
    + if( in.format_numeric() )
    + v.format_numeric(true);
    + r.set_column( i, v );
    + }else
    + {
    + r.set_column( i, numtrans[i]->transform(
    r.get_value(i), r ) );
    + }
    }
    }

    @@ -259,7 +272,20 @@
    {
    if( trans[i] != NULL )
    {
    - trans_values[i] = trans[i]->transform(
    r.get_value(i), r );
    + if( trans[i]->keep_numeric() )
    + {
    + // In this case, if a column is formatted as
    a number
    + // it should stay formatted as a number under
    this trans-
    + // formation.
    + const variant& in = r.get_value(i);
    + variant v = trans[i]->transform( in, r );
    + if( in.format_numeric() )
    + v.format_numeric(true);
    + trans_values[i] = v;
    + }else
    + {
    + trans_values[i] = trans[i]->transform(
    r.get_value(i), r );
    + }
    }
    }

    @@ -338,12 +364,32 @@
    {
    if( numtrans[i] != NULL )
    {
    - r.set_column( i, numtrans[i]->transform(
    r.get_value(i), r ) );
    + if( numtrans[i]->keep_numeric() )
    + {
    + const variant& in = r.get_value(i);
    + variant v = numtrans[i]->transform( in, r );
    + if( in.format_numeric() )
    + v.format_numeric(true);
    + r.set_column( i, v );
    + }else
    + {
    + r.set_column( i, numtrans[i]->transform(
    r.get_value(i), r ) );
    + }
    }

    if( trans[i] != NULL )
    {
    - trans_values[i] = trans[i]->transform(
    r.get_value(i), r );
    + if( trans[i]->keep_numeric() )
    + {
    + const variant& in = r.get_value(i);
    + variant v = trans[i]->transform( in, r );
    + if( in.format_numeric() )
    + v.format_numeric(true);
    + trans_values[i] = v;
    + }else
    + {
    + trans_values[i] = trans[i]->transform(
    r.get_value(i), r );
    + }
    }
    }

    @@ -763,6 +809,11 @@
    return _t1->numeric();
    }

    +bool libawf::composite_transformation::keep_numeric() const
    +{
    + return _t1->keep_numeric();
    +}
    +
    bool libawf::calculated_column::run_late( ) const
    {
    return false;
    @@ -777,3 +828,7 @@
    {
    }

    +bool libawf::basic_transformation::keep_numeric() const
    +{
    + return false;
    +}
    Index: src/libawf/recordview.h
    ===================================================================
    --- src/libawf/recordview.h (revision 209)
    +++ src/libawf/recordview.h (working copy)
    @@ -48,6 +48,14 @@
    * @return
    */
    virtual bool numeric() const = 0;
    +
    + /**
    + * Return true from this function if, when a numeric
    column is
    + * input into this transformation it should remain
    numeric even
    + * after it has been transformed. This is used for
    example when
    + * a span is added around a numeric column. The
    default is false.
    + */
    + virtual bool keep_numeric() const;
    };

    class data_transformation : public basic_transformation
    @@ -240,6 +248,7 @@
    virtual ~composite_transformation();
    virtual libawf::variant transform(const
    libawf::variant& v, const variable_table& v);
    virtual bool numeric() const;
    + virtual bool keep_numeric() const;
    private:
    basic_transformation* _t1;
    basic_transformation* _t2;
    Index: src/libawf/htmltable.cc
    ===================================================================
    --- src/libawf/htmltable.cc (revision 209)
    +++ src/libawf/htmltable.cc (working copy)
    @@ -160,7 +160,7 @@
    os << "<td";
    else
    os << "<td class=\"" << te.style << "\"";
    - if( te.value.numeric() ) // all numeric values
    should be right aligned.
    + if( te.value.format_numeric() ) // all numeric
    values should be right aligned.
    os << " class=\"awf_numeric\"";
    os << ">";
    os << te.value.format();
    Index: src/libawf/dataeditconfview.cc
    ===================================================================
    --- src/libawf/dataeditconfview.cc (revision 227)
    +++ src/libawf/dataeditconfview.cc (working copy)
    @@ -1461,17 +1461,32 @@
    return false;
    }

    +bool
    libawf::colour_indicator_transformation::keep_numeric( )
    const
    +{
    + return true;
    +}
    +
    bool libawf::image_indicator_transformation::numeric( )
    const
    {
    return false;
    }

    +bool
    libawf::image_indicator_transformation::keep_numeric( )
    const
    +{
    + return true;
    +}
    +
    bool
    libawf::calculation_indicator_transformation::numeric( )
    const
    {
    return false; // The calculation is appended to the
    column, and therefor the result is
    // a string.
    }

    +bool
    libawf::calculation_indicator_transformation::keep_numeric( )
    const
    +{
    + return true;
    +}
    +
    bool libawf::grouping_column::run_late( ) const
    {
    return true;

     
    • labels: --> Indicators
    • milestone: --> Version 0.2.0 Pre-release
    • status: open --> closed-fixed
     
    • assigned_to: nobody --> mwilliamson