backup
This commit is contained in:
@@ -68,28 +68,32 @@ bool XQItemFactory::isValid()
|
||||
}
|
||||
|
||||
|
||||
//! es reicht nicht, einen itemType aus den itemType-templates zu
|
||||
//! Es reicht nicht, einen itemType aus den itemType-templates zu
|
||||
//! holen: möglicherweise muss der noch mit zusätzlichen attributen
|
||||
//! ergänzt werden, (hier 'UnitType' ).
|
||||
//! ergänzt werden.
|
||||
//! Vom aufwand ist es auch egal, ob ich daten aus dem XML in das
|
||||
//! item oder den itemtyp schreiben muss.
|
||||
|
||||
XQItemType* XQItemFactory::makeItemType(const XQNodePtr& sheetEntry )
|
||||
{
|
||||
QString typeKey = sheetEntry->attribute("ItemType");
|
||||
QString typeKey = sheetEntry->attribute( c_ItemType );
|
||||
|
||||
XQItemType* itemType = findItemTypeTemplate(typeKey);
|
||||
|
||||
// wir prüfen, ob im sheetEntry noch zusätzliche attribute vorhanden
|
||||
// sind, die wir in dem itemType müssen
|
||||
|
||||
qDebug() << " --- makeItemType: " << sheetEntry->to_string();
|
||||
|
||||
// über alle attribute
|
||||
for (const auto& attr : sheetEntry->attributes())
|
||||
for (const auto& attrEntry : sheetEntry->attributes())
|
||||
{
|
||||
// prüfen, ob der itemType des attribute schon hat
|
||||
int role = itemType->hasAttribute( attr.first);
|
||||
int role = itemType->roleForAttributeKey( attrEntry.first );
|
||||
// wenn ja, überschreiben
|
||||
if( role != XQItem::NoRole )
|
||||
{
|
||||
QVariant newValue = makeVariant(role,attr.second);
|
||||
QVariant newValue = makeVariant(role, attrEntry.second );
|
||||
itemType = itemType->replaceAttribute( newValue, role );
|
||||
}
|
||||
|
||||
@@ -97,7 +101,7 @@ XQItemType* XQItemFactory::makeItemType(const XQNodePtr& sheetEntry )
|
||||
return itemType;
|
||||
}
|
||||
|
||||
//! firz!
|
||||
//! sucht einen item typ aus der map mit 'vorgefertigen' itemtypen.
|
||||
|
||||
XQItemType* XQItemFactory::findItemTypeTemplate(const QString& key ) const
|
||||
{
|
||||
@@ -107,7 +111,7 @@ XQItemType* XQItemFactory::findItemTypeTemplate(const QString& key ) const
|
||||
}
|
||||
|
||||
|
||||
//! firz!
|
||||
//! sucht eine model-beschreibung
|
||||
|
||||
XQNodePtr XQItemFactory::findModelSheet( const QString& modelName ) const
|
||||
{
|
||||
@@ -153,6 +157,7 @@ QVariant XQItemFactory::makeVariant( int dataRole, const QString& source ) const
|
||||
case XQItem::ItemTypeRole:
|
||||
{
|
||||
// itemType() -> XQItemType*
|
||||
qDebug() << " --- makeVariant: make ItemType: " << source;
|
||||
XQItemType* itemType = findItemTypeTemplate( source );
|
||||
value = QVariant::fromValue(itemType);
|
||||
break;
|
||||
@@ -202,10 +207,8 @@ QVariant XQItemFactory::makeVariant( int dataRole, const QString& source ) const
|
||||
|
||||
|
||||
case XQItem::IconRole:
|
||||
{
|
||||
QIcon typeIcon;
|
||||
if(XQAppData::hasTypeIcon(source))
|
||||
typeIcon = XQAppData::typeIcon(source);
|
||||
{
|
||||
QIcon typeIcon = XQAppData::typeIcon(source);
|
||||
value = QVariant::fromValue(typeIcon);
|
||||
break;
|
||||
}
|
||||
@@ -264,9 +267,8 @@ XQItem* XQItemFactory::makeItem( const XQNodePtr& sheetNode, const XQNodePtr& co
|
||||
{
|
||||
// den itemtype des neuen items rausfinden
|
||||
QString typeKey = sheetNode->attribute(c_ItemType);
|
||||
qDebug() << " --- makeItem: typeKey: " << typeKey << ": " << sheetNode->to_string();
|
||||
//XQItemType* itemType = makeItemType(sheetEntry); // throws
|
||||
XQItemType* itemType = findItemTypeTemplate(typeKey);
|
||||
|
||||
XQItemType* itemType = makeItemType(sheetNode); // throws
|
||||
// fallunterscheidung beim inhalt:
|
||||
const QString* contentPtr{};
|
||||
// das ist Unterschied zum normalen Item: Der Titel kommt aus der Modelbeschreibung
|
||||
@@ -280,24 +282,8 @@ XQItem* XQItemFactory::makeItem( const XQNodePtr& sheetNode, const XQNodePtr& co
|
||||
|
||||
}
|
||||
|
||||
XQItemList XQItemFactory::makeHeaderRow( const XQNodePtr& headerNode )
|
||||
{
|
||||
|
||||
XQItemList list;
|
||||
// über alle kinder der <Header> sektion
|
||||
for( const auto& headerEntry : headerNode->children() )
|
||||
{
|
||||
//qDebug() << " --- headerEntry: " << headerEntry->tag_name() << ": " << headerEntry->attribute( "ItemType") << headerEntry->attribute( "Caption");
|
||||
XQItem* headerItem = makeItem( headerEntry );
|
||||
list.append( headerItem );
|
||||
}
|
||||
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//! erzeugt eine header item row.
|
||||
//! erzeugt eine item-row.
|
||||
|
||||
XQItemList XQItemFactory::makeContentRow( const XQNodePtr& sheetNode, const XQNodePtr& contentNode )
|
||||
{
|
||||
|
@@ -34,7 +34,7 @@ public:
|
||||
|
||||
XQItem* makeItem( const XQNodePtr& sheetNode, const XQNodePtr& contentNode=nullptr);
|
||||
|
||||
XQItemList makeHeaderRow( const XQNodePtr& sheetNode );
|
||||
|
||||
XQItemList makeContentRow( const XQNodePtr& sheetNode, const XQNodePtr& contentNode );
|
||||
//XQItemList makeEmptyRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode );
|
||||
|
||||
|
@@ -70,18 +70,17 @@ void XQItemType::setData(const QVariant& value, int role )
|
||||
}
|
||||
|
||||
//! tested, ob ein attribute (z.B. unitType) hier vorhanden ist
|
||||
int XQItemType::hasAttribute( const QString& attrKey )
|
||||
int XQItemType::roleForAttributeKey( const QString& attrKey )
|
||||
{
|
||||
int role = XQItem::fetchItemDataRole(attrKey);
|
||||
// gibbed überhaupt eine rolle für unser attribut?
|
||||
if( role == XQItem::NoRole)
|
||||
return XQItem::NoRole;
|
||||
|
||||
// wenn ja, ist die role hier besetzt?
|
||||
QVariant value = data(role);
|
||||
if( !value.isValid() || value.isNull() )
|
||||
return XQItem::NoRole;
|
||||
|
||||
if( role != XQItem::NoRole)
|
||||
{
|
||||
// wenn ja, ist die role hier besetzt?
|
||||
QVariant value = data(role);
|
||||
if( !value.isValid() || value.isNull() )
|
||||
return XQItem::NoRole;
|
||||
}
|
||||
return role;
|
||||
}
|
||||
|
||||
@@ -91,6 +90,7 @@ int XQItemType::hasAttribute( const QString& attrKey )
|
||||
XQItemType* XQItemType::replaceAttribute( const QVariant& newValue, int role )
|
||||
{
|
||||
|
||||
qDebug() << " --- Before: " << makeItemTypeKey() << " role:" << XQItem::fetchItemDataRoleName(role) << " value:" << newValue.toString();
|
||||
// hat sich überhaupt was geändert?
|
||||
QVariant oldValue = data(role);
|
||||
|
||||
@@ -115,8 +115,10 @@ XQItemType* XQItemType::replaceAttribute( const QVariant& newValue, int role )
|
||||
|
||||
// speichern
|
||||
s_ItemTypeMap.insert( newKey, myClone );
|
||||
// und ins item übernehmen
|
||||
//item.setItemType( myClone );
|
||||
|
||||
|
||||
|
||||
qDebug() << " --- After: " << myClone->makeItemTypeKey();
|
||||
|
||||
/// Obacht! Der alte, geänderte itemType bleibt erhalten
|
||||
/// und verrottet ggf. ohne Daseinszweck
|
||||
@@ -131,6 +133,7 @@ XQItemType* XQItemType::replaceAttribute( const QVariant& newValue, int role )
|
||||
QVariant XQItemType::formatText( const XQItem& item ) const
|
||||
{
|
||||
XQItem::UnitType uType = unitType();
|
||||
//qDebug() << " --- formatText: " << XQItem::fetchUnitTypeToString( uType);
|
||||
const QString& cont = item.content();
|
||||
if( uType != XQItem::NoUnitType )
|
||||
return formatToSI( cont, uType );
|
||||
@@ -244,10 +247,11 @@ QString XQItemType::makeItemTypeKey()
|
||||
key = key.arg( renderStyleToString() );
|
||||
key = key.arg( editorTypeToString() );
|
||||
key = key.arg( unitTypeToString() );
|
||||
key = key.arg( contentFormat() );
|
||||
|
||||
key = key.arg( contentFormat() );
|
||||
key = key.arg( data(XQItem::FlagsRole).toString() );
|
||||
key = key.arg( icon().name() );
|
||||
// icons haben leider keine namen, es sei denn, sie kommen aus einen theme
|
||||
//key = key.arg( icon().name() );
|
||||
key = key.arg( icon().cacheKey() );
|
||||
key = key.arg( fixedChoicesToString() );
|
||||
|
||||
return key;
|
||||
|
@@ -40,12 +40,12 @@ public:
|
||||
QVariant data( int role ) const override;
|
||||
void setData(const QVariant& value, int role ) override;
|
||||
|
||||
virtual QVariant formatText( const XQItem& item ) const;
|
||||
QVariant formatText( const XQItem& item ) const;
|
||||
|
||||
QString formatToSI(const QString& rawText, XQItem::UnitType unitType ) const;
|
||||
QString unFormatFromSI(const QString& valueText ) const;
|
||||
|
||||
int hasAttribute( const QString& attrKey );
|
||||
int roleForAttributeKey( const QString& attrKey );
|
||||
XQItemType* replaceAttribute(const QVariant& newValue, int role );
|
||||
|
||||
QString makeItemTypeKey();
|
||||
|
Reference in New Issue
Block a user