-- pre-holiday

This commit is contained in:
2025-08-27 14:06:31 +02:00
parent 6ee677c595
commit 04b0f650d6
12 changed files with 245 additions and 134 deletions

View File

@@ -15,7 +15,6 @@ TreeView
columnWidthProvider: function(column) columnWidthProvider: function(column)
{ {
var z= 1.7*(width / columns); var z= 1.7*(width / columns);
console.log("höh!");
return z; return z;
} }

View File

@@ -66,7 +66,7 @@ void XQChildModel::addModelData( const XQNodePtr& contentRoot )
int newRow = _sections.lastRow(section); int newRow = _sections.lastRow(section);
XQNodePtr sheetNode = section.sheetRootNode(); XQNodePtr sheetNode = section.sheetRootNode();
XQItemList list = _itemFactory.makeRow( XQItemFactory::mData, sheetNode, contentEntry ); XQItemList list = _itemFactory.makeRow( sheetNode, contentEntry );
// als Baum? // als Baum?
//section.headerItem().appendRow( list ); //section.headerItem().appendRow( list );
@@ -84,7 +84,7 @@ void XQChildModel::addSectionEntry( const QString& key, const XQNodePtr& content
section.setContentRootNode( contentEntry->parent() ); section.setContentRootNode( contentEntry->parent() );
int newRow = _sections.lastRow(section); int newRow = _sections.lastRow(section);
XQNodePtr sheetNode = section.sheetRootNode(); XQNodePtr sheetNode = section.sheetRootNode();
XQItemList list = _itemFactory.makeRow( XQItemFactory::mHeader, sheetNode, contentEntry ); XQItemList list = _itemFactory.makeRow( sheetNode, nullptr );
insertRow( newRow, list); insertRow( newRow, list);
} }
} }

View File

@@ -51,18 +51,16 @@ XQItem* XQMainModel::addProjectItem( XQNodePtr contentNode )
for(const auto& section : _sections ) for(const auto& section : _sections )
{ {
if( contentNode->attribute(c_ContentType) == section.contentType() )
if( contentNode->attribute( c_ContentType) == section.contentType() )
{ {
qDebug() << " --- add PROJECT: contentNode: " << contentNode->to_string(); qDebug() << " --- add PROJECT: contentNode: " << contentNode->to_string();
// __fixme! das ist mist! // __fixme! das ist mist!
const XQNodePtr sheetNode = section.sheetRootNode()->first_child(); const XQNodePtr sheetNode = section.sheetRootNode()->first_child();
XQItemList list = _itemFactory.makeRow( XQItemFactory::mSingle, sheetNode, contentNode, "ProjectName"); XQItem* newItem = _itemFactory.makeSingleItem( sheetNode, contentNode->attribute( "ProjectName") );
// den neuen eintrag in die passende section der übersicht eintragen ... // den neuen eintrag in die passende section der übersicht eintragen ...
section.headerItem().appendRow( list ); section.headerItem().appendRow( newItem );
// ... ausklappen... // ... ausklappen...
const QModelIndex index = section.headerItem().index(); const QModelIndex index = section.headerItem().index();
_treeTable->expand( index ); _treeTable->expand( index );
@@ -72,30 +70,56 @@ XQItem* XQMainModel::addProjectItem( XQNodePtr contentNode )
//newItem->setContentNode( contentNode ); //newItem->setContentNode( contentNode );
//emit itemCreated( newItem ); //emit itemCreated( newItem );
XQItem* newItem = dynamic_cast<XQItem*>(list[0]);
// erzeuger sheet node speichern // erzeuger sheet node speichern
newItem->setSheetNode( sheetNode ); newItem->setSheetNode( sheetNode );
return newItem; return newItem;
} }
} }
throw XQException( "addProjectItem: main model should not be empty!" ); throw XQException( "addProjectItem: main model should not be empty!" );
} }
void XQMainModel::addSectionItem( const XQModelSection& section, XQItem* projectItem ) void XQMainModel::addSectionItem( const XQModelSection& section, XQItem* projectItem )
{ {
qDebug() << " --- SUPPA0: " << section.contentType();
qDebug() << " --- SUPPA1: -> " << projectItem->contentNode()->to_string();
qDebug() << " --- SUPPA2: -> " << projectItem->sheetNode()->to_string();
qDebug() << " --- SUPPA3: -> " << projectItem->sheetNode()->find_child_by_tag_name("CurrentSection")->to_string();
XQNodePtr sectionChild = projectItem->sheetNode()->find_child_by_tag_name("CurrentSection");
//qDebug() << " --- SUPPA4: -> " << section.contentRootNode()->to_string();
return; return;
//
if(sectionChild)
{
//XQItemList list = _itemFactory.makeRow( XQItemFactory::mStatic, sectionChild, nullptr, section.contentType() );
//projectItem->appendRow( list );
_treeTable->expand( projectItem->index() );
}
return;
for(const auto& xsection : _sections )
{
if( projectItem->contentNode()->attribute(c_ContentType) == xsection.contentType() )
{
//qDebug() << " --- FITZ;: contentNode: " << contentNode->to_string();
}
}
// ich brauche _meine_ section für den sheetNode! // ich brauche _meine_ section für den sheetNode!
/*
XQNodePtr sheetNode = projectItem->sheetNode()->find_child_by_tag_name("CurrentSection"); XQNodePtr sheetNode = projectItem->sheetNode()->find_child_by_tag_name("CurrentSection");
XQItemList list = _itemFactory.makeRow( XQItemFactory::mSingle, sheetNode, nullptr, c_ContentType ); XQItemList list = _itemFactory.makeRow( XQItemFactory::mSingle, sheetNode, nullptr, c_ContentType );
projectItem->appendRow( list ); projectItem->appendRow( list );
_treeTable->expand( projectItem->index() ); _treeTable->expand( projectItem->index() );
*/
} }

