repaired it (a bit)
This commit is contained in:
@@ -141,7 +141,8 @@ XQItem::XQItem( XQItemType* itemType )
|
||||
XQItem::XQItem(XQItemType* itemType, const QString *content )
|
||||
: XQItem{ itemType }
|
||||
{
|
||||
setContent(content);
|
||||
// hier setzen wir direkt ohne umwege den string pointer
|
||||
QStandardItem::setData( QVariant::fromValue<const QString*>(content), XQItem::ContentRole );
|
||||
}
|
||||
|
||||
XQItem::XQItem( XQItemType* itemType, const QString& content )
|
||||
@@ -160,20 +161,29 @@ XQItem* XQItem::clone() const
|
||||
//! false für ein ungültiges item. 'ungültig' heisst hier, dass nur ein
|
||||
//! mockup-itemtype gesetzt ist.
|
||||
|
||||
bool XQItem::isValid() const
|
||||
bool XQItem::isValidX() const
|
||||
{
|
||||
XQItemType* dummyType = XQItemType::staticItemType();
|
||||
return QStandardItem::data( XQItem::ItemTypeRole ).value<XQItemType*>() != dummyType;
|
||||
}
|
||||
|
||||
|
||||
//! testet, ob es einen content-node gibt.
|
||||
|
||||
bool XQItem::hasContentNode() const
|
||||
{
|
||||
return contentNode() != nullptr;
|
||||
}
|
||||
if( column() == 0)
|
||||
{
|
||||
QVariant value = QStandardItem::data( XQItem::ContentNodeRole );
|
||||
return !value.isNull();
|
||||
}
|
||||
|
||||
// sonst: delegieren an den node-Besitzer
|
||||
QModelIndex pIndex = model()->index( row(), 0 );
|
||||
if( pIndex.isValid() )
|
||||
{
|
||||
XQItem& firstItem = xqItemFromIndex( pIndex );
|
||||
return firstItem.hasContentNode();
|
||||
}
|
||||
}
|
||||
|
||||
//! gibt den content-node zurück.
|
||||
|
||||
@@ -346,21 +356,6 @@ QString* XQItem::content() const
|
||||
*/
|
||||
|
||||
|
||||
//! Setzt den content()-string pointer. (als leihgabe)
|
||||
|
||||
void XQItem::setContent( const QString* content )
|
||||
{
|
||||
setData( QVariant::fromValue<const QString*>(content), XQItem::ContentRole );
|
||||
}
|
||||
|
||||
|
||||
//! Holt den schlüssel bzw. bezeicher des content() string aus 'unserem' content knoten.
|
||||
|
||||
QString XQItem::contentKey() const
|
||||
{
|
||||
return contentNode()->attributes().key_of( rawText() );
|
||||
}
|
||||
|
||||
//! Gibt den content-format string zurück
|
||||
|
||||
QString XQItem::contentFormat() const
|
||||
@@ -432,6 +427,10 @@ QString XQItem::dataRoleName(int role) const
|
||||
return XQItem::fetchItemDataRoleName(role);
|
||||
}
|
||||
|
||||
bool XQItem::hasContentPtr() const
|
||||
{
|
||||
return !QStandardItem::data( XQItem::ContentRole ).isNull();
|
||||
}
|
||||
|
||||
//! Gibt den content()-String zurück, sofern vorhanden.
|
||||
//! sonst: gibt der ihnalt der Qt::DisplayRole als fallback
|
||||
@@ -439,9 +438,12 @@ QString XQItem::dataRoleName(int role) const
|
||||
|
||||
QString XQItem::contentFallBackText() const
|
||||
{
|
||||
const QString* contentPtr = QStandardItem::data( XQItem::ContentRole ).value<const QString*>();
|
||||
if(contentPtr)
|
||||
return *contentPtr;
|
||||
if( hasContentPtr() )
|
||||
{
|
||||
const QString* contentPtr = QStandardItem::data( XQItem::ContentRole ).value<const QString*>();
|
||||
if(contentPtr)
|
||||
return *contentPtr;
|
||||
}
|
||||
|
||||
// wenn wir keinen contentPtr haben, benutzen wir als fallback
|
||||
// die basis-text() role
|
||||
@@ -516,16 +518,24 @@ QVariant XQItem::data(int role ) const
|
||||
|
||||
case ContentNodeRole:
|
||||
{
|
||||
// Das Node-Besitzer-Item wohnt in der ersten Spalte,
|
||||
// wenn wir also der Node-Besitzer item sind ...
|
||||
if( column() == 0)
|
||||
return QStandardItem::data( XQItem::ContentNodeRole );
|
||||
// Das Node-Besitzer-Item wohnt in der ersten Spalte,
|
||||
// wenn wir also der Node-Besitzer item sind ...
|
||||
if( column() == 0)
|
||||
{
|
||||
QVariant value = QStandardItem::data( XQItem::ContentNodeRole );
|
||||
if( !value.isNull() )
|
||||
return value;
|
||||
throw XQException( "ContentNode is nullptr!");
|
||||
}
|
||||
|
||||
// sonst: delegieren an den node-Besitzer
|
||||
QModelIndex pIndex = model()->index( row(), 0 );
|
||||
// sonst: delegieren an den node-Besitzer
|
||||
QModelIndex pIndex = model()->index( row(), 0 );
|
||||
if( pIndex.isValid())
|
||||
{
|
||||
XQItem& firstItem = xqItemFromIndex( pIndex );
|
||||
|
||||
return firstItem.data( XQItem::ContentNodeRole );
|
||||
}
|
||||
throw XQException( "Item has no valid index (yet)!");
|
||||
}
|
||||
|
||||
case Qt::StatusTipRole:
|
||||
@@ -606,7 +616,7 @@ void XQItem::setData(const QVariant& value, int role )
|
||||
// fallback: wenns keinen content node gibt, dann nehmen wir
|
||||
// das standardverfahren.
|
||||
int role = XQItem::ContentRole;
|
||||
if( !hasContentNode() )
|
||||
if( !hasContentPtr() )
|
||||
role = Qt::DisplayRole;
|
||||
QStandardItem::setData( plainText, role );
|
||||
return;
|
||||
@@ -728,13 +738,10 @@ XQItem::UnitType XQItem::fetchUnitType(const QString& unitTypeKey)
|
||||
return s_UnitTypeMap.key(unitTypeKey);
|
||||
}
|
||||
|
||||
|
||||
//! gibt die bezeichung für den gegebenen unitType aus.
|
||||
|
||||
QString XQItem::fetchUnitTypeToString( UnitType unitType)
|
||||
{
|
||||
return s_UnitTypeMap[unitType];
|
||||
}
|
||||
|
||||
/// ---
|
||||
/// ---
|
||||
/// ---
|
||||
|
Reference in New Issue
Block a user