Beispiel #1
0
bool SelectionBase::ExpressionPart::match(const SPFeatureI &feature,SelectionBase *operation) const
{
    if ( _type == ExpressionPart::ptFEATURETYPE){
        return hasType(feature->geometryType(), _geometryType);
    }
    if ( _type == ExpressionPart::ptENVELOPE && _envelope.isValid())   {
        return _envelope.contains(feature->geometry().get());
    }
    if ( _type == ExpressionPart::ptPOLYGON && _polygon.get() != 0)   {
        return _polygon->contains(feature->geometry().get());
    }

    if ( _type == ExpressionPart::ptATTRIBUTESELECTION )   {
        QVariant val = feature(_leftSide);
        ColumnDefinition coldef = feature->attributedefinition(_leftSide);
        if ( coldef.datadef().domain()->ilwisType() == itITEMDOMAIN){
            val = coldef.datadef().domain()->impliedValue(val);
        }
        if ( QString(val.typeName()) == "QString" && QString(_rightSide.typeName()) == "QString"){
            return operation->compare1(_operator,val.toString(), _rightSide.toString());
        } else {
            bool ok1,ok2;
            double v1 = val.toDouble(&ok1);
            double v2 = _rightSide.toDouble(&ok2);
            bool ok3 = operation->compare2(_operator, v1, v2, true);
            return ok1&& ok2 && ok3;
        }
    }
    return false;
}
Beispiel #2
0
Qt::ItemFlags TableModel::flags(const QModelIndex &index) const
{
	Qt::ItemFlags flags = QAbstractTableModel::flags(index);
	if(index.isValid()) {
		bool can_edit = false;
		ColumnDefinition cd = m_columns.value(index.column());
		if(!cd.isNull()) {
			can_edit = !cd.isReadOnly();
			if(!cd.isVirtual()) {
				qfu::Table::Field field = tableField(index.column());
				if(!field.isNull()) {
					can_edit = can_edit && field.canUpdate();
					int type = columnType(index.column());
					// BLOB fields cannot be edited in grid.
					//can_edit = can_edit && (type != QVariant::ByteArray);
					if(type == QVariant::Bool) {
						flags |= Qt::ItemIsUserCheckable;// << Qt::ItemIsEnabled;
					}
				}
				else {
					can_edit = false;
				}
			}
		}
		if(can_edit)
			flags |= Qt::ItemIsEditable;
		else
			flags &= ~Qt::ItemIsEditable;
		//qfInfo() << cd.fieldName() << flags << "checkable:" << (flags & Qt::ItemIsUserCheckable);
	}
	return flags;
}
QString IlwisObjectModel::valuetype() const
{
    try{
        if ( !_ilwisobject.isValid())
            return "";

        IlwisTypes objectype = _ilwisobject->ilwisType();
        IlwisTypes valueType = itUNKNOWN;
        if ( hasType( objectype, itCOVERAGE|itDOMAIN)){
            if ( objectype == itRASTER){
                IRasterCoverage raster = _ilwisobject.as<RasterCoverage>();
                valueType = raster->datadef().domain()->valueType();
            } else if ( hasType( objectype , itFEATURE)){
                IFeatureCoverage features = _ilwisobject.as<FeatureCoverage>();
                ColumnDefinition coldef = features->attributeDefinitions().columndefinition(COVERAGEKEYCOLUMN);
                if ( coldef.isValid()){
                    valueType = coldef.datadef().domain()->valueType();
                }

            } else if ( hasType( objectype , itDOMAIN)){
                IDomain dom = _ilwisobject.as<Domain>();
                valueType = dom->valueType();

            }
        }
        QString typeName =  TypeHelper::type2HumanReadable(valueType);

        return typeName == sUNDEF ? "" : typeName;
    }catch(const ErrorObject& ){
        // no exceptions may escape here
    }
    return "";
}
bool Ilwis::Postgresql::PostgresqlDatabaseUtil::exists(Ilwis::SPFeatureI feature) const
{
    PostgresqlDatabaseUtil pgUtil(_resource,_options);
    SqlStatementHelper sqlHelper(pgUtil);

    QString where;
    QList<QString> primaryKeys;
    getPrimaryKeys(primaryKeys);
    Record record = feature->record();
    foreach (QString primaryKey, primaryKeys) {
        if (where.isEmpty()) {
            where.append(" WHERE ");
        } else {
            where.append(" AND ");
        }
        ColumnDefinition coldef = feature->attributedefinition(primaryKey);
        QVariant value = record.cell(coldef.columnindex());

        where.append(primaryKey).append(" = ");
        where.append(sqlHelper.createInsertValueString(value, coldef));
    }

    QString sql = "SELECT ";
    //sql.append(" count(").append(primaryKeys.at(0)).append(") ");
    sql.append(QStringList(primaryKeys).join(","));
    sql.append(" FROM ").append(qTableFromTableResource());
    sql.append(where);

    QSqlQuery query = doQuery(sql, "exists");
    return query.next();
}
ColumnDefinition::ColumnDefinition(const ColumnDefinition& coldef){
    if(coldef.__bool__())
    {
        Ilwis::ColumnDefinition* ilwDef = coldef.ptr().get();
        if(ilwDef->isValid())
            _ilwisColDef.reset(new Ilwis::ColumnDefinition(*ilwDef));
    }
}
Beispiel #6
0
Qt::ItemFlags RunsTableModel::flags(const QModelIndex &index) const
{
	Qt::ItemFlags flgs = Super::flags(index);
	ColumnDefinition cd = columnDefinition(index.column());
	if(cd.matchesSqlId(QStringLiteral("startTimeMs"))) {
		flgs = Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | flgs;
		//qfInfo() << flgs;
	}
	return flgs;
}
Beispiel #7
0
void
Grid::PostRender (Context *ctx, Region *region, bool skip_children)
{
	// render our chidren if we need to
	if (!skip_children) {
		VisualTreeWalker walker = VisualTreeWalker (this, ZForward, false);
		while (UIElement *child = walker.Step ())
			child->DoRender (ctx, region);
	}
	
	if (GetShowGridLines () && ctx->IsMutable ()) {
		double offset = 0;
		double dash = 4;
		ColumnDefinitionCollection *cols = GetColumnDefinitionsNoAutoCreate ();
		RowDefinitionCollection *rows = GetRowDefinitionsNoAutoCreate ();
		cairo_t *cr = ctx->Cairo ();
		int col_count = cols ? cols->GetCount () : 0;
		int row_count = rows ? rows->GetCount () : 0;
		
		cairo_save (cr);
		RenderLayoutClip (cr);
		cairo_set_line_width(cr, 1.0);
		// Initially render a blue color
		cairo_set_dash (cr, &dash, 1, offset);
		cairo_set_source_rgb (cr, 0.4, 0.4, 1.0);
		cairo_new_path (cr);

		// Draw gridlines between each pair of columns/rows
		for (int count = 0; count < 2; count++) {
			for (int i = 0, offset = 0; i < col_count - 1; i++) {
				ColumnDefinition *def = cols->GetValueAt (i)->AsColumnDefinition ();
				offset += def->GetActualWidth ();
				cairo_move_to (cr, offset, 0);
				cairo_line_to (cr, offset, GetActualHeight ());
			}
			
			for (int i = 0, offset = 0; i < row_count - 1; i++) {
				RowDefinition *def = rows->GetValueAt (i)->AsRowDefinition ();
				offset += def->GetActualHeight ();
				cairo_move_to (cr, 0, offset);
				cairo_line_to (cr, GetActualWidth (), offset);
			}
			
			cairo_stroke (cr);
			
			// For the second pass render a yellow color in the gaps between the previous dashes
			cairo_set_dash (cr, &dash, 1, dash);
			cairo_set_source_rgb (cr, 1.0, 1.0, 0.3);
		}
		cairo_restore (cr);
	}		

	// Chain up, but skip children since we've already rendered them here.
	UIElement::PostRender (ctx, region, true);
}
Beispiel #8
0
bool BaseTable::addColumn(const ColumnDefinition& def){
    if ( _columnDefinitionsByName.contains(def.name())) {
        kernel()->issues()->log(TR("Adding duplicate column %1").arg(name()),IssueObject::itWarning);
        return false;
    }
    _columnDefinitionsByName[def.name()] = def;
    _columnDefinitionsByIndex[def.id()] = _columnDefinitionsByName[def.name()];
    _columns = _columnDefinitionsByName.size();

    return true;
}
Beispiel #9
0
void SqlTableModel::removeAllColumnsFunction(QQmlListProperty<TableModelColumn> *list_property)
{
	qfLogFuncFrame();
	SqlTableModel *that = static_cast<SqlTableModel*>(list_property->object);
	while (that->columnCount()) {
		ColumnDefinition cd = that->removeColumn(0);
		QF_ASSERT(cd.isNull(), "Error removing column", break);
	}
	qDeleteAll(that->m_columns);
	that->m_columns.clear();
}
bool AttributeDefinition::addColumn(const ColumnDefinition& def){

    if ( _columnDefinitionsByName.find(def.name()) != _columnDefinitionsByName.end()) { // no duplicates
        return false;
    }
    ColumnDefinition coldef = def;
    coldef.columnindex(_columnDefinitionsByIndex.size());
    _columnDefinitionsByName[coldef.name()] = _columnDefinitionsByIndex.size();
    _columnDefinitionsByIndex.push_back(coldef);

    return true;
}
QString IlwisObjectModel::rangeDefinition(bool defaultRange, bool calc, const QString& columnName) {
    try {
        IlwisTypes objectype = _ilwisobject->ilwisType();
        QString rangeString;
        if ( hasType( objectype, itCOVERAGE|itDOMAIN)){
            if ( objectype == itRASTER){
                IRasterCoverage raster = _ilwisobject.as<RasterCoverage>();
                if ( defaultRange){
                  rangeString = raster->datadef().domain()->range()->toString();
                }else{
                    if ( calc){
                        raster->loadData();
                        raster->statistics(NumericStatistics::pBASIC);
                    }
                  rangeString = raster->datadef().range()->toString();
                }
            } else if ( hasType( objectype , itFEATURE)){
                IFeatureCoverage features = _ilwisobject.as<FeatureCoverage>();
                ColumnDefinition coldef = features->attributeDefinitions().columndefinition(COVERAGEKEYCOLUMN);
                if ( coldef.isValid()){
                    if ( defaultRange)
                      rangeString =  coldef.datadef().domain()->range()->toString();
                    else{
                        if ( calc){
                            features->loadData();
                            std::vector<QVariant> data = features->attributeTable()->column(columnName);
                            if ( data.size() != 0){
                                std::vector<double> values(data.size());
                                int  i=0;
                                for(auto v : data)
                                    values[i++] = v.toDouble();
                                NumericStatistics stats; // realy like to do this with a template specialization of the proper calculate function, but the syntax was unclear to me
                                stats.calculate(values.begin(), values.end());
                                NumericRange *rng = new NumericRange(stats.prop(NumericStatistics::pMIN),stats.prop(NumericStatistics::pMAX));
                                features->attributeDefinitionsRef().columndefinitionRef(columnName).datadef().range(rng);
                            }
                        }
                        rangeString = coldef.datadef().range()->toString();
                    }
                }

            } else if ( hasType( objectype , itDOMAIN)){
                rangeString = _ilwisobject.as<Domain>()->range()->toString();
            }
        }
        return rangeString;
    }catch(const ErrorObject& ){
        // no exceptions may escape here
    }
    return "";

}
void CreateTableSqlStatementBuilder::addColumnDefinition(const Utf8String &columnName,
                                                         ColumnType columnType,
                                                         bool isPrimaryKey)
{
    sqlStatementBuilder.clear();

    ColumnDefinition columnDefinition;
    columnDefinition.setName(columnName);
    columnDefinition.setType(columnType);
    columnDefinition.setIsPrimaryKey(isPrimaryKey);

    columnDefinitions.append(columnDefinition);
}
Beispiel #13
0
QVariant TableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
	static QIcon ico_dirty(QPixmap(":/qf/core/images/pencil.png"));
	//static QIcon ico_filter(QPixmap(":/libqfgui/images/filter.png"));
	QVariant ret;
	if(orientation == Qt::Horizontal) {
		if(role == Qt::DisplayRole || role == Qt::EditRole) {
			ColumnDefinition cd = m_columns.value(section);
			QF_ASSERT(!cd.isNull(),
					  QString("Invalid horizontal section number: %1").arg(section),
					  return ret);
			ret = cd.caption();
		}
		else if(role == Qt::DecorationRole) {
UINT TableDefinition::adjustOffset(ColumnDefinition &colDef) {
  colDef.m_offset = m_recSize;
  ULONG fieldSize = colDef.size();
  switch(colDef.getType()) {
  case DBTYPE_VARCHAR :
  case DBTYPE_VARCHARN:
    break;
  default:
    colDef.m_len = fieldSize;
    break;
  }
  if(isNullAllowed(colDef.getType())) {
    fieldSize++; /* make space for the indicator */
  }
  return fieldSize;
}
QString PostgresqlTableConnector::createInsertValueString(QVariant value, const ColumnDefinition &coldef) const {
    IDomain domain = coldef.datadef().domain<>();
    if (hasType(domain->valueType(),itINTEGER)) {

        return QString::number(value.toInt());

    } else if (hasType(domain->valueType(),itDOUBLE | itFLOAT)) {

        return QString::number(value.toDouble());

    } else if (hasType(domain->valueType(),itTHEMATICITEM | itNAMEDITEM | itINDEXEDITEM | itNUMERICITEM | itTIMEITEM)) {

        return domain->impliedValue(value).toString();

    } else if (hasType(domain->valueType(), itDATETIME)) {
        if ( QString(value.typeName()).compare("Ilwis::Time") != 0){
            ERROR2(ERR_COULD_NOT_CONVERT_2,value.toString(), "time");
            Time time(0,0,0,0,0);
            return time.toString(itDATE);
        } else{
            Time time = value.value<Ilwis::Time>();
            return time.toString(itDATETIME);
        }
    } else if (hasType(domain->valueType(),itSTRING)){

        return QString("'%1'").arg(value.toString());

    } else {
        ERROR0("Could not determine data type.");
        return QString("");
    }
}
Beispiel #16
0
Ilwis::OperationImplementation::State SetAttributeTable::prepare(ExecutionContext *ctx, const SymbolTable &st)
{
    OperationImplementation::prepare(ctx,st);

    OperationHelper::check([&] ()->bool { return _inputTable.prepare(_expression.input<QString>(0), itTABLE); },
    {ERR_COULD_NOT_LOAD_2,_expression.input<QString>(0), "" } );

    OperationHelper::check([&] ()->bool { return _inputRaster.prepare(_expression.input<QString>(1), itRASTER); },
    {ERR_COULD_NOT_LOAD_2,_expression.input<QString>(1), "" } );

    _primaryKey = _expression.input<QString>(2);

    int index = _inputTable->columnIndex(_primaryKey);
    if ( index == iUNDEF){
        kernel()->issues()->log(TR("Table doesnt contain column ") + _primaryKey);
        return sPREPAREFAILED;
    }
    std::vector<QVariant> values = _inputTable->column(_primaryKey);
    std::set<QVariant> uniques;
    int undefs = 0;
    for(QVariant v : values){
        if ( isNumericalUndef(v.toDouble()))
            ++undefs;
        else
            uniques.insert(v);
    }
    if ( (uniques.size() + undefs ) != values.size()){
        kernel()->issues()->log(TR("Key column must not contain duplicate values"));
        return sPREPAREFAILED;
    }

    ColumnDefinition coldef = _inputTable->columndefinition(index);
    if ( !coldef.datadef().domain()->isCompatibleWith(_inputRaster->datadef().domain().ptr())){
        kernel()->issues()->log(TR("Key column doesnt match raster domain ") + _primaryKey);
        return sPREPAREFAILED;
    }

    OperationHelperRaster helper;
    helper.initialize(_inputRaster, _outputRaster, itRASTERSIZE | itENVELOPE | itCOORDSYSTEM | itGEOREF|itDOMAIN);

    for(quint32 i = 0; i < _outputRaster->size().zsize(); ++i){
        QString index = _outputRaster->stackDefinition().index(i);
        DataDefinition datadef = _outputRaster->datadef(i);
        _outputRaster->setBandDefinition(index,DataDefinition(datadef.domain(), datadef.range()->clone()));
    }
    return sPREPARED;
}
Beispiel #17
0
QVariant SqlTableModel::data(const QModelIndex &index, int role) const
{
	if(role == Qt::DisplayRole) {
		ColumnDefinition cd = columnDefinition(index.column());
		int cast_type = cd.castType();
		if(cast_type == qMetaTypeId<qf::core::sql::DbEnum>()) {
			DbEnumCastProperties props(cd.castProperties());
			QString group_name = props.groupName();
			if(!group_name.isEmpty()) {
				QVariant v = data(index, Qt::EditRole);
				sql::DbEnumCache& db_enum_cache = qf::core::sql::DbEnumCache::instanceForConnection(connectionName());
				QString group_id = v.toString();
				sql::DbEnum dbe = db_enum_cache.dbEnum(group_name, group_id);
				QString caption_format = props.captionFormat();
				QString caption = dbe.fillInPlaceholders(caption_format);
				return caption;
			}
		}
	}
	else if(role == Qt::BackgroundColorRole) {
		ColumnDefinition cd = columnDefinition(index.column());
		int cast_type = cd.castType();
		if(cast_type == qMetaTypeId<qf::core::sql::DbEnum>()) {
			DbEnumCastProperties props(cd.castProperties());
			QString group_name = props.groupName();
			if(!group_name.isEmpty()) {
				QVariant v = data(index, Qt::EditRole);
				QString group_id = v.toString();
				if(!group_id.isEmpty()) {
					sql::DbEnumCache& db_enum_cache = qf::core::sql::DbEnumCache::instanceForConnection(connectionName());
					sql::DbEnum dbe = db_enum_cache.dbEnum(group_name, group_id);
					QColor color = dbe.color();
					if(color.isValid())
						return color;
				}
			}
			return QVariant();
		}
	}
	else if(role == Qt::TextColorRole) {
		ColumnDefinition cd = columnDefinition(index.column());
		int cast_type = cd.castType();
		if(cast_type == qMetaTypeId<qf::core::sql::DbEnum>()) {
			QVariant v = data(index, Qt::BackgroundRole);
			if(v.isValid()) {
				QColor bgr_color = v.value<QColor>();
				if(bgr_color.isValid()) {
					return contrastTextColor(bgr_color);
				}
			}
		}
	}
	QVariant ret = Super::data(index, role);
	return ret;
}
bool FeatureConnector::storeMetaData(FeatureCoverage *fcov, IlwisTypes type) {
    if ( type == 0)
        return false;
    DataDefinition datadef;

    ITable attTable = fcov->attributeTable();
    ColumnDefinition coldef = attTable->columndefinition(COVERAGEKEYCOLUMN);
    if ( coldef.isValid()) {
        datadef = coldef.datadef();
    } else {
        IIndexedIdDomain indexdom;
        indexdom.prepare();
        indexdom->setRange(IndexedIdentifierRange(type2Prefix(type),fcov->featureCount(type)));
        datadef.domain(indexdom);
    }

    bool ok = CoverageConnector::storeMetaData(fcov, type, datadef);
    if ( !ok)
        return false;

    QString dataFile = fcov->name();
    int index = dataFile.lastIndexOf(".");
    if ( index != -1) {
        dataFile = dataFile.left(index);
    }

    _odf->setKeyValue("Domain","Type","DomainUniqueID");
    _odf->setKeyValue("DomainSort","Sorting","AlphaNumeric");
    _odf->setKeyValue("DomainSort","Prefix","feature");
    _odf->setKeyValue("DomainSort","Class","Domain UniqueID");
    _odf->setKeyValue("DomainIdentifier","Nr",QString::number(fcov->featureCount(type)));


    if ( fcov->featureTypes() & itPOLYGON){
        ok = storeMetaPolygon(fcov, dataFile);
    }
    if ( fcov->featureTypes() & itLINE){
        ok = storeMetaLine(fcov, dataFile);
    }

    _odf->store();
    return ok;
}
Beispiel #19
0
QVariant FlatTable::cell(const quint32 index, quint32 rec, bool asRaw) const
{
    if (!const_cast<FlatTable *>(this)->initLoad()) {
        return QVariant();
    }

    if ( !isColumnIndexValid(index)) {
        return QVariant();
    }
    if ( rec < recordCount()) {
        QVariant var = _datagrid[rec].cell(index);
        if ( !asRaw) {
            ColumnDefinition coldef = columndefinition(index);
            return coldef.datadef().domain<>()->impliedValue(var);
        }
        return var;
    }
    kernel()->issues()->log(TR(ERR_INVALID_RECORD_SIZE_IN).arg(name()),IssueObject::itWarning);
    return QVariant();
}
Beispiel #20
0
void TableSelector::stringCase(const LogicalExpressionPart& part, const ColumnDefinition& coldef, const QVariant& var, std::vector<bool>::iterator& iter) {
    QString text = part.value();
    QString fieldtxt = var.toString();
    if ( coldef.datadef().domain<>()->valueType() == itTHEMATICITEM){
        quint32 raw = var.toUInt();
        INamedIdDomain domainid = coldef.datadef().domain<>().as<NamedIdDomain>();
        SPDomainItem item = domainid->item(raw);
        fieldtxt = item->name();
    }
    LogicalOperator lconnector =  part.logicalConnector();
    switch(part.condition()){
    case loEQ:{
        switch(lconnector){
        case loNONE:
            *iter = fieldtxt == text;break;
        case loOR:
            *iter = *iter || fieldtxt == text;break;
        case loAND:
            *iter = *iter && fieldtxt == text;break;
        default:
            *iter = false;break;
        }
        break;
    }
    case loNEQ:{
        switch(lconnector){
        case loNONE:
            *iter = fieldtxt != text;break;
        case loOR:
            *iter = *iter || fieldtxt != text;break;
        case loAND:
            *iter = *iter && fieldtxt != text;break;
        default:
            *iter = false;break;
        }
        break;
    }
    default:
        *iter = false;
    }
}
Beispiel #21
0
void BaseTable::initValuesColumn(const QString& colname){
    ColumnDefinition def = columndefinition(colname);
    if ( !def.isValid()){
        ERROR2(WARN_INVALID_OBJECT,TR("column definition"), name());
        return;
    }

    IlwisTypes valueType = def.datadef().domain<>()->valueType();
    std::vector<QVariant> col(recordCount());
    for(auto& var : col) {
        if ( hasType(valueType, itINTEGER | itDOMAINITEM))
            var = QVariant((int)iUNDEF);
        else if ( hasType(valueType, itDOUBLE | itFLOAT))
           var = QVariant(rUNDEF);
        else if ( hasType(valueType, itSTRING))
            var = QVariant(sUNDEF);
        else if ( hasType(valueType, itCOORDINATE))
            var.setValue(crdUNDEF);
    }
    column(def.name(),col);
}
Beispiel #22
0
bool RunsTableModel::setValue(int row_ix, int column_ix, const QVariant &val)
{
	bool ret;
	ColumnDefinition cd = columnDefinition(column_ix);
	if(cd.matchesSqlId(QStringLiteral("finishTimeMs"))) {
		QVariant start_ms = value(row_ix, "startTimeMs");
		if(!start_ms.isNull()) {
			int time_ms = val.toInt() - start_ms.toInt();
			if(time_ms > 0) {
				Super::setValue(row_ix, "timeMs", time_ms);
			}
		}
	}
	else if(cd.matchesSqlId(QStringLiteral("timeMs"))) {
		QVariant start_ms = value(row_ix, "startTimeMs");
		if(!start_ms.isNull()) {
			int finish_ms = val.toInt() + start_ms.toInt();
			if(finish_ms > 0) {
				Super::setValue(row_ix, columnIndex("finishTimeMs"), finish_ms);
			}
		}
	}
	else if(cd.matchesSqlId(QStringLiteral("startTimeMs"))) {
		if(!val.isNull()) {
			int start_ms = val.toInt();
			int finish_ms = value(row_ix, "finishTimeMs").toInt();
			int time_ms = value(row_ix, "timeMs").toInt();
			if(finish_ms > 0) {
				int time_ms = finish_ms - start_ms;
				Super::setValue(row_ix, columnIndex("timeMs"), time_ms);
			}
			else if(time_ms > 0) {
				finish_ms = start_ms + time_ms;
				Super::setValue(row_ix, "finishTimeMs", finish_ms);
			}
		}
	}
	ret = Super::setValue(row_ix, column_ix, val);
	return ret;
}
Beispiel #23
0
bool BaseTable::addColumn(const ColumnDefinition& def){

    if ( !def.isValid())
        return false;

    if ( isReadOnly())
        return false;
    changed(true);

    bool ok =_attributeDefinition.addColumn(def);
    _columns = std::max(_columns, _attributeDefinition.definitionCount());

    return ok;
}
ColumnDefinition AppColumnDefinitionFactory::getDefinition(ColumnType type)
{
   ColumnDefinition definition;
   switch (type) {
   case ColumnType::Text:
      definition = ColumnDefinition(new TextDefinition);
      break;
   case ColumnType::DateTime:
      definition = ColumnDefinition(new DateTimeDefinition);
      break;
   case ColumnType::Selection:
      definition = ColumnDefinition(new SelectionDefinition);
      break;
   case ColumnType::None:
      break;
   }

   if (definition) {
      definition->setType(type);
   }

   return definition;
}
void AttributeDefinition::columndefinition(const ColumnDefinition &coldef)
{
    if ( coldef.id() >=  _columnDefinitionsByIndex.size())     {
        addColumn({coldef.name(), coldef.datadef().domain<>()});
    } else {
        auto iter1 = _columnDefinitionsByName.find(coldef.name());
        if ( iter1 != _columnDefinitionsByName.end()) {
            ColumnDefinition cdef = coldef;
            cdef.columnindex((*iter1).second);
            _columnDefinitionsByIndex[cdef.columnindex()] = cdef;
            (*iter1).second = cdef.columnindex();

        }else {
            addColumn(coldef);
        }
    }
}
Beispiel #26
0
bool FlatTable::addColumn(const ColumnDefinition &def)
{
    bool ok = BaseTable::addColumn(def);
    if(!ok) {
        return false;
    }
    if (  isDataLoaded()) {
        for(Record& row : _datagrid) {
            row.addColumn();
            row.changed(true);
        }
        initValuesColumn(def.name());
    }
    return true;
}
 bool Table::addColumn(ColumnDefinition& coldef){
     Ilwis::ColumnDefinition* ilwDef = coldef.ptr().get();
     return this->ptr()->as<Ilwis::Table>()->addColumn(*ilwDef);
 }
 void Table::setColumnDefinition(ColumnDefinition& coldef){
     Ilwis::ColumnDefinition* ilwDef = coldef.ptr().get();
     this->ptr()->as<Ilwis::Table>()->columndefinition(*ilwDef);
 }
bool NumericRepresentationSetter::canUse(const IIlwisObject &obj, const ColumnDefinition &coldef) const
{
    if ( coldef.isValid())
        return hasType(coldef.datadef().domain()->ilwisType(), itNUMERICDOMAIN);
    return false;
}
Beispiel #30
0
QVariant TableModel::data(const QModelIndex &index, int role) const
{
	QVariant ret;
	if(!index.isValid())
		return ret;
	if(role == RawValueRole) {
		ret = value(index.row(), index.column());
	}
	else if(role == ValueIsDirtyRole) {
		ret = isDirty(index.row(), index.column());
	}
	else if(role == SortRole) {
		int type = columnType(index.column());
		if(type == QVariant::Bool)
			ret = value(index.row(), index.column()).toBool();
		else
			ret = data(index, Qt::DisplayRole);
	}
	else if(role == Qt::DisplayRole) {
		ColumnDefinition cd = m_columns.value(index.column());
		if(cd.isNull()) {
			return QString("!%1").arg(index.column());
		}
		if(data(index, ValueIsNullRole).toBool()) {
			if(isNullReportedAsString())
				return QStringLiteral("null");
			return QVariant();
		}
		ret = data(index, Qt::EditRole);
		int type = columnType(index.column());
		if(type == QVariant::Invalid)
			type = ret.type(); /// pokud jsou sloupce virtualni (sloupce se pocitaji, nemusi byt pro ne definovan typ)
		if(type == QVariant::ByteArray) {
			const static QString blob_string = "{blob %1%2}";
			int size = ret.toByteArray().size();
			if(size < 1024) ret = blob_string.arg(size).arg(" B");
			else ret = blob_string.arg(size/1024).arg("kB");
		}
		else if(type == QVariant::Bool) {
			/// display check
			ret = QString();
		}
		QString format = cd.format();
		if(format.isEmpty()) {
			if(type == QVariant::Date) {
				format = m_defaultDateFormat;
			}
			else if(type == QVariant::Time) {
				format = m_defaultTimeFormat;
				//qfInfo() << "format" << format;
			}
			else if(type == QVariant::DateTime) {
				format = m_defaultDateTimeFormat;
				//qfInfo() << "format" << format;
			}
		}
		if(!format.isEmpty()) {
			if(type == QVariant::Time) {
				QTime t = ret.toTime();
				ret = t.toString(format);
			}
			else if(type == QVariant::Date) {
				QDate d = ret.toDate();
				ret = d.toString(format);
			}
			else if(type == QVariant::DateTime) {
				QDateTime dt = ret.toDateTime();
				ret = dt.toString(format);
			}
		}
	}
	else if(role == Qt::EditRole) {
		ret = data(index, RawValueRole);
		ret = rawValueToEdit(index.column(), ret);
	}
	else if (role == ValueIsNullRole) {
		ret = data(index, RawValueRole);
		return ret.isNull() && ret.isValid();
	}
	else if (role == Qt::TextAlignmentRole) {
		const ColumnDefinition cd = m_columns.value(index.column());
		Qt::Alignment al = cd.alignment();
		if(!!al)
			ret = (int)al;
		else {
			if(!data(index, ValueIsNullRole).toBool()) {
				ret = data(index, RawValueRole);
				if(ret.type() > QVariant::Bool && ret.type() <= QVariant::Double)
					ret = Qt::AlignRight;
				else
					ret = Qt::AlignLeft;
			}
		}
	}
	else if(role == Qt::TextColorRole) {
		int type = columnType(index.column());
		if(type == QVariant::ByteArray)
			return QColor(Qt::blue);
		if(data(index, ValueIsNullRole).toBool()) {
			return QColor(Qt::blue);
		}
		ret = QVariant();
	}
	else if (role == Qt::BackgroundColorRole) {
		/// delegate does it
	}
	else if (role == Qt::CheckStateRole) {
		int type = columnType(index.column());
		if(type == QVariant::Bool) {
			//qfInfo() << "BOOL";
			return (data(index, Qt::EditRole).toBool()? Qt::Checked: Qt::Unchecked);
		}
		return QVariant();
	}
	else if (role == Qt::ToolTipRole) {
		QString s = data(index, Qt::DisplayRole).toString();
		//s = "<pre>" + s + "</pre>"; /// kvuli chybe v Qt 4.6.3, kdy aplikace pada pokud je v textu za sebou 0x09 0x0A
		s.replace("\t\n", "\n");
		ret = s;
		//ret = data(index, Qt::DisplayRole);
		//qfInfo() << ret.toString();
	}
	return ret;
}