View File

@@ -116,6 +116,8 @@ XQItem::XQPrefixExponentMap XQItem::s_PrefixExponentMap
}; };
//! Default konstruktor, setzt einen ungültigen (dummy)
//! itemType.
XQItem::XQItem() XQItem::XQItem()
: XQItem{XQItemType::staticItemType()} : XQItem{XQItemType::staticItemType()}
@@ -123,6 +125,9 @@ XQItem::XQItem()
} }
//! Default konstruktor mit einem vorhandenen itemType.
XQItem::XQItem( XQItemType* itemType ) XQItem::XQItem( XQItemType* itemType )
: QStandardItem{} : QStandardItem{}
{ {
@@ -130,12 +135,20 @@ XQItem::XQItem( XQItemType* itemType )
} }
//! konstruiert ein daten-item mit zeiger auf 'unser' attribut
//! im übergeordneten content-node.
XQItem::XQItem(XQItemType* itemType, const QString *content ) XQItem::XQItem(XQItemType* itemType, const QString *content )
: XQItem{ itemType } : XQItem{ itemType }
{ {
setContent(content); setContent(content);
} }
XQItem::XQItem( XQItemType* itemType, const QString& content )
: XQItem{ itemType }
{
setText(content);
}
//! ruft den copy-konstruktor auf. //! ruft den copy-konstruktor auf.
XQItem* XQItem::clone() const XQItem* XQItem::clone() const
@@ -154,14 +167,19 @@ bool XQItem::isValid() const
} }
//! testet, ob es einen content-node gibt.
bool XQItem::hasContentNode() const
{
return contentNode() != nullptr;
}
//! gibt den content-node zurück. //! gibt den content-node zurück.
XQNodePtr XQItem::contentNode() const XQNodePtr XQItem::contentNode() const
{ {
XQNodePtr node = data( ContentNodeRole ).value<XQNodePtr>(); return data( ContentNodeRole ).value<XQNodePtr>();
if( node )
return node;
throw XQException("XQItem::contentNode() nullptr");
} }
@@ -319,15 +337,16 @@ QString XQItem::rawText() const
//! Gibt den string-zeiger auf das attribut aus unseren XQNodePtr zurück. //! Gibt den string-zeiger auf das attribut aus unseren XQNodePtr zurück.
/*
QString* XQItem::content() const QString* XQItem::content() const
{ {
// macht jetzt das, ws draufsteht: gibt einen string* zurück // macht jetzt das, was draufsteht: gibt einen string* zurück
return data( XQItem::ContentRole ).value<QString*>(); return data( XQItem::ContentRole ).value<QString*>();
} }
*/
//! set den content()-string pointer. (als leihgabe) //! Setzt den content()-string pointer. (als leihgabe)
void XQItem::setContent( const QString* content ) void XQItem::setContent( const QString* content )
{ {
@@ -335,21 +354,21 @@ void XQItem::setContent( const QString* content )
} }
//! holt den schlüssel bzw. bezeicher des content() string aus 'unserem' content knoten. //! Holt den schlüssel bzw. bezeicher des content() string aus 'unserem' content knoten.
QString XQItem::contentKey() const QString XQItem::contentKey() const
{ {
return contentNode()->attributes().key_of( rawText() ); return contentNode()->attributes().key_of( rawText() );
} }
//! gibt den content-format string zurück //! Gibt den content-format string zurück
QString XQItem::contentFormat() const QString XQItem::contentFormat() const
{ {
return data( XQItem::ContentFormatRole ).toString(); return data( XQItem::ContentFormatRole ).toString();
} }
//! setz den den content format-string. wird im itemType gespeichert. //! Setzt den den content format-string. wird im itemType gespeichert.
void XQItem::setContentFormat(const QString& contentFormat) void XQItem::setContentFormat(const QString& contentFormat)
{ {
@@ -357,7 +376,7 @@ void XQItem::setContentFormat(const QString& contentFormat)
} }
//! gibt das read-only auswahl-model zurück (wenn dieses item als //! Gibt das read-only auswahl-model zurück (wenn dieses item als
//! combobox gerendert wird). wird im itemType gespeichert. //! combobox gerendert wird). wird im itemType gespeichert.
QStandardItemModel* XQItem::fixedChoices() const QStandardItemModel* XQItem::fixedChoices() const
@@ -413,6 +432,23 @@ QString XQItem::dataRoleName(int role) const
return XQItem::fetchItemDataRoleName(role); return XQItem::fetchItemDataRoleName(role);
} }
//! Gibt den content()-String zurück, sofern vorhanden.
//! sonst: gibt der ihnalt der Qt::DisplayRole als fallback
//! zurück.
QString XQItem::contentFallBackText() const
{
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
return QStandardItem::data( Qt::DisplayRole ).toString();
}
//! angespasste variante von qstandarditem::setData. geteilte attribute //! angespasste variante von qstandarditem::setData. geteilte attribute
//! werden vom xqitemtype geholt //! werden vom xqitemtype geholt
@@ -438,33 +474,34 @@ QVariant XQItem::data(int role ) const
return itemType().data(role); return itemType().data(role);
} }
// Zugriffe auf den sichtbaren inhalt geben den inhalt des string pointer case XQItem::ContentRole:
// auf ein feld in content node wieder.
// DisplayRole gibt den formatieren inhalt wieder. die formatierung übernimmt
// der item type
// auf den original inhalt im content node zurückgeben.
case Qt::DisplayRole :
{ {
if( itemType().renderStyle() == XQItem::FormattedStyle)//return "display:"+content(); qDebug() << " --- data(XQItem::ContentRole) should NOT be called!";
return itemType().formatText( *this ); return *QStandardItem::data( XQItem::ContentRole ).value<QString*>();
[[fallthrough]];
} }
// EditRole & ContentRole sollen den 'rohen' inhalt unseres string-pointers // EditRole & ContentRole sollen den 'rohen' inhalt unseres string-pointers
// auf den original inhalt im content node zurückgeben. // auf den original inhalt im content node zurückgeben.
case Qt::EditRole : case Qt::EditRole :
case XQItem::ContentRole:
{ {
// Zugriffe auf den text-inhalt geben den inhalt des string pointer
// auf ein feld in content-node wieder. Wenn kein content-node vorhanden
// ist (single-items), wird Qt::DisplayRole zurückgeliefert.
const QString* contentPtr = QStandardItem::data( XQItem::ContentRole ).value<const QString*>(); return contentFallBackText();
if(contentPtr) //[[fallthrough]];
return *contentPtr; }
static const QString s_dummyContent("-"); // DisplayRole gibt den formatierten inhalt wieder. die formatierung übernimmt
return s_dummyContent; // der item type
case Qt::DisplayRole :
{
QString plainText = contentFallBackText();
if( renderStyle() == XQItem::FormattedStyle)
return XQItemType::formatToSI( plainText, unitType() );
return plainText;
} }
case Qt::ToolTipRole: case Qt::ToolTipRole:
@@ -482,7 +519,7 @@ QVariant XQItem::data(int role ) const
// Das Node-Besitzer-Item wohnt in der ersten Spalte, // Das Node-Besitzer-Item wohnt in der ersten Spalte,
// wenn wir also der Node-Besitzer item sind ... // wenn wir also der Node-Besitzer item sind ...
if( column() == 0) if( column() == 0)
return QStandardItem::data( XQItem::ContentNodeRole ); return QStandardItem::data( XQItem::ContentNodeRole );
// sonst: delegieren an den node-Besitzer // sonst: delegieren an den node-Besitzer
QModelIndex pIndex = model()->index( row(), 0 ); QModelIndex pIndex = model()->index( row(), 0 );
@@ -557,25 +594,67 @@ void XQItem::setData(const QVariant& value, int role )
return; return;
} }
// set the raw, unformatted data case XQItem::ContentRole:
case ContentRole:
{ {
// string ptr setzen kann die basis. qDebug() << " --- data(XQItem::ContentRole) should NOT be called!";
break; // string ptr setzen macht die basis implementierung
[[fallthrough]];
} }
// set the raw, unformatted data
case Qt::EditRole:
{
QString currentText = contentFallBackText();
qDebug() << " --- setting EDITrole: " << currentText;
}
case Qt::DisplayRole:
{
// Wenn wir formatiert sind, machen wir das rückgängig
if( itemType().renderStyle() == XQItem::FormattedStyle)
QVariant plainText = XQItemType::unFormatFromSI( value.toString() );
// string setzen kann die basis ...
qDebug() << " --- setting CONTENTrole: " << value.toString();
// ... aber nur, wenn wir auch einen contentNode haben
/*
if( itemType().renderStyle() == XQItem::FormattedStyle)//return "display:"+content();
return itemType().formatText( *this );
[[fallthrough]];
}
case Qt::DisplayRole:
{
// Wenn wir formatiert sind, machen wir das rückgängig
if( itemType().renderStyle() == XQItem::FormattedStyle)
QVariant plaintText = XQItemType::unFormatFromSI( value.toString() );
// string setzen kann die basis ...
qDebug() << " --- setting CONTENTrole: " << value.toString();
// ... aber nur, wenn wir auch einen contentNode haben
if( itemType().renderStyle() == XQItem::FormattedStyle)//return "display:"+content();
return itemType().formatText( *this );
[[fallthrough]];
}
// EditRole & ContentRole sollen den 'rohen' inhalt unseres string-pointers
// auf den original inhalt im content node zurückgeben.
case Qt::EditRole : case Qt::EditRole :
case XQItem::ContentRole:
{ {
qDebug() << " --- setting EDITrole: " << value.toString();
break;
}
case Qt::DisplayRole : const QString* contentPtr = QStandardItem::data( XQItem::ContentRole ).value<const QString*>();
{ if(contentPtr)
// what will happen? value is a string ptr ?! return *contentPtr;
qDebug() << " --- setting DISPLAYrole: " << value.toString(); if( )
break; break;
} }
*/
// alles andere wie gehabt // alles andere wie gehabt
case ContentNodeRole: case ContentNodeRole:

View File

@@ -133,6 +133,7 @@ public:
XQItem(); XQItem();
XQItem( XQItemType* itemType ); XQItem( XQItemType* itemType );
XQItem( XQItemType* itemType, const QString* content ); XQItem( XQItemType* itemType, const QString* content );
XQItem( XQItemType* itemType, const QString& content );
virtual ~XQItem() = default; virtual ~XQItem() = default;
@@ -143,7 +144,8 @@ public:
//! //!
bool isValid() const; bool isValid() const;
//! gibt den zu diesem item gehörigen datenknoten zurück bool hasContentNode() const;
//! gibt den zu diesem item gehörigen datenknoten zurück
virtual XQNodePtr contentNode() const; virtual XQNodePtr contentNode() const;
virtual XQNodePtr sheetNode() const; virtual XQNodePtr sheetNode() const;
@@ -162,7 +164,7 @@ public:
QString rawText() const; QString rawText() const;
// changed: gibt jetzt den pointer zurück. // changed: gibt jetzt den pointer zurück.
QString* content() const; //QString* content() const;
QString contentKey() const; QString contentKey() const;
void setContent( const QString* content ); void setContent( const QString* content );
@@ -241,6 +243,9 @@ protected:
XQItem(const XQItem& other) = default; XQItem(const XQItem& other) = default;
XQItem& operator=(const XQItem& other) = default; XQItem& operator=(const XQItem& other) = default;
QString contentFallBackText() const;
// das ist protected, weil damit der content()-zugriff demoliert werden kann
void setContentNode(const XQNodePtr& contentNode ); void setContentNode(const XQNodePtr& contentNode );
using XQItemFlagMap = QMap<QString,int>; using XQItemFlagMap = QMap<QString,int>;

View File

@@ -220,27 +220,35 @@ QSize XQItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelI
} }
//! Erzeugt ein editor-widget, sofern ein gültiger content-Ptr vorhanden und ein editor-Type gesetzt ist.
QWidget* XQItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const QWidget* XQItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
{ {
XQItem& item = xqItemFromIndex(index);
return QStyledItemDelegate::createEditor( parent, option, index ); XQItem::EditorType edType = item.editorType();
if( !item.hasContentNode() || edType == XQItem::NoEditorType )
int editorType = XQItem::xqItemFromIndex(index).editorType();
QWidget* editor = itemEditorFactory()->createEditor(editorType, parent);
if( editor )
{ {
return editor; qDebug() << "---- NO Content or NO EditorType";
return nullptr;
} }
qDebug() << "---- ed type:" << XQItem::fetchEditorTypeToString( edType ) << ": " << edType;
//return QStyledItemDelegate::createEditor( parent, option, index );
return itemEditorFactory()->createEditor(edType, parent);
} }
//!
void XQItemDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const void XQItemDelegate::setEditorData(QWidget* editor, const QModelIndex& index) const
{ {
XQItem& item = xqItemFromIndex( index ); XQItem& item = xqItemFromIndex( index );
switch( item.editorType() ) XQItem::EditorType edType = item.editorType();
if( edType != XQItem::NoEditorType )
{ {
switch( edType )
{
case XQItemType::ComboBoxType : case XQItemType::ComboBoxType :
{ {
QComboBox* comboBox = qobject_cast<QComboBox*>(editor); QComboBox* comboBox = qobject_cast<QComboBox*>(editor);
@@ -251,11 +259,23 @@ void XQItemDelegate::setEditorData(QWidget* editor, const QModelIndex& index) co
} }
default: default:
break; //QStyledItemDelegate::setEditorData(editor, index);
// wir benutzen hier die DisplayRole wenn der Inhalt schon formatiert ist.
int role = item.renderStyle() == XQItem::FormattedStyle ? Qt::DisplayRole : Qt::EditRole;
QVariant value = index.data(role);
QByteArray userProp = editor->metaObject()->userProperty().name();
if (!userProp.isEmpty())
{
if (!value.isValid())
value = QVariant(editor->property(userProp).metaType());
editor->setProperty(userProp, value);
}
}
} }
QStyledItemDelegate::setEditorData(editor, index);
} }
void XQItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const void XQItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const

