-- pre-holiday
This commit is contained in:
@@ -15,7 +15,6 @@ TreeView
|
||||
columnWidthProvider: function(column)
|
||||
{
|
||||
var z= 1.7*(width / columns);
|
||||
console.log("höh!");
|
||||
return z;
|
||||
}
|
||||
|
||||
|
@@ -66,7 +66,7 @@ void XQChildModel::addModelData( const XQNodePtr& contentRoot )
|
||||
int newRow = _sections.lastRow(section);
|
||||
|
||||
XQNodePtr sheetNode = section.sheetRootNode();
|
||||
XQItemList list = _itemFactory.makeRow( XQItemFactory::mData, sheetNode, contentEntry );
|
||||
XQItemList list = _itemFactory.makeRow( sheetNode, contentEntry );
|
||||
|
||||
// als Baum?
|
||||
//section.headerItem().appendRow( list );
|
||||
@@ -84,7 +84,7 @@ void XQChildModel::addSectionEntry( const QString& key, const XQNodePtr& content
|
||||
section.setContentRootNode( contentEntry->parent() );
|
||||
int newRow = _sections.lastRow(section);
|
||||
XQNodePtr sheetNode = section.sheetRootNode();
|
||||
XQItemList list = _itemFactory.makeRow( XQItemFactory::mHeader, sheetNode, contentEntry );
|
||||
XQItemList list = _itemFactory.makeRow( sheetNode, nullptr );
|
||||
insertRow( newRow, list);
|
||||
}
|
||||
}
|
||||
|
@@ -51,18 +51,16 @@ XQItem* XQMainModel::addProjectItem( XQNodePtr contentNode )
|
||||
|
||||
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();
|
||||
|
||||
// __fixme! das ist mist!
|
||||
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 ...
|
||||
section.headerItem().appendRow( list );
|
||||
section.headerItem().appendRow( newItem );
|
||||
// ... ausklappen...
|
||||
const QModelIndex index = section.headerItem().index();
|
||||
_treeTable->expand( index );
|
||||
@@ -72,30 +70,56 @@ XQItem* XQMainModel::addProjectItem( XQNodePtr contentNode )
|
||||
//newItem->setContentNode( contentNode );
|
||||
//emit itemCreated( newItem );
|
||||
|
||||
XQItem* newItem = dynamic_cast<XQItem*>(list[0]);
|
||||
// erzeuger sheet node speichern
|
||||
newItem->setSheetNode( sheetNode );
|
||||
return newItem;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
throw XQException( "addProjectItem: main model should not be empty!" );
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
//
|
||||
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!
|
||||
|
||||
|
||||
/*
|
||||
XQNodePtr sheetNode = projectItem->sheetNode()->find_child_by_tag_name("CurrentSection");
|
||||
XQItemList list = _itemFactory.makeRow( XQItemFactory::mSingle, sheetNode, nullptr, c_ContentType );
|
||||
projectItem->appendRow( list );
|
||||
_treeTable->expand( projectItem->index() );
|
||||
*/
|
||||
|
||||
}
|
||||
|
@@ -116,6 +116,8 @@ XQItem::XQPrefixExponentMap XQItem::s_PrefixExponentMap
|
||||
};
|
||||
|
||||
|
||||
//! Default konstruktor, setzt einen ungültigen (dummy)
|
||||
//! itemType.
|
||||
|
||||
XQItem::XQItem()
|
||||
: XQItem{XQItemType::staticItemType()}
|
||||
@@ -123,6 +125,9 @@ XQItem::XQItem()
|
||||
|
||||
}
|
||||
|
||||
|
||||
//! Default konstruktor mit einem vorhandenen itemType.
|
||||
|
||||
XQItem::XQItem( XQItemType* itemType )
|
||||
: 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{ itemType }
|
||||
{
|
||||
setContent(content);
|
||||
}
|
||||
|
||||
XQItem::XQItem( XQItemType* itemType, const QString& content )
|
||||
: XQItem{ itemType }
|
||||
{
|
||||
setText(content);
|
||||
}
|
||||
//! ruft den copy-konstruktor auf.
|
||||
|
||||
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.
|
||||
|
||||
XQNodePtr XQItem::contentNode() const
|
||||
{
|
||||
XQNodePtr node = data( ContentNodeRole ).value<XQNodePtr>();
|
||||
if( node )
|
||||
return node;
|
||||
throw XQException("XQItem::contentNode() nullptr");
|
||||
return data( ContentNodeRole ).value<XQNodePtr>();
|
||||
}
|
||||
|
||||
|
||||
@@ -319,15 +337,16 @@ QString XQItem::rawText() const
|
||||
|
||||
|
||||
//! Gibt den string-zeiger auf das attribut aus unseren XQNodePtr zurück.
|
||||
|
||||
/*
|
||||
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*>();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
//! set den content()-string pointer. (als leihgabe)
|
||||
//! Setzt den content()-string pointer. (als leihgabe)
|
||||
|
||||
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
|
||||
{
|
||||
return contentNode()->attributes().key_of( rawText() );
|
||||
}
|
||||
|
||||
//! gibt den content-format string zurück
|
||||
//! Gibt den content-format string zurück
|
||||
|
||||
QString XQItem::contentFormat() const
|
||||
{
|
||||
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)
|
||||
{
|
||||
@@ -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.
|
||||
|
||||
QStandardItemModel* XQItem::fixedChoices() const
|
||||
@@ -413,6 +432,23 @@ QString XQItem::dataRoleName(int role) const
|
||||
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
|
||||
//! werden vom xqitemtype geholt
|
||||
|
||||
@@ -438,33 +474,34 @@ QVariant XQItem::data(int role ) const
|
||||
return itemType().data(role);
|
||||
}
|
||||
|
||||
// Zugriffe auf den sichtbaren inhalt geben den inhalt des string pointer
|
||||
// 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 :
|
||||
case XQItem::ContentRole:
|
||||
{
|
||||
if( itemType().renderStyle() == XQItem::FormattedStyle)//return "display:"+content();
|
||||
return itemType().formatText( *this );
|
||||
[[fallthrough]];
|
||||
qDebug() << " --- data(XQItem::ContentRole) should NOT be called!";
|
||||
return *QStandardItem::data( XQItem::ContentRole ).value<QString*>();
|
||||
}
|
||||
|
||||
// EditRole & ContentRole sollen den 'rohen' inhalt unseres string-pointers
|
||||
// auf den original inhalt im content node zurückgeben.
|
||||
|
||||
case Qt::EditRole :
|
||||
case XQItem::ContentRole:
|
||||
case Qt::EditRole :
|
||||
{
|
||||
// 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*>();
|
||||
if(contentPtr)
|
||||
return *contentPtr;
|
||||
return contentFallBackText();
|
||||
//[[fallthrough]];
|
||||
}
|
||||
|
||||
static const QString s_dummyContent("-");
|
||||
return s_dummyContent;
|
||||
// DisplayRole gibt den formatierten inhalt wieder. die formatierung übernimmt
|
||||
// der item type
|
||||
|
||||
case Qt::DisplayRole :
|
||||
{
|
||||
QString plainText = contentFallBackText();
|
||||
if( renderStyle() == XQItem::FormattedStyle)
|
||||
return XQItemType::formatToSI( plainText, unitType() );
|
||||
return plainText;
|
||||
}
|
||||
|
||||
case Qt::ToolTipRole:
|
||||
@@ -482,7 +519,7 @@ QVariant XQItem::data(int role ) const
|
||||
// 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 );
|
||||
return QStandardItem::data( XQItem::ContentNodeRole );
|
||||
|
||||
// sonst: delegieren an den node-Besitzer
|
||||
QModelIndex pIndex = model()->index( row(), 0 );
|
||||
@@ -557,25 +594,67 @@ void XQItem::setData(const QVariant& value, int role )
|
||||
return;
|
||||
}
|
||||
|
||||
// set the raw, unformatted data
|
||||
case ContentRole:
|
||||
case XQItem::ContentRole:
|
||||
{
|
||||
// string ptr setzen kann die basis.
|
||||
break;
|
||||
qDebug() << " --- data(XQItem::ContentRole) should NOT be called!";
|
||||
// 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 XQItem::ContentRole:
|
||||
{
|
||||
qDebug() << " --- setting EDITrole: " << value.toString();
|
||||
break;
|
||||
}
|
||||
|
||||
case Qt::DisplayRole :
|
||||
{
|
||||
// what will happen? value is a string ptr ?!
|
||||
qDebug() << " --- setting DISPLAYrole: " << value.toString();
|
||||
const QString* contentPtr = QStandardItem::data( XQItem::ContentRole ).value<const QString*>();
|
||||
if(contentPtr)
|
||||
return *contentPtr;
|
||||
if( )
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
*/
|
||||
|
||||
// alles andere wie gehabt
|
||||
case ContentNodeRole:
|
||||
|
@@ -133,6 +133,7 @@ public:
|
||||
XQItem();
|
||||
XQItem( XQItemType* itemType );
|
||||
XQItem( XQItemType* itemType, const QString* content );
|
||||
XQItem( XQItemType* itemType, const QString& content );
|
||||
|
||||
virtual ~XQItem() = default;
|
||||
|
||||
@@ -143,7 +144,8 @@ public:
|
||||
//!
|
||||
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 sheetNode() const;
|
||||
@@ -162,7 +164,7 @@ public:
|
||||
QString rawText() const;
|
||||
|
||||
// changed: gibt jetzt den pointer zurück.
|
||||
QString* content() const;
|
||||
//QString* content() const;
|
||||
QString contentKey() const;
|
||||
void setContent( const QString* content );
|
||||
|
||||
@@ -241,6 +243,9 @@ protected:
|
||||
XQItem(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 );
|
||||
|
||||
using XQItemFlagMap = QMap<QString,int>;
|
||||
|
@@ -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
|
||||
{
|
||||
|
||||
return QStyledItemDelegate::createEditor( parent, option, index );
|
||||
|
||||
int editorType = XQItem::xqItemFromIndex(index).editorType();
|
||||
QWidget* editor = itemEditorFactory()->createEditor(editorType, parent);
|
||||
if( editor )
|
||||
XQItem& item = xqItemFromIndex(index);
|
||||
XQItem::EditorType edType = item.editorType();
|
||||
if( !item.hasContentNode() || edType == XQItem::NoEditorType )
|
||||
{
|
||||
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
|
||||
{
|
||||
|
||||
XQItem& item = xqItemFromIndex( index );
|
||||
switch( item.editorType() )
|
||||
XQItem::EditorType edType = item.editorType();
|
||||
if( edType != XQItem::NoEditorType )
|
||||
{
|
||||
switch( edType )
|
||||
{
|
||||
case XQItemType::ComboBoxType :
|
||||
{
|
||||
QComboBox* comboBox = qobject_cast<QComboBox*>(editor);
|
||||
@@ -251,11 +259,23 @@ void XQItemDelegate::setEditorData(QWidget* editor, const QModelIndex& index) co
|
||||
}
|
||||
|
||||
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
|
||||
|
@@ -99,6 +99,7 @@ XQItemType* XQItemFactory::makeItemType(const XQNodePtr& sheetEntry )
|
||||
return itemType;
|
||||
}
|
||||
|
||||
|
||||
//! sucht einen item typ aus der map mit 'vorgefertigen' itemtypen.
|
||||
|
||||
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 )
|
||||
{
|
||||
@@ -304,7 +301,7 @@ XQItemList XQItemFactory::createGenericRow( const XQNodePtr& contentNode, const
|
||||
|
||||
//! 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;
|
||||
@@ -320,24 +317,23 @@ XQItemList XQItemFactory::makeRow(CreationMode mode, const XQNodePtr& sheetNode,
|
||||
//
|
||||
|
||||
for( const auto& sheetEntry : sheetNode->children() )
|
||||
list.append( makeItem( mode, sheetEntry, contentNode, captionKey ) );
|
||||
list.append( makeItem( sheetEntry, contentNode ) );
|
||||
|
||||
Q_ASSERT(!list.empty());
|
||||
|
||||
// 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);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
//! fixme! unsinn!
|
||||
//! 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
|
||||
//! verwendet: es handelt sich dann um ein header item, das erzeugt wurde.
|
||||
//! 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
|
||||
//! verwendet: es handelt sich dann um ein header item
|
||||
|
||||
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
|
||||
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,
|
||||
// sonst wird der content indirekt über den tag-name des sheetnode geholt
|
||||
|
||||
switch( mode )
|
||||
{
|
||||
case mHeader:
|
||||
contentPtr = sheetNode->attribute_ptr(captionKey);
|
||||
break;
|
||||
|
||||
case mData:
|
||||
contentPtr = contentNode->attribute_ptr( sheetNode->tag_name() );
|
||||
break;
|
||||
|
||||
case mSingle:
|
||||
contentPtr = contentNode->attribute_ptr( captionKey );
|
||||
}
|
||||
if( !contentNode )
|
||||
contentPtr = sheetNode->attribute_ptr(c_Caption);
|
||||
else
|
||||
contentPtr = contentNode->attribute_ptr( sheetNode->tag_name() );
|
||||
|
||||
XQItem* newItem = new XQItem( itemType, contentPtr);
|
||||
|
||||
@@ -371,3 +358,18 @@ XQItem* XQItemFactory::makeItem(CreationMode mode, const XQNodePtr& sheetNode, c
|
||||
|
||||
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;
|
||||
}
|
||||
|
@@ -28,20 +28,18 @@ class XQItemFactory : public xsingleton<XQItemFactory>
|
||||
|
||||
public:
|
||||
|
||||
enum CreationMode
|
||||
{
|
||||
mHeader,
|
||||
mData,
|
||||
mSingle
|
||||
};
|
||||
|
||||
|
||||
void initItemFactory(const QString& modelSheetFileName );
|
||||
|
||||
XQNodePtr findModelSheet( const QString& modelName ) const;
|
||||
|
||||
XQItemList makeRow( const XQNodePtr& sheetNode, const XQNodePtr& contentNode );
|
||||
|
||||
//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?
|
||||
//XQItemList createGenericRow( const XQNodePtr& contentNode, const XQNodePtr& sheetNode );
|
||||
@@ -56,7 +54,7 @@ protected:
|
||||
|
||||
bool isValid();
|
||||
|
||||
XQItem* makeItem( CreationMode mode, const XQNodePtr& sheetNode, const XQNodePtr& contentNode, const QString& captionKey );
|
||||
XQItem* makeItem(const XQNodePtr& sheetNode, const XQNodePtr& contentNode );
|
||||
|
||||
// shortcuts
|
||||
using ItemConfigFunc = std::function<void( XQItem* item, const QString& attrValue, XQNodePtr contentNode, XQNodePtr sheetNode )>;
|
||||
|
@@ -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.
|
||||
|
||||
QString XQItemType::formatToSI( const QString& valueTxt, XQItem::UnitType unitType ) const
|
||||
QString XQItemType::formatToSI( const QString& valueTxt, XQItem::UnitType unitType )
|
||||
{
|
||||
|
||||
if( valueTxt.isEmpty() )
|
||||
@@ -180,18 +167,18 @@ QString XQItemType::formatToSI( const QString& valueTxt, XQItem::UnitType unitTy
|
||||
strVal = sysLocale.toString(nVal, 'f', 2);
|
||||
strPrefix = s_PrefixExponentMap.key(exp);
|
||||
//qDebug() << " convert: " << dVal << " : " << valueTxt << ": " << strVal << ":" << exp << " : " << strPrefix << ": " << nVal;
|
||||
|
||||
return QString("%1 %2%3").arg( strVal, strPrefix, unitTypeToString() );
|
||||
QString unitStr = XQItem::fetchUnitTypeToString( unitType);
|
||||
return QString("%1 %2%3").arg( strVal, strPrefix, unitStr );
|
||||
|
||||
}
|
||||
|
||||
|
||||
//! 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
|
||||
if( input.isEmpty() )
|
||||
return input;
|
||||
|
@@ -40,17 +40,14 @@ public:
|
||||
QVariant data( int role ) const 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 );
|
||||
XQItemType* replaceAttribute(const QVariant& newValue, int role );
|
||||
|
||||
QString makeItemTypeKey();
|
||||
|
||||
static XQItemType* staticItemType();
|
||||
static QString formatToSI(const QString& rawText, XQItem::UnitType unitType );
|
||||
static QString unFormatFromSI(const QString& valueText );
|
||||
|
||||
protected:
|
||||
|
||||
|
@@ -111,7 +111,7 @@ void XQViewModel::initModel(const QString& modelName)
|
||||
const XQNodePtr header = sectionNode->find_child_by_tag_name( c_Header );
|
||||
if( header )
|
||||
{
|
||||
XQItemList list = _itemFactory.makeRow( XQItemFactory::mHeader, header, nullptr );
|
||||
XQItemList list = _itemFactory.makeRow( header, nullptr );
|
||||
addSection(list, sectionNode );
|
||||
}
|
||||
}
|
||||
@@ -292,7 +292,7 @@ void XQViewModel::cmdCutUndo( const XQCommand& command )
|
||||
const XQNodePtr& savedNode = entry.contentNode;
|
||||
// __fix! should not be _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]);
|
||||
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 ...
|
||||
newNode->add_me_at( nodePos );
|
||||
// ... 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 );
|
||||
// die neue item-row selektieren
|
||||
const QModelIndex& selIdx = list[0]->index();
|
||||
|
@@ -7,18 +7,18 @@
|
||||
-->
|
||||
|
||||
<ItemTypes>
|
||||
<TreeParentType RenderStyle="PlainStyle" ItemFlags="IsEnabled|IsDropEnabled" Icon="DirIcon" />
|
||||
<TreeSectionType RenderStyle="PlainStyle" ItemFlags="IsEnabled" Icon="DesktopIcon"/>
|
||||
<TreeChildType RenderStyle="PlainStyle" ItemFlags="IsUserCheckable|IsEnabled" Icon="MediaPlay"/>
|
||||
<HeaderType RenderStyle="HeaderStyle" ItemFlags="IsEnabled"/>
|
||||
<TreeParentType RenderStyle="PlainStyle" EditorType="LineEditType" ItemFlags="IsEnabled|IsDropEnabled" Icon="DirIcon" />
|
||||
<TreeSectionType RenderStyle="PlainStyle" EditorType="LineEditType" ItemFlags="IsEnabled" Icon="DesktopIcon"/>
|
||||
<TreeChildType RenderStyle="PlainStyle" EditorType="LineEditType" ItemFlags="IsUserCheckable|IsEnabled" Icon="MediaPlay"/>
|
||||
<HeaderType RenderStyle="HeaderStyle" EditorType="LineEditType" ItemFlags="IsEnabled"/>
|
||||
<HiddenType RenderStyle="HiddenStyle"/>
|
||||
<StaticType RenderStyle="PlainStyle"/>
|
||||
<PlainType RenderStyle="PlainStyle" ItemFlags="IsEnabled|IsEditable|IsSelectable"/>
|
||||
<ValueType RenderStyle="FormattedStyle" ItemFlags="IsEnabled|IsEditable|IsSelectable" UnitType="Coulomb"/>
|
||||
<CheckableType RenderStyle="FormattedStyle" ItemFlags="IsEnabled|IsEditable|IsSelectable" UnitType="###"/>
|
||||
<PercentageType RenderStyle="ProgressBarStyle" ItemFlags="IsEnabled|IsSelectable"/>
|
||||
<ChoiceType RenderStyle="ComboBoxStyle" ItemFlags="IsEnabled|IsSelectable|IsEditable" FixedChoices="la|le|lo|lu"/>
|
||||
<IntValueType RenderStyle="SpinBoxStyle" ItemFlags="IsEnabled|IsSelectable"/>
|
||||
<PlainType RenderStyle="PlainStyle" EditorType="LineEditType" ItemFlags="IsEnabled|IsEditable|IsSelectable"/>
|
||||
<ValueType RenderStyle="FormattedStyle" EditorType="LineEditType" ItemFlags="IsEnabled|IsEditable|IsSelectable" UnitType="Coulomb"/>
|
||||
<CheckableType RenderStyle="FormattedStyle" EditorType="LineEditType" ItemFlags="IsEnabled|IsEditable|IsSelectable" UnitType="###"/>
|
||||
<PercentageType RenderStyle="ProgressBarStyle" EditorType="LineEditType" ItemFlags="IsEnabled|IsSelectable"/>
|
||||
<ChoiceType RenderStyle="ComboBoxStyle" EditorType="ComboBoxType" ItemFlags="IsEnabled|IsSelectable|IsEditable" FixedChoices="la|le|lo|lu"/>
|
||||
<IntValueType RenderStyle="SpinBoxStyle" EditorType="SpinBoxType" ItemFlags="IsEnabled|IsSelectable"/>
|
||||
</ItemTypes>
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user