示例#1
0
QVariant AttributeDefinition::checkInput(const QVariant& inputVar, quint32 columnIndex)  const{
    QVariant actualval= inputVar;
    const ColumnDefinition& coldef = columndefinitionRef(columnIndex);
    QString typenm = inputVar.typeName();
    if ( !coldef.datadef().domain<>().isValid()){
        ERROR2(ERR_NO_INITIALIZED_2,"Domain",coldef.name());
        return QVariant();
    }
    IlwisTypes domtype = coldef.datadef().domain<>()->ilwisType();
    IlwisTypes valueType = coldef.datadef().domain<>()->valueType();
    IDomain dm = coldef.datadef().domain<>();
    if ( domtype == itITEMDOMAIN){
        if ( inputVar == sUNDEF){
            return QVariant((int)iUNDEF);
        } else if ( typenm == "QString"){
            actualval = dm->impliedValue(inputVar);

            SPItemRange rng2 = coldef.datadef().range<ItemRange>();

            if ( !hasType(valueType,itINDEXEDITEM)){
                SPItemRange rng1 = dm->range<ItemRange>();
                SPDomainItem item = rng1->item(inputVar.toString());
                if ( item.isNull()){
                    return QVariant((int)iUNDEF);
                }
                if ( !rng2->contains(item->name())){
                    rng2->add(item->clone());
                }
                actualval = item->raw();
            }
        }

    }else if ( domtype == itNUMERICDOMAIN){
        if (typenm == "QString")
            actualval =  dm->impliedValue(inputVar);
        if ( hasType(valueType,itDATETIME) && actualval.value<Ilwis::Time>() == tUNDEF)
            return actualval;
        else if (isNumericalUndef(actualval.toDouble()))
            return rUNDEF;
        if (! dm->contains(actualval))
            actualval = rUNDEF;
        else {
            SPNumericRange rng = coldef.datadef().range<NumericRange>();
            if ( !rng.isNull()){
                if ( hasType(valueType,itDATETIME))
                    rng->add(actualval.value<Ilwis::Time>());
                else
                    rng->add(actualval.toDouble());
            }
        }
    } else if ( domtype == itTEXTDOMAIN){
        return dm->impliedValue(inputVar);
    }
    return actualval;
}
示例#2
0
void BaseTable::adjustRange(int index) {

    ColumnDefinition& coldef = columndefinitionRef(index);
    if (!coldef.isValid())
        return;

    if( hasType(coldef.datadef().domain<>()->ilwisType(), itNUMERICDOMAIN)) {
        SPNumericRange rng = coldef.datadef().range<NumericRange>();
        std::vector<QVariant> values = column(coldef.id());
        if ( values.size() > 0 && !rng.isNull()) {
            double vmin=1e208, vmax=-1e208;
            bool hasfraction = true;
            for(const QVariant& var : values ){
                double v = var.toDouble();
                if ( !isNumericalUndef2(v, this))
                    vmin = std::min(vmin, v) ;
                v = var.toDouble();
                if (!isNumericalUndef2(v, this))                         {
                    vmax = std::max(vmax, v)    ;
                }
                hasfraction |= (v - (qint64)v != 0);

            }
            if ( vmin != 1e208 && vmax != -1e208) { //something has changed
                rng->min(vmin);
                rng->max(vmax);
                if (!hasfraction)
                    rng->resolution(1);
            }
        }
    } else if ( hasType(coldef.datadef().domain<>()->ilwisType(), itITEMDOMAIN)) {
        SPItemRange rng = coldef.datadef().range<ItemRange>();
        SPItemRange rngDomain = coldef.datadef().domain<>()->range<ItemRange>();
        std::vector<QVariant> values = column(coldef.id());
        if ( values.size() > 0 && !rng.isNull()) {
            rng->clear();
            for(auto qval : values) {
                quint32 id = qval.toUInt();
                SPDomainItem item = rngDomain->item(id);
                if ( !item.isNull()) {
                    rng->add(item->clone());
                }
            }
        }
    }
    coldef.changed(false);

}
void NumericItemRange::add(SPDomainItem item)
{
    if ( item.isNull() || !item->isValid() || item->valueType() != itNUMERICITEM)
        return;

    SPNumericItem nitem = item.staticCast<NumericItem>();
    for(auto iter = _items.rbegin(); iter != _items.rend(); ++iter) {
        if ( nitem->range() > (*iter)->range()) {
            if ( nitem->raw() == iUNDEF)
                nitem->_raw = _items.size();
            _items.insert(iter.base(),1, nitem );
            return;
        }
    }
    if ( _items.size() == 0) { // no overlapping items allowed; so the only case that is legal here is the first
        nitem->_raw = 0;
        _items.push_back(nitem);
    }
}