View File

@@ -99,6 +99,7 @@ XQItemType* XQItemFactory::makeItemType(const XQNodePtr& sheetEntry )
return itemType; return itemType;
} }
//! sucht einen item typ aus der map mit 'vorgefertigen' itemtypen. //! sucht einen item typ aus der map mit 'vorgefertigen' itemtypen.
XQItemType* XQItemFactory::findItemTypeTemplate(const QString& key ) const XQItemType* XQItemFactory::findItemTypeTemplate(const QString& key ) const
@@ -256,10 +257,6 @@ QVariant XQItemFactory::makeVariant( int dataRole, const QString& source ) const
/// ------------------------------------------------ /// ------------------------------------------------
/// ///
/* /*
XQItemList XQItemFactory::makeEmptyRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode ) XQItemList XQItemFactory::makeEmptyRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode )
{ {
@@ -304,7 +301,7 @@ XQItemList XQItemFactory::createGenericRow( const XQNodePtr& contentNode, const
//! erzeugt eine item-row. //! erzeugt eine item-row.
XQItemList XQItemFactory::makeRow(CreationMode mode, const XQNodePtr& sheetNode, const XQNodePtr& contentNode, const QString& captionKey ) XQItemList XQItemFactory::makeRow(const XQNodePtr& sheetNode, const XQNodePtr& contentNode )
{ {
XQItemList list; XQItemList list;
@@ -320,24 +317,23 @@ XQItemList XQItemFactory::makeRow(CreationMode mode, const XQNodePtr& sheetNode,
// //
for( const auto& sheetEntry : sheetNode->children() ) for( const auto& sheetEntry : sheetNode->children() )
list.append( makeItem( mode, sheetEntry, contentNode, captionKey ) ); list.append( makeItem( sheetEntry, contentNode ) );
Q_ASSERT(!list.empty()); Q_ASSERT(!list.empty());
// wir merken uns den original content node auch, aber // wir merken uns den original content node auch, aber
// im ersten Item. // im ersten Item. Kann null sein, macht aber erstmal nix.
dynamic_cast<XQItem*>(list[0])->setContentNode(contentNode); dynamic_cast<XQItem*>(list[0])->setContentNode(contentNode);
return list; return list;
} }
//! fixme! unsinn! //! Erzeugt ein XQItem aus einer typ-beschreibung ('sheetNode') und einem daten-knoten ('contentNode').
//! erzeugt ein XQItem aus einer typ-beschreibung ('sheetNode') und einem daten-knoten ('contentNode'). //! Wenn der content node nicht gesetzt ist, wird stattdess das attribut 'Caption' aus der typ-beschreibung
//! wenn der content node nicht gesetzt ist, wird stattdess das attribut 'Caption' aus der typ-beschreibung //! verwendet: es handelt sich dann um ein header item
//! verwendet: es handelt sich dann um ein header item, das erzeugt wurde.
XQItem* XQItemFactory::makeItem(CreationMode mode, const XQNodePtr& sheetNode, const XQNodePtr& contentNode, const QString& captionKey ) XQItem* XQItemFactory::makeItem(const XQNodePtr& sheetNode, const XQNodePtr& contentNode )
{ {
// den itemtype des neuen items rausfinden // den itemtype des neuen items rausfinden
XQItemType* itemType = makeItemType(sheetNode); // throws XQItemType* itemType = makeItemType(sheetNode); // throws
@@ -347,19 +343,10 @@ XQItem* XQItemFactory::makeItem(CreationMode mode, const XQNodePtr& sheetNode, c
// das ist Unterschied vom HeaderItem zum normalen Item: Der Titel kommt aus der Modelbeschreibung, // das ist Unterschied vom HeaderItem zum normalen Item: Der Titel kommt aus der Modelbeschreibung,
// sonst wird der content indirekt über den tag-name des sheetnode geholt // sonst wird der content indirekt über den tag-name des sheetnode geholt
switch( mode ) if( !contentNode )
{ contentPtr = sheetNode->attribute_ptr(c_Caption);
case mHeader: else
contentPtr = sheetNode->attribute_ptr(captionKey); contentPtr = contentNode->attribute_ptr( sheetNode->tag_name() );
break;
case mData:
contentPtr = contentNode->attribute_ptr( sheetNode->tag_name() );
break;
case mSingle:
contentPtr = contentNode->attribute_ptr( captionKey );
}
XQItem* newItem = new XQItem( itemType, contentPtr); XQItem* newItem = new XQItem( itemType, contentPtr);
@@ -371,3 +358,18 @@ XQItem* XQItemFactory::makeItem(CreationMode mode, const XQNodePtr& sheetNode, c
return newItem; return newItem;
} }
//! Erzeugt ein Item _ohne_ internen content node, sondern
XQItem* XQItemFactory::makeSingleItem( const XQNodePtr& sheetNode, const QString& caption )
{
// den itemtype des neuen items rausfinden
XQItemType* itemType = makeItemType(sheetNode); // throws
XQItem* newItem = new XQItem( itemType, caption);
// __fixme!
if( newItem->isCheckable() )
{
newItem->setCheckState( Qt::Checked );
}
return newItem;
}

View File

@@ -28,20 +28,18 @@ class XQItemFactory : public xsingleton<XQItemFactory>
public: public:
enum CreationMode
{
mHeader,
mData,
mSingle
};
void initItemFactory(const QString& modelSheetFileName ); void initItemFactory(const QString& modelSheetFileName );
XQNodePtr findModelSheet( const QString& modelName ) const; XQNodePtr findModelSheet( const QString& modelName ) const;
XQItemList makeRow( const XQNodePtr& sheetNode, const XQNodePtr& contentNode );
//XQItemList makeEmptyRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode ); //XQItemList makeEmptyRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode );
XQItemList makeRow( CreationMode mode, const XQNodePtr& sheetNode, const XQNodePtr& contentNode, const QString& captionKey=c_Caption ); XQItem* makeSingleItem( const XQNodePtr& sheetNode, const QString& caption );
// wozu ist das gut? // wozu ist das gut?
//XQItemList createGenericRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode ); //XQItemList createGenericRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode );
@@ -56,7 +54,7 @@ protected:
bool isValid(); bool isValid();
XQItem* makeItem( CreationMode mode, const XQNodePtr& sheetNode, const XQNodePtr& contentNode, const QString& captionKey ); XQItem* makeItem(const XQNodePtr& sheetNode, const XQNodePtr& contentNode );
// shortcuts // shortcuts
using ItemConfigFunc = std::function<void( XQItem* item, const QString& attrValue, XQNodePtr contentNode, XQNodePtr sheetNode )>; using ItemConfigFunc = std::function<void( XQItem* item, const QString& attrValue, XQNodePtr contentNode, XQNodePtr sheetNode )>;

View File

@@ -134,22 +134,9 @@ XQItemType* XQItemType::replaceAttribute( const QVariant& newValue, int role )
} }
//! formatiert den content() string eines items.
QVariant XQItemType::formatText( const XQItem& item ) const
{
XQItem::UnitType uType = unitType();
//qDebug() << " --- formatText: " << XQItem::fetchUnitTypeToString( uType);
const QString& cont = item.rawText();
if( uType != XQItem::NoUnitType )
return formatToSI( cont, uType );
return cont;
}
//! formatiert einen zahlenwert als string mit einheit. //! formatiert einen zahlenwert als string mit einheit.
QString XQItemType::formatToSI( const QString& valueTxt, XQItem::UnitType unitType ) const QString XQItemType::formatToSI( const QString& valueTxt, XQItem::UnitType unitType )
{ {
if( valueTxt.isEmpty() ) if( valueTxt.isEmpty() )
@@ -180,18 +167,18 @@ QString XQItemType::formatToSI( const QString& valueTxt, XQItem::UnitType unitTy
strVal = sysLocale.toString(nVal, 'f', 2); strVal = sysLocale.toString(nVal, 'f', 2);
strPrefix = s_PrefixExponentMap.key(exp); strPrefix = s_PrefixExponentMap.key(exp);
//qDebug() << " convert: " << dVal << " : " << valueTxt << ": " << strVal << ":" << exp << " : " << strPrefix << ": " << nVal; //qDebug() << " convert: " << dVal << " : " << valueTxt << ": " << strVal << ":" << exp << " : " << strPrefix << ": " << nVal;
QString unitStr = XQItem::fetchUnitTypeToString( unitType);
return QString("%1 %2%3").arg( strVal, strPrefix, unitTypeToString() ); return QString("%1 %2%3").arg( strVal, strPrefix, unitStr );
} }
//! entfernt die einheit aus einem formatierten string //! entfernt die einheit aus einem formatierten string
QString XQItemType::unFormatFromSI(const QString& formText ) const QString XQItemType::unFormatFromSI(const QString& formText )
{ {
QString input = formText.simplified(); const QString input = formText.simplified();
// #1: strip numeric part // #1: strip numeric part
if( input.isEmpty() ) if( input.isEmpty() )
return input; return input;

View File

@@ -40,17 +40,14 @@ public:
QVariant data( int role ) const override; QVariant data( int role ) const override;
void setData(const QVariant& value, int role ) override; void setData(const QVariant& value, int role ) override;
QVariant formatText( const XQItem& item ) const;
QString formatToSI(const QString& rawText, XQItem::UnitType unitType ) const;
QString unFormatFromSI(const QString& valueText ) const;
int roleForAttributeKey( const QString& attrKey ); int roleForAttributeKey( const QString& attrKey );
XQItemType* replaceAttribute(const QVariant& newValue, int role ); XQItemType* replaceAttribute(const QVariant& newValue, int role );
QString makeItemTypeKey(); QString makeItemTypeKey();
static XQItemType* staticItemType(); static XQItemType* staticItemType();
static QString formatToSI(const QString& rawText, XQItem::UnitType unitType );
static QString unFormatFromSI(const QString& valueText );
protected: protected:

View File

@@ -111,7 +111,7 @@ void XQViewModel::initModel(const QString& modelName)
const XQNodePtr header = sectionNode->find_child_by_tag_name( c_Header ); const XQNodePtr header = sectionNode->find_child_by_tag_name( c_Header );
if( header ) if( header )
{ {
XQItemList list = _itemFactory.makeRow( XQItemFactory::mHeader, header, nullptr ); XQItemList list = _itemFactory.makeRow( header, nullptr );
addSection(list, sectionNode ); addSection(list, sectionNode );
} }
} }
@@ -292,7 +292,7 @@ void XQViewModel::cmdCutUndo( const XQCommand& command )
const XQNodePtr& savedNode = entry.contentNode; const XQNodePtr& savedNode = entry.contentNode;
// __fix! should not be _contentRoot! // __fix! should not be _contentRoot!
savedNode->add_me_at( entry.nodePos, _contentRoot ); savedNode->add_me_at( entry.nodePos, _contentRoot );
XQItemList list = _itemFactory.makeRow( XQItemFactory::mData, section.sheetRootNode(), savedNode ); XQItemList list = _itemFactory.makeRow( section.sheetRootNode(), savedNode );
XQItem& firstItem = *((XQItem*)list[0]); XQItem& firstItem = *((XQItem*)list[0]);
qDebug() << " --- Cut Undo: " << firstItem.text() << " " << firstItem.row() << " id#" << entry.contentNode->_id << " count: " << entry.contentNode.use_count(); qDebug() << " --- Cut Undo: " << firstItem.text() << " " << firstItem.row() << " id#" << entry.contentNode->_id << " count: " << entry.contentNode.use_count();
@@ -328,7 +328,7 @@ void XQViewModel::cmdPaste( const XQCommand& command )
// ... diesen einfügen ... // ... diesen einfügen ...
newNode->add_me_at( nodePos ); newNode->add_me_at( nodePos );
// ... und damit eine frische item-row erzeugen // ... und damit eine frische item-row erzeugen
XQItemList list = _itemFactory.makeRow( XQItemFactory::mData, section.sheetRootNode(), newNode ); XQItemList list = _itemFactory.makeRow( section.sheetRootNode(), newNode );
insertRow( insRow, list ); insertRow( insRow, list );
// die neue item-row selektieren // die neue item-row selektieren
const QModelIndex& selIdx = list[0]->index(); const QModelIndex& selIdx = list[0]->index();

View File

@@ -7,18 +7,18 @@
--> -->
<ItemTypes> <ItemTypes>
<TreeParentType RenderStyle="PlainStyle" ItemFlags="IsEnabled|IsDropEnabled" Icon="DirIcon" /> <TreeParentType RenderStyle="PlainStyle" EditorType="LineEditType" ItemFlags="IsEnabled|IsDropEnabled" Icon="DirIcon" />
<TreeSectionType RenderStyle="PlainStyle" ItemFlags="IsEnabled" Icon="DesktopIcon"/> <TreeSectionType RenderStyle="PlainStyle" EditorType="LineEditType" ItemFlags="IsEnabled" Icon="DesktopIcon"/>
<TreeChildType RenderStyle="PlainStyle" ItemFlags="IsUserCheckable|IsEnabled" Icon="MediaPlay"/> <TreeChildType RenderStyle="PlainStyle" EditorType="LineEditType" ItemFlags="IsUserCheckable|IsEnabled" Icon="MediaPlay"/>
<HeaderType RenderStyle="HeaderStyle" ItemFlags="IsEnabled"/> <HeaderType RenderStyle="HeaderStyle" EditorType="LineEditType" ItemFlags="IsEnabled"/>
<HiddenType RenderStyle="HiddenStyle"/> <HiddenType RenderStyle="HiddenStyle"/>
<StaticType RenderStyle="PlainStyle"/> <StaticType RenderStyle="PlainStyle"/>
<PlainType RenderStyle="PlainStyle" ItemFlags="IsEnabled|IsEditable|IsSelectable"/> <PlainType RenderStyle="PlainStyle" EditorType="LineEditType" ItemFlags="IsEnabled|IsEditable|IsSelectable"/>
<ValueType RenderStyle="FormattedStyle" ItemFlags="IsEnabled|IsEditable|IsSelectable" UnitType="Coulomb"/> <ValueType RenderStyle="FormattedStyle" EditorType="LineEditType" ItemFlags="IsEnabled|IsEditable|IsSelectable" UnitType="Coulomb"/>
<CheckableType RenderStyle="FormattedStyle" ItemFlags="IsEnabled|IsEditable|IsSelectable" UnitType="###"/> <CheckableType RenderStyle="FormattedStyle" EditorType="LineEditType" ItemFlags="IsEnabled|IsEditable|IsSelectable" UnitType="###"/>
<PercentageType RenderStyle="ProgressBarStyle" ItemFlags="IsEnabled|IsSelectable"/> <PercentageType RenderStyle="ProgressBarStyle" EditorType="LineEditType" ItemFlags="IsEnabled|IsSelectable"/>
<ChoiceType RenderStyle="ComboBoxStyle" ItemFlags="IsEnabled|IsSelectable|IsEditable" FixedChoices="la|le|lo|lu"/> <ChoiceType RenderStyle="ComboBoxStyle" EditorType="ComboBoxType" ItemFlags="IsEnabled|IsSelectable|IsEditable" FixedChoices="la|le|lo|lu"/>
<IntValueType RenderStyle="SpinBoxStyle" ItemFlags="IsEnabled|IsSelectable"/> <IntValueType RenderStyle="SpinBoxStyle" EditorType="SpinBoxType" ItemFlags="IsEnabled|IsSelectable"/>
</ItemTypes> </ItemTypes>