-- fyerabend

This commit is contained in:
2025-08-08 21:39:33 +02:00
parent 666a2a9440
commit 5919d9d90d
15 changed files with 228 additions and 257 deletions

View File

@@ -16,9 +16,7 @@
#include <xqitem.h> #include <xqitem.h>
#include <QFile> #include <QFile>
//! firz
XQDocument::XQDocument(const QString& aFileName, const QString& aFriendlyName, XQItem* aTreeItem, XQViewModel* aModelView ) XQDocument::XQDocument(const QString& aFileName, const QString& aFriendlyName, XQItem* aTreeItem, XQViewModel* aModelView )
: fileName{ aFileName }, friendlyName{ aFriendlyName }, treeItem{ aTreeItem }, modelView{ aModelView } : fileName{ aFileName }, friendlyName{ aFriendlyName }, treeItem{ aTreeItem }, modelView{ aModelView }
@@ -26,6 +24,8 @@ XQDocument::XQDocument(const QString& aFileName, const QString& aFriendlyName, X
} }
//! firz
XQDocument::~XQDocument() XQDocument::~XQDocument()
{ {
//delete _documentRoot; //delete _documentRoot;
@@ -37,6 +37,8 @@ XQDocument::~XQDocument()
/// ///
//! firz
XQDocumentStore::~XQDocumentStore() XQDocumentStore::~XQDocumentStore()
{ {
//for (auto entry : *this) //for (auto entry : *this)
@@ -46,6 +48,7 @@ XQDocumentStore::~XQDocumentStore()
} }
//! firz
void XQDocumentStore::addDocument( const QString& aFileName, const QString& aFriendlyName, XQItem* aTreeItem, XQViewModel* aModelView ) void XQDocumentStore::addDocument( const QString& aFileName, const QString& aFriendlyName, XQItem* aTreeItem, XQViewModel* aModelView )
{ {

View File

@@ -26,18 +26,15 @@
#include <xqitemfactory.h> #include <xqitemfactory.h>
//! default konstruktor.
XQMainModel::XQMainModel(QObject *parent ) XQMainModel::XQMainModel(QObject *parent )
: XQViewModel{parent} : XQViewModel{parent}
{ {
} }
//! initialisiert dieses model über den namen.
XQMainModel::~XQMainModel()
{
// delete
}
void XQMainModel::initModel(const QString& modelName) void XQMainModel::initModel(const QString& modelName)
{ {
@@ -56,6 +53,8 @@ void XQMainModel::initModel(const QString& modelName)
} }
//! erzeugt einen eintrag in der baum-übersicht.
XQItem* XQMainModel::createTreeEntry( XQNodePtr contentNode ) XQItem* XQMainModel::createTreeEntry( XQNodePtr contentNode )
{ {
for(const auto& section : _sections ) for(const auto& section : _sections )
@@ -75,6 +74,7 @@ XQItem* XQMainModel::createTreeEntry( XQNodePtr contentNode )
throw XQException( "createTreeEntry: main model should not be emtpy!" ); throw XQException( "createTreeEntry: main model should not be emtpy!" );
} }
//! firz
void XQMainModel::initContextMenu() void XQMainModel::initContextMenu()
{ {

View File

@@ -30,7 +30,7 @@ class XQMainModel : public XQViewModel
public: public:
explicit XQMainModel(QObject *parent = nullptr); explicit XQMainModel(QObject *parent = nullptr);
virtual ~XQMainModel(); virtual ~XQMainModel() = default;
void initModel(const QString& modelName) override; void initModel(const QString& modelName) override;
XQItem* createTreeEntry( XQNodePtr contentNode ); XQItem* createTreeEntry( XQNodePtr contentNode );

View File

@@ -23,6 +23,7 @@
#include <xqnodewriter.h> #include <xqnodewriter.h>
//! firz
XQMainWindow::XQMainWindow( QWidget* parent ) XQMainWindow::XQMainWindow( QWidget* parent )
: QMainWindow(parent) : QMainWindow(parent)
@@ -32,6 +33,9 @@ XQMainWindow::XQMainWindow( QWidget* parent )
initMainWindow(); initMainWindow();
} }
//! firz
void XQMainWindow::initMainWindow() void XQMainWindow::initMainWindow()
{ {
@@ -97,6 +101,9 @@ void XQMainWindow::initMainWindow()
} }
//! firz
void XQMainWindow::onUndo() void XQMainWindow::onUndo()
{ {
qDebug() << " --- undo Pressed"; qDebug() << " --- undo Pressed";
@@ -105,6 +112,9 @@ void XQMainWindow::onUndo()
} }
//!
void XQMainWindow::onRedo() void XQMainWindow::onRedo()
{ {
qDebug() << " --- redo Pressed"; qDebug() << " --- redo Pressed";
@@ -114,12 +124,16 @@ void XQMainWindow::onRedo()
} }
//! erzeugt ein document
void XQMainWindow::onCreateDocument() void XQMainWindow::onCreateDocument()
{ {
qDebug() << " ---- create document Pressed!"; qDebug() << " ---- create document Pressed!";
} }
//! öffnet ein XML document
void XQMainWindow::onOpenDocument() void XQMainWindow::onOpenDocument()
{ {
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Project"), c_DocumentDirectory, tr("project data(*.xtr)") ); QString fileName = QFileDialog::getOpenFileName(this, tr("Open Project"), c_DocumentDirectory, tr("project data(*.xtr)") );
@@ -137,6 +151,7 @@ void XQMainWindow::onOpenDocument()
} }
//! speichert ein XML document
void XQMainWindow::onSaveDocument() void XQMainWindow::onSaveDocument()
{ {
@@ -145,6 +160,9 @@ void XQMainWindow::onSaveDocument()
} }
//! fragt nach einem datei-namen und speichert das akutelle XML
//! document unter diesem
void XQMainWindow::onSaveDocumentAs() void XQMainWindow::onSaveDocumentAs()
{ {
QString fileName = QFileDialog::getSaveFileName(this, "Save as", c_DocumentDirectory, tr("project data(*.xtr)") ); QString fileName = QFileDialog::getSaveFileName(this, "Save as", c_DocumentDirectory, tr("project data(*.xtr)") );
@@ -162,17 +180,24 @@ void XQMainWindow::onSaveDocumentAs()
} }
//! wird aufgerufen, wenn ein XML geschlossen werden soll.
void XQMainWindow::onCloseDocument() void XQMainWindow::onCloseDocument()
{ {
qDebug() << " ---- close Pressed!"; qDebug() << " ---- close Pressed!";
} }
//! beendet diese application
void XQMainWindow::onExit() void XQMainWindow::onExit()
{ {
qApp->exit(); qApp->exit();
} }
//! zeigt den about-dialog
void XQMainWindow::onAbout() void XQMainWindow::onAbout()
{ {
@@ -189,6 +214,7 @@ void XQMainWindow::onAbout()
} }
//! firz
// when item in the left tree is clicked, switch view on the right side // when item in the left tree is clicked, switch view on the right side
void XQMainWindow::onTreeItemClicked(const QModelIndex& index ) void XQMainWindow::onTreeItemClicked(const QModelIndex& index )
{ {
@@ -207,6 +233,8 @@ void XQMainWindow::onTreeItemClicked(const QModelIndex& index )
} }
//! firz
// when item in the left tree is clicked, switch view on the right side // when item in the left tree is clicked, switch view on the right side
void XQMainWindow::onTabClicked( int index ) void XQMainWindow::onTabClicked( int index )
{ {
@@ -215,9 +243,11 @@ void XQMainWindow::onTabClicked( int index )
_mainTreeView->setCurrentIndex( _documentStore[index].treeItem->index() ); _mainTreeView->setCurrentIndex( _documentStore[index].treeItem->index() );
} }
//! liest eine XML datei namens 'fileName'
void XQMainWindow::loadDocument( const QString& fileName ) void XQMainWindow::loadDocument( const QString& fileName )
{ {
//ntThrowIfNullPtr
// gibts die Datei? // gibts die Datei?
if( !QFile::exists( fileName) ) if( !QFile::exists( fileName) )
throw XQException( "no such file", fileName ); throw XQException( "no such file", fileName );
@@ -271,6 +301,8 @@ void XQMainWindow::loadDocument( const QString& fileName )
} }
//! speichert ein XML unter dem 'filename'
void XQMainWindow::saveDocument( const QString& fileName ) void XQMainWindow::saveDocument( const QString& fileName )
{ {
XQNodeWriter nodeWriter; XQNodeWriter nodeWriter;

View File

@@ -144,42 +144,11 @@ XQItem::XQItem(XQItemType* itemType, const QString *content, const XQNodePtr& co
} }
/* //! ruft den copy-konstruktor auf.
XQItem::XQItem(const XQItem& other)
: QStandardItem( other )
{
// QStandardItem( other ) koopiert bereits
// die data() struktur
}
XQItem& XQItem::operator=(const XQItem& other)
{
if( this != &other)
{
// kopiert data()
this->QStandardItem::operator=( other );
}
return *this;
}
*/
//! firz
XQItem::~XQItem()
{
}
//! firz
XQItem* XQItem::clone() const XQItem* XQItem::clone() const
{ {
//return new XQItem( *this ); return new XQItem( *this );
// this is used as invisible filling material
//return new XQItem( "", XQItemType::StaticStyle );
// __fix!
return new XQItem();
} }
@@ -193,7 +162,7 @@ bool XQItem::isValid() const
} }
//! firz //! gibt den content-node zurück.
XQNodePtr XQItem::contentNode() const XQNodePtr XQItem::contentNode() const
{ {
@@ -201,7 +170,7 @@ XQNodePtr XQItem::contentNode() const
} }
//! firz //! setzt den content node.
void XQItem::setContentNode( const XQNodePtr& contentNode ) void XQItem::setContentNode( const XQNodePtr& contentNode )
{ {
@@ -209,15 +178,14 @@ void XQItem::setContentNode( const XQNodePtr& contentNode )
} }
//! firz //! gibt den sheet-node zurück.
XQNodePtr XQItem::sheetNode() const XQNodePtr XQItem::sheetNode() const
{ {
//
return data( SheetNodeRole ).value<XQNodePtr>(); return data( SheetNodeRole ).value<XQNodePtr>();
} }
//! firz //! setzt den sheet-node
void XQItem::setSheetNode(const XQNodePtr& sheetNode ) void XQItem::setSheetNode(const XQNodePtr& sheetNode )
{ {
@@ -225,7 +193,7 @@ void XQItem::setSheetNode(const XQNodePtr& sheetNode )
} }
//! firz //! tested, ob ein attribut mit dem namen 'attribKey' vorhanden ist.
bool XQItem::hasAttribute( const QString& attribKey ) const bool XQItem::hasAttribute( const QString& attribKey ) const
{ {
@@ -233,7 +201,7 @@ bool XQItem::hasAttribute( const QString& attribKey ) const
} }
//! firz //! gibt das attribut namens 'attribKey' zurück, sofern vorhanden, sonst 'defaultValue'
const QString& XQItem::attribute( const QString& attribKey, const QString& defaultValue ) const const QString& XQItem::attribute( const QString& attribKey, const QString& defaultValue ) const
{ {
@@ -243,7 +211,7 @@ const QString& XQItem::attribute( const QString& attribKey, const QString& defau
} }
//! firz //! tested, ob das attribut namens 'attribKey' dem wert 'attribValue' entspricht.
bool XQItem::testAttribute( const QString& attribKey, const QString& attribValue ) const bool XQItem::testAttribute( const QString& attribKey, const QString& attribValue ) const
{ {
@@ -251,15 +219,21 @@ bool XQItem::testAttribute( const QString& attribKey, const QString& attribValue
} }
//! firz //! gibt eine referenz auf den itemType dieses items zurück.
XQItemType& XQItem::itemType() const XQItemType& XQItem::itemType() const
{ {
// __fix: wir gehen hier davon aus, das der itemType immer existiert,
// nur weil er in jeden konstruktor gesetzt wird, das muss aber nicht
// so sein!
XQItemType* itemTypePtr = QStandardItem::data( XQItem::ItemTypeRole ).value<XQItemType*>(); XQItemType* itemTypePtr = QStandardItem::data( XQItem::ItemTypeRole ).value<XQItemType*>();
return *itemTypePtr; return *itemTypePtr;
// should_throw
} }
//! firz
//! speichert einen neuen itemType.
void XQItem::setItemType( XQItemType* itemTypePtr ) void XQItem::setItemType( XQItemType* itemTypePtr )
{ {
@@ -268,7 +242,7 @@ void XQItem::setItemType( XQItemType* itemTypePtr )
} }
//! firz //! set ein einzelnes itemFlag.
void XQItem::addFlag( Qt::ItemFlag newFlag ) void XQItem::addFlag( Qt::ItemFlag newFlag )
{ {
@@ -276,7 +250,7 @@ void XQItem::addFlag( Qt::ItemFlag newFlag )
} }
//! firz //! löscht ein einzelnes itemFlag.
void XQItem::clearFlag( Qt::ItemFlag newFlag ) void XQItem::clearFlag( Qt::ItemFlag newFlag )
{ {
@@ -287,7 +261,7 @@ void XQItem::clearFlag( Qt::ItemFlag newFlag )
/// data() access shortcuts /// data() access shortcuts
/// ///
//! firz //! gibt den renderStyle zurück.
XQItem::RenderStyle XQItem::renderStyle() const XQItem::RenderStyle XQItem::renderStyle() const
{ {
@@ -295,37 +269,38 @@ XQItem::RenderStyle XQItem::renderStyle() const
} }
//! firz //! gibt den renderStyle als string zurück.
QString XQItem::renderStyleToString() const QString XQItem::renderStyleToString() const
{ {
return XQItem::fetchRenderStyleToString( renderStyle() ); return XQItem::fetchRenderStyleToString( renderStyle() );
} }
//! firz
//! setzt den editorType. wird im itemType gespeichert.
void XQItem::setRenderStyle(RenderStyle renderStyle ) void XQItem::setRenderStyle(RenderStyle renderStyle )
{ {
setData( QVariant::fromValue(renderStyle), XQItem::RenderStyleRole ); setData( QVariant::fromValue(renderStyle), XQItem::RenderStyleRole );
// Der RenderStyle wohnt im ItemType
//itemType().replaceAttribute( this, RenderStyleRole, renderStyle );
} }
//! gibt den editorType zurück.
XQItem::EditorType XQItem::editorType() const XQItem::EditorType XQItem::editorType() const
{ {
return data( EditorTypeRole ).value<EditorType>(); return data( EditorTypeRole ).value<EditorType>();
} }
//! firz //! gibt den renderStyle als string zurück.
QString XQItem::editorTypeToString() const QString XQItem::editorTypeToString() const
{ {
return XQItem::fetchEditorTypeToString( editorType() ); return XQItem::fetchEditorTypeToString( editorType() );
} }
//! firz //! setzt den editorType. wird im itemType gespeichert.
void XQItem::setEditorType(EditorType editorType) void XQItem::setEditorType(EditorType editorType)
{ {
@@ -335,7 +310,7 @@ void XQItem::setEditorType(EditorType editorType)
} }
//! firz //! setzt den unitType.
XQItem::UnitType XQItem::unitType() const XQItem::UnitType XQItem::unitType() const
{ {
@@ -343,7 +318,7 @@ XQItem::UnitType XQItem::unitType() const
} }
//! firz //! gibt den unitType als string zurück.
QString XQItem::unitTypeToString() const QString XQItem::unitTypeToString() const
{ {
@@ -351,7 +326,7 @@ QString XQItem::unitTypeToString() const
} }
//! firz //! setzt den editorType. wird im itemType gespeichert.
void XQItem::setUnitType(UnitType unitType) void XQItem::setUnitType(UnitType unitType)
{ {
@@ -359,7 +334,8 @@ void XQItem::setUnitType(UnitType unitType)
} }
//! firz //! gibt den content-string zurück. das ist ein derefenzierter pointer
//! auf das zu diesem item gehörige daten-attribut 'useres' datenknotens.
const QString& XQItem::content() const const QString& XQItem::content() const
{ {
@@ -373,7 +349,7 @@ const QString& XQItem::content() const
} }
//! firz //! set den content()-string pointer. (als leihgabe)
void XQItem::setContent( const QString* content ) void XQItem::setContent( const QString* content )
{ {
@@ -381,7 +357,7 @@ void XQItem::setContent( const QString* content )
} }
//! firz //! holt den schlüssel bzw. bezeicher des content() string aus 'unserem' content knoten.
const QString& XQItem::contentKey() const const QString& XQItem::contentKey() const
{ {
@@ -395,6 +371,7 @@ QString XQItem::contentFormat() const
return data( XQItem::ContentFormatRole ).toString(); return data( XQItem::ContentFormatRole ).toString();
} }
//! setz den den content format-string. wird im itemType gespeichert.
void XQItem::setContentFormat(const QString& contentFormat) void XQItem::setContentFormat(const QString& contentFormat)
{ {
@@ -403,7 +380,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) //! combobox gerendert wird). wird im itemType gespeichert.
QStandardItemModel* XQItem::fixedChoices() const QStandardItemModel* XQItem::fixedChoices() const
{ {
@@ -451,7 +428,7 @@ bool XQItem::isHeaderStyle()
//! gibt den namen der datarole zurück //! gibt den namen der datarole zurück
QString XQItem::dataRoleName(int role) QString XQItem::dataRoleName(int role) const
{ {
if( role < XQItem::NoRole && model() ) if( role < XQItem::NoRole && model() )
return model()->roleNames()[role]; return model()->roleNames()[role];
@@ -483,10 +460,23 @@ QVariant XQItem::data(int role ) const
return itemType().data(role); return itemType().data(role);
} }
// Das ist der Sonderfall, hier dereferenzieren wir den // Zugriffe auf den sichtbaren inhalt geben den inhalt des string pointer
// Zeiger auf den QString* aus unserem XQNodePtr // 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 Qt::DisplayRole :
{
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: case XQItem::ContentRole:
{ {
@@ -538,41 +528,85 @@ QVariant XQItem::data(int role ) const
} }
/*!
Überschreibt setData() vom QStandardItem. Es wird unterschieden zwischen den data roles, die von
'unserem' itemType verwaltet und gespeichert werden und unseren eigenen. ein XQItem enthält nur folgende
Felder:
// - die ItemFlags (geerbt vom QStandardItem) stimmt nicht!
- den pointer auf den ItemType
- den pointer auf den inhalts-string: content()
Die anderen werte werden vom itemType verwaltet:
- der EditorType
- der RenderStyle
- der UnitType
- das ContentFormat
- das Icon
- ggf. das choiceModel, falls dieses Item als combobox gerendert wird.
*/
void XQItem::setData(const QVariant& value, int role ) void XQItem::setData(const QVariant& value, int role )
{ {
//replaceAttribute( XQItem* item, XQItem::ItemDataRole role, const QVariant& newValue)
//emitDataChanged()
switch(role) switch(role)
{ {
// das ist ein pointer auf den original-string aus dem XML
// ContentRole :
// ItemTypeRole :
case RenderStyleRole : case RenderStyleRole :
case EditorTypeRole : case EditorTypeRole :
case UnitTypeRole: case UnitTypeRole:
case ContentFormatRole: case ContentFormatRole:
case FlagsRole: case FlagsRole: // Stimmt das?
case IconRole: case IconRole:
case FixedChoicesRole: case FixedChoicesRole:
{
//qDebug() << " ---call type set Data: " << role << ": " << XQItem::fetchItemDataRoleName(role) << ":" << value.toString(); //qDebug() << " ---call type set Data: " << role << ": " << XQItem::fetchItemDataRoleName(role) << ":" << value.toString();
itemType().replaceAttribute( this, value, role ); itemType().replaceAttribute( this, value, role );
break; emitDataChanged();
// no break, return!
return;
}
// DAS PASSIERT NIE, AUSSER
// set the raw, unformatted data
case ContentRole:
{
// what will happen? value is a string ptr ?!
qDebug() << " --- setting content: " << value.toString();
// string ptr setzen kann die basis.
break;
return;
}
case Qt::EditRole :
{
// what will happen? value is a string ptr ?!
qDebug() << " --- setting editrole: " << value.toString();
return;
}
case Qt::DisplayRole :
{
// what will happen? value is a string ptr ?!
qDebug() << " --- setting DISPLAYrole: " << value.toString();
// ignore this
return;
}
// alles andere wie gehabt
case ContentNodeRole: case ContentNodeRole:
case SheetNodeRole: case SheetNodeRole:
case TypeKeyRole: //case TypeKeyRole: not used
case Qt::DisplayRole :
case Qt::EditRole :
// return the raw, unformatted data
case ContentRole:
default: default:
break;
}
// hier: behandlung wie gehabt
QStandardItem::setData( value,role); QStandardItem::setData( value,role);
}
} }

View File

@@ -131,7 +131,7 @@ public:
XQItem( XQItemType* itemType, const QString* content ); XQItem( XQItemType* itemType, const QString* content );
XQItem( XQItemType* itemType, const QString* content, const XQNodePtr& contentNode ); XQItem( XQItemType* itemType, const QString* content, const XQNodePtr& contentNode );
virtual ~XQItem(); virtual ~XQItem() = default;
//! creates not a clone but a new default item, \see QStandardItemModel::setItemPrototype() //! creates not a clone but a new default item, \see QStandardItemModel::setItemPrototype()
//! -- not used at the moment -- //! -- not used at the moment --
@@ -202,7 +202,7 @@ public:
// //
bool isHeaderStyle(); bool isHeaderStyle();
QString dataRoleName(int role); QString dataRoleName(int role) const;
QVariant data(int role = Qt::DisplayRole ) const override; QVariant data(int role = Qt::DisplayRole ) const override;
void setData(const QVariant &value, int role ) override; void setData(const QVariant &value, int role ) override;

View File

@@ -242,7 +242,6 @@ void XQItemDelegate::setEditorData(QWidget* editor, const QModelIndex& index) co
{ {
XQItem& item = xqItemFromIndex( index ); XQItem& item = xqItemFromIndex( index );
qDebug() << " --- ZZZ: setEditorData: " << item.text();
switch( item.editorType() ) switch( item.editorType() )
{ {
case XQItemType::ComboBoxType : case XQItemType::ComboBoxType :

View File

@@ -30,33 +30,47 @@ size_t XQItemType::s_ItemTypeCount = 0;
XQItemType::XQItemType() XQItemType::XQItemType()
: XQItem(nullptr) // vermeide rekursion : XQItem(nullptr) // vermeide rekursion
{ {
} }
XQItemType::XQItemType( const XQItemType& other) XQItemType::XQItemType( const XQItemType& other)
: XQItem( other ) : XQItem( other )
{ {
} }
//! destruktor, räumt das fixedChoices auf, so vorhanden.
XQItemType::~XQItemType() XQItemType::~XQItemType()
{ {
// das einzige property, was auch auf dem heap liegt.
QStandardItemModel* choices = fixedChoices();
if( choices )
{
setfixedChoices( nullptr );
delete choices;
}
} }
//! ruft QStandardItem::data auf
QVariant XQItemType::data( int role ) const QVariant XQItemType::data( int role ) const
{ {
return QStandardItem::data(role); return QStandardItem::data(role);
} }
//! ruft QStandardItem::setData auf
void XQItemType::setData(const QVariant &value, int role ) void XQItemType::setData(const QVariant &value, int role )
{ {
return QStandardItem::setData(value,role); return QStandardItem::setData(value,role);
} }
//! setzt einen attributwert neu. Ggf. wird ein neuer ItemType erzeugt.
void XQItemType::replaceAttribute( XQItem* item, const QVariant& newValue, int role ) void XQItemType::replaceAttribute( XQItem* item, const QVariant& newValue, int role )
{ {
// hat sich überhaupt was geändert? // hat sich überhaupt was geändert?
@@ -82,20 +96,26 @@ void XQItemType::replaceAttribute( XQItem* item, const QVariant& newValue, int r
// und ins item übernehmen // und ins item übernehmen
item->setItemType( myClone ); item->setItemType( myClone );
/// Obacht! Der alte, geänderte itemType bleibt erhaltent /// Obacht! Der alte, geänderte itemType bleibt erhalten
/// und verrottet ggf. ohne Daseinszweck /// und verrottet ggf. ohne Daseinszweck
} }
} }
} }
QVariant XQItemType::formatText( const XQItem& item ) const
QString XQItemType::formatToSI( const QString& valueTxt ) const
{ {
/* return "type says:"+ item.content();
}
//! firz
QString XQItemType::formatToSI( const QString& valueTxt, XQItem::UnitType unitType ) const
{
if( valueTxt.isEmpty() ) if( valueTxt.isEmpty() )
return valueTxt; return valueTxt;
if( XQItem::ISODate == _unitType ) if( XQItem::ISODate == unitType )
{ {
// format iso date // format iso date
QDateTime dateTime = QDateTime::fromString(valueTxt, Qt::ISODate); QDateTime dateTime = QDateTime::fromString(valueTxt, Qt::ISODate);
@@ -122,14 +142,14 @@ QString XQItemType::formatToSI( const QString& valueTxt ) const
//qDebug() << " convert: " << dVal << " : " << valueTxt << ": " << strVal << ":" << exp << " : " << strPrefix << ": " << nVal; //qDebug() << " convert: " << dVal << " : " << valueTxt << ": " << strVal << ":" << exp << " : " << strPrefix << ": " << nVal;
return QString("%1 %2%3").arg( strVal, strPrefix, unitTypeToString() ); return QString("%1 %2%3").arg( strVal, strPrefix, unitTypeToString() );
*/
return "fitze!";
} }
//! firz
QString XQItemType::unFormatFromSI(const QString& formText ) const QString XQItemType::unFormatFromSI(const QString& formText ) const
{ {
/*
QString input = formText.simplified(); QString input = formText.simplified();
// #1: strip numeric part // #1: strip numeric part
if( input.isEmpty() ) if( input.isEmpty() )
@@ -167,14 +187,15 @@ QString XQItemType::unFormatFromSI(const QString& formText ) const
//qDebug() << " convert: " << numPart << " : " << unitPart << " : " << dVal << " : " << result; //qDebug() << " convert: " << numPart << " : " << unitPart << " : " << dVal << " : " << result;
return result; return result;
*/
return "fitze!";
} }
/// ///
/// --- statics -------------------------------------------------------------------------- /// --- statics --------------------------------------------------------------------------
/// ///
//! gibt den dummy item type zurück (benutzt für null-items).
XQItemType* XQItemType::staticItemType() XQItemType* XQItemType::staticItemType()
{ {
static XQItemType s_DummyItemType; static XQItemType s_DummyItemType;
@@ -182,6 +203,8 @@ XQItemType* XQItemType::staticItemType()
} }
//! erzeugt aus den eingenschaften des itemTypes einen eindeutigen schlüssel.
QString XQItemType::makeItemTypeKey() QString XQItemType::makeItemTypeKey()
{ {
QString key("%1:%2:%3:%4:%5:%6:%7"); QString key("%1:%2:%3:%4:%5:%6:%7");

View File

@@ -40,8 +40,10 @@ 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;
virtual QVariant formatText( const XQItem& item ) const;
// FIX! Das gehört hier nicht her! // FIX! Das gehört hier nicht her!
QString formatToSI(const QString& rawText ) const; QString formatToSI(const QString& rawText, XQItem::UnitType unitType ) const;
QString unFormatFromSI(const QString& valueText ) const; QString unFormatFromSI(const QString& valueText ) const;
void replaceAttribute( XQItem* item, const QVariant& newValue, int role ); void replaceAttribute( XQItem* item, const QVariant& newValue, int role );

View File

@@ -12,7 +12,7 @@
***************************************************************************/ ***************************************************************************/
#include <xqmodelsections.h> #include <xqmodelsectionlist.h>
#include <xqitem.h> #include <xqitem.h>

View File

@@ -12,8 +12,8 @@
***************************************************************************/ ***************************************************************************/
#ifndef XQMODELSECTIONS_H #ifndef XQMODELSECTIONLIST_H
#define XQMODELSECTIONS_H #define XQMODELSECTIONLIST_H
#include <QPersistentModelIndex> #include <QPersistentModelIndex>
#include <xqnode.h> #include <xqnode.h>
@@ -68,4 +68,4 @@ public:
}; };
#endif // XQMODELSECTIONS_H #endif // XQMODELSECTIONLIST_H

View File

@@ -18,120 +18,25 @@
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <stack>
#include <iterator>
#include <QDebug> #include <QDebug>
#include <QModelIndex> #include <QModelIndex>
#include <znode.h> #include <znode.h>
#include <xqappdata.h> #include <xqappdata.h>
#include <znode_factory.h> #include <znode_factory.h>
// Overload the operator<< for QString and std::ostream //! überlädt den operator<< für QString und std::ostream
std::ostream& operator<<(std::ostream& os, const QString& obj); std::ostream& operator<<(std::ostream& os, const QString& obj);
// raw node //! raw node
using XQNode = znode::zbasic_node<QString>; using XQNode = znode::zbasic_node<QString>;
// default shared node //! default shared node
using XQNodePtr = std::shared_ptr<znode::zbasic_node<QString>>; using XQNodePtr = std::shared_ptr<znode::zbasic_node<QString>>;
// the node factory //! die node factory
using XQNodeFactory = znode::znode_factory<QString>; using XQNodeFactory = znode::znode_factory<QString>;
class XQNodeList : public znode::zbasic_node<QString>::znode_list
{
public:
XQNodeList() = default;
virtual ~XQNodeList() = default;
};
class XNodeIterator
{
public:
using iterator_category = std::forward_iterator_tag;
using value_type = XQNode;
using difference_type = std::ptrdiff_t;
using pointer = XQNode*;
using reference = XQNode&;
XNodeIterator() = default;
XNodeIterator(XQNodePtr root)
{
if (root) {
_stack.push(root);
}
}
reference operator*() const {
return *_stack.top();
}
pointer operator->() const {
return _stack.top().get();
}
XNodeIterator& operator++() {
auto node = _stack.top();
_stack.pop();
for (auto it = node->children().rbegin(); it != node->children().rend(); ++it)
{
_stack.push(*it);
}
return *this;
}
XNodeIterator operator++(int) {
XNodeIterator tmp = *this;
++(*this);
return tmp;
}
bool operator==(const XNodeIterator& other) const {
return _stack == other._stack;
}
bool operator!=(const XNodeIterator& other) const {
return !(*this == other);
}
private:
std::stack<XQNodePtr> _stack;
};
// Define the tree class with begin and end methods
class XTree
{
public:
XTree(XQNodePtr root)
: _root(root)
{}
XNodeIterator begin()
{
return XNodeIterator(_root);
}
XNodeIterator end()
{
return XNodeIterator();
}
private:
XQNodePtr _root;
};
//void inspect( XQNodePtr node, int offSet=0 ); //void inspect( XQNodePtr node, int offSet=0 );
void inspect( const XQNodePtr& node, int indent=0 ); void inspect( const XQNodePtr& node, int indent=0 );

View File

@@ -20,7 +20,7 @@
#include <QStandardItemModel> #include <QStandardItemModel>
#include <xqsimpleclipboard.h> #include <xqsimpleclipboard.h>
#include <xqmodelsections.h> #include <xqmodelsectionlist.h>
#include <xqitemfactory.h> #include <xqitemfactory.h>
#include <xqcontextmenu.h> #include <xqcontextmenu.h>
@@ -81,17 +81,22 @@ public:
virtual void cmdNew( XQCommand& command ); virtual void cmdNew( XQCommand& command );
virtual void cmdNewUndo( XQCommand& command ); virtual void cmdNewUndo( XQCommand& command );
/* /*!
Derzeit wir die default-implementierung von data/setData genutzt. hier wäre dann die
Stelle um setData & data an externe 'handler' umzubiegen, siehe giovannies 'model-injection'
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override
{
return QStandardItemModel::data( index, role );
}
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override
{ {
qDebug() << " --- setData: " << value.toString(); qDebug() << " --- setData: " << value.toString();
return QStandardItemModel::setData( index, value, role ); return QStandardItemModel::setData( index, value, role );
} }
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override
{
return QStandardItemModel::data( index, role );
}
*/ */
public slots: public slots:

View File

@@ -21,7 +21,7 @@ HEADERS += \
items/xqitemtype.h \ items/xqitemtype.h \
items/xqitemdelegate.h \ items/xqitemdelegate.h \
model/xqcommand.h \ model/xqcommand.h \
model/xqmodelsections.h \ model/xqmodelsectionlist.h \
model/xqnode.h \ model/xqnode.h \
model/xqnodewriter.h \ model/xqnodewriter.h \
model/xqselectionmodel.h \ model/xqselectionmodel.h \
@@ -59,7 +59,7 @@ SOURCES += \
items/xqitemdelegate.cpp \ items/xqitemdelegate.cpp \
main.cpp \ main.cpp \
model/xqcommand.cpp \ model/xqcommand.cpp \
model/xqmodelsections.cpp \ model/xqmodelsectionlist.cpp \
model/xqnode.cpp \ model/xqnode.cpp \
model/xqnodewriter.cpp \ model/xqnodewriter.cpp \
model/xqselectionmodel.cpp \ model/xqselectionmodel.cpp \

View File

@@ -6,43 +6,11 @@
--> -->
<ItemTypesX>
<HiddenType RenderStyle="HiddenStyle"/>
<StaticType RenderStyle="StaticStyle"/>
<HeaderType RenderStyle="HeaderStyle"/>
<TreeParentType RenderStyle="StaticStyle" ItemFlags="IsEnabled|IsDropEnabled"/>
<TreeChildType RenderStyle="StaticStyle" ItemFlags="IsEnabled|IsDragEnabled|IsSelectable|IsDropEnabled"/>
<ValueType RenderStyle="LineEditStyle" ItemFlags="IsEnabled|IsEditable|IsSelectable"/>
<PercentageType RenderStyle="ProgressBarStyle" ItemFlags="IsEnabled|IsSelectable"/>
<ChoiceType RenderStyle="ComboBoxStyle" ItemFlags="IsEnabled|IsSelectable|IsEditable" FixedChoices="la|le|lo|lu"/>
<IntValueType RenderStyle="SpinBoxStyle" ItemFlags="IsEnabled|IsSelectable"/>
</ItemTypesX>
<!--
MainModel
-->
<MainModelX>
<ActiveProjects HeaderCaption="Active Projects" HeaderItemType="TreeParentType" Icon="icn08Dummy" State="runnning">
<Project HeaderCaption="#-Project" HeaderItemType="TreeChildType" Icon="icn74Dummy"/>
</ActiveProjects>
<PlannedProjects HeaderCaption="Planned Projects" HeaderItemType="TreeParentType" Icon="icn08Dummy" State="planned">
<Project HeaderCaption="#Project" HeaderItemType="TreeChildType" Icon="icn74Dummy"/>
</PlannedProjects>
</MainModelX>
<!--
Der ItemType beschreibt die Eigenschaften eines Items.
-->
<ItemTypes> <ItemTypes>
<HiddenType RenderStyle="HiddenStyle"/> <HiddenType RenderStyle="HiddenStyle"/>
<StaticType RenderStyle="PlainStyle"/> <StaticType RenderStyle="PlainStyle"/>
<TreeChildType RenderStyle="PlainStyle" ItemFlags="IsEnabled|IsDragEnabled|IsSelectable|IsDropEnabled"/> <TreeChildType RenderStyle="PlainStyle" ItemFlags="IsEnabled|IsDragEnabled|IsSelectable|IsDropEnabled"/>
<PlainType RenderStyle="PlainStyle" ItemFlags="IsEnabled|IsEditable|IsSelectable"/>
<ValueType RenderStyle="FormattedStyle" ItemFlags="IsEnabled|IsEditable|IsSelectable"/> <ValueType RenderStyle="FormattedStyle" ItemFlags="IsEnabled|IsEditable|IsSelectable"/>
<PercentageType RenderStyle="ProgressBarStyle" ItemFlags="IsEnabled|IsSelectable"/> <PercentageType RenderStyle="ProgressBarStyle" ItemFlags="IsEnabled|IsSelectable"/>
<ChoiceType RenderStyle="ComboBoxStyle" ItemFlags="IsEnabled|IsSelectable|IsEditable" FixedChoices="la|le|lo|lu"/> <ChoiceType RenderStyle="ComboBoxStyle" ItemFlags="IsEnabled|IsSelectable|IsEditable" FixedChoices="la|le|lo|lu"/>
@@ -69,8 +37,8 @@
<DocumentDetailsModel> <DocumentDetailsModel>
<Panel FriendlyName="@PanelName"> <Panel FriendlyName="@PanelName">
<PanelID HeaderCaption="Panel" HeaderItemType="HeaderType" ItemType="ValueType" Icon="icn74Dummy"/> <PanelID HeaderCaption="Panel" HeaderItemType="HeaderType" ItemType="PlainType" Icon="icn74Dummy"/>
<PanelName HeaderCaption="Name" HeaderItemType="HeaderType" ItemType="ValueType"/> <PanelName HeaderCaption="Name" HeaderItemType="HeaderType" ItemType="PlainType"/>
<Manufacturer HeaderCaption="Manufacturer" HeaderItemType="HeaderType" ItemType="ValueType"/> <Manufacturer HeaderCaption="Manufacturer" HeaderItemType="HeaderType" ItemType="ValueType"/>
<WattPeak HeaderCaption="Watt Peak" HeaderItemType="HeaderType" ItemType="ValueType" Unit="Wp"/> <WattPeak HeaderCaption="Watt Peak" HeaderItemType="HeaderType" ItemType="ValueType" Unit="Wp"/>
<Width HeaderCaption="Width" HeaderItemType="HeaderType" ItemType="ValueType" Unit="m"/> <Width HeaderCaption="Width" HeaderItemType="HeaderType" ItemType="ValueType" Unit="m"/>