cleanups, added const iterators to xqmaptor

This commit is contained in:
2025-09-05 09:57:43 +02:00
parent c9b61c1c2b
commit 8d26c32e51
7 changed files with 78 additions and 77 deletions

View File

@@ -38,6 +38,7 @@ const QString c_ProjectID = "ProjectID";
const QString c_ModelSheetFileName = "xml/modelsheets.xml"; const QString c_ModelSheetFileName = "xml/modelsheets.xml";
const QString c_ModelDummyFileName = "xml/saved_testfile.xtr"; const QString c_ModelDummyFileName = "xml/saved_testfile.xtr";
const QString c_DocumentDirectory = "xml/"; const QString c_DocumentDirectory = "xml/";
const QString c_DocumentFileName1 = "xml/modeldata1.xtr"; const QString c_DocumentFileName1 = "xml/modeldata1.xtr";
const QString c_DocumentFileName2 = "xml/modeldata2.xtr"; const QString c_DocumentFileName2 = "xml/modeldata2.xtr";
const QString c_DocumentFileName3 = "xml/modeldata3.xtr"; const QString c_DocumentFileName3 = "xml/modeldata3.xtr";

View File

@@ -18,8 +18,8 @@
//! erzeugt ein docukument //! erzeugt ein docukument
XQDocument::XQDocument(const QString& aFileName, const QString& aFriendlyName, XQItem* aTreeItem, XQViewModel* aModelView ) XQDocument::XQDocument(const QString& aFileName, const QString& aFriendlyName, XQItem* aTreeItem, XQViewModel* aViewModel )
: fileName{ aFileName }, friendlyName{ aFriendlyName }, treeItem{ aTreeItem }, modelView{ aModelView } : fileName{ aFileName }, friendlyName{ aFriendlyName }, treeItem{ aTreeItem }, viewModel{ aViewModel }
{ {
} }
@@ -44,9 +44,9 @@ XQDocumentStore::~XQDocumentStore()
//! erzeugt ein document eintrag //! erzeugt ein document eintrag
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* aViewModel )
{ {
XQDocument newDocument( aFileName, aFriendlyName, aTreeItem, aModelView ); XQDocument newDocument( aFileName, aFriendlyName, aTreeItem, aViewModel );
addAtKey( aFileName, newDocument ); addAtKey( aFileName, newDocument );
// attention: this assumes the presence of the 'ProjectID' value // attention: this assumes the presence of the 'ProjectID' value
//addAlias( aFileName, aTreeItem->attribute(c_ProjectID) ); //addAlias( aFileName, aTreeItem->attribute(c_ProjectID) );

View File

@@ -28,12 +28,10 @@ struct XQDocument
XQDocument() = default; XQDocument() = default;
XQDocument( const QString& aFileName, const QString& aFriendlyName, XQItem* aTreeItem, XQViewModel* aModelView ); XQDocument( const QString& aFileName, const QString& aFriendlyName, XQItem* aTreeItem, XQViewModel* aModelView );
virtual ~XQDocument() = default;
QString fileName; // also used as key QString fileName; // also used as key
QString friendlyName; QString friendlyName;
XQItem* treeItem{}; XQItem* treeItem{};
XQViewModel* modelView{}; XQViewModel* viewModel{};
}; };
@@ -46,11 +44,7 @@ public:
XQDocumentStore() = default; XQDocumentStore() = default;
virtual ~ XQDocumentStore(); virtual ~ XQDocumentStore();
void addDocument( const QString& aFileName, const QString& aFriendlyName, XQItem* aTreeItem, XQViewModel* aModelView ); void addDocument( const QString& aFileName, const QString& aFriendlyName, XQItem* aTreeItem, XQViewModel* aViewModel );
protected:
XQNode _treeRootNode{ "treeRootNode" };
}; };

View File

@@ -98,7 +98,7 @@ void XQMainWindow::initMainWindow()
connect( _mainTreeView, &QTreeView::clicked, this, [&,this](const QModelIndex& index) connect( _mainTreeView, &QTreeView::clicked, this, [&,this](const QModelIndex& index)
{ {
onChildViewItemClicked( XQItem::xqItemFromIndex(index) ); onTreeViewItemClicked( XQItem::xqItemFromIndex(index) );
}); });
@@ -125,7 +125,8 @@ void XQMainWindow::initMainWindow()
// #2. load demo data // #2. load demo data
loadDocument( c_DocumentFileName1 ); loadDocument( c_DocumentFileName1 );
loadDocumentQML( c_DocumentFileName2 ); //loadDocumentQML( c_DocumentFileName2 );
loadDocument( c_DocumentFileName2 );
qDebug() << " --- all here: " << XQNode::s_Count; qDebug() << " --- all here: " << XQNode::s_Count;
@@ -259,48 +260,58 @@ void XQMainWindow::onAbout()
void XQMainWindow::onTreeViewItemClicked( const XQItem& item ) void XQMainWindow::onTreeViewItemClicked( const XQItem& item )
{ {
/*
qDebug() << " --- XXX mainWindow onTreeItemClicked:" << item.text();
_mainTreeView->selectionModel()->select(item.index(), QItemSelectionModel::Select); _mainTreeView->selectionModel()->select(item.index(), QItemSelectionModel::Select);
if( XQNodePtr contentNode = item.contentNode() ) if( XQNodePtr contentNode = item.contentNode() )
{ {
//XQNodePtr contentNode = item.contentNode()
QString key = contentNode->attribute(c_ProjectID); QString key = contentNode->attribute(c_ProjectID);
qDebug() << " --- FIRZ: key: " << key;
bool isThere = _documentStore.contains(key); bool isThere = _documentStore.contains(key);
if( isThere) if( isThere)
_tabWidget->setCurrentWidget( _documentStore[key].modelView->treeTable() ); _tabWidget->setCurrentWidget( _documentStore[key].viewModel->treeTable() );
}
*/
qDebug() << " --- Tree item CLICK:" << item.text() << " : " << item.itemType().text();
if( item.itemType().text() == "TreeChildType" )
{
setChildTabByName( item.text() );
} }
} }
void XQMainWindow::onTreeViewItemChanged(const XQItem &item ) void XQMainWindow::onTreeViewItemChanged(const XQItem& item )
{ {
qDebug() << " --- MAIN WINDOW on itemChanged:" << item.text(); qDebug() << " --- TREE VIEW itemChanged:" << item.text() << " : " << item.parent()->text();
} // hier müssen wir erst das projekt aktivieren
XQItem* xqItem = static_cast<XQItem*>(item.parent());
void XQMainWindow::onChildViewItemClicked( const XQItem& item ) onTreeViewItemClicked( *xqItem );
{ //if( item.itemType().text() == "TreeSectionType" )
qDebug() << " --- MAIN WINDOW on CHILD item CLICK:" << item.text(); {
} int idx = _tabWidget->currentIndex();
if(_documentStore.contains(idx) )
void XQMainWindow::onChildViewItemChanged(const XQItem &item ) {
{ qDebug() << " --- should toggle: " << item.text();
qDebug() << " --- MAIN WINDOW on CHILD itemChanged:" << item.text(); XQViewModel& childModel = *_documentStore[idx].viewModel;
childModel.toggleSection(item.text());
}
}
} }
//! beim click auf ein tab im linken fenster wird der navigationsbaum angepasst. //! beim click auf ein tab im linken fenster wird der navigationsbaum angepasst.
void XQMainWindow::onChildViewTabClicked( int index ) void XQMainWindow::onChildViewTabClicked( int idx )
{ {
qDebug() << " --- onChildTabClicked: " << index; if(_documentStore.contains(idx) )
//const QString& key = _documentStore[index].treeItem->attribute( c_ProjectID ); {
//qDebug() << " ---- tab clicked: " << index << " : " << _documentStore[index].friendlyName;// << ": " << key; QModelIndex treeIndex =_documentStore[idx].treeItem->index();
//_mainTreeView->setCurrentIndex( _documentStore[index]->treeTtem.index() ); _mainModel.expandNewItem( treeIndex );
}
} }
//! firz
void XQMainWindow::onSectionCreated( const XQModelSection& section ) void XQMainWindow::onSectionCreated( const XQModelSection& section )
{ {
qDebug() << " --- XXX section created: " << section.contentType() << ":" << section.sheetRootNode()->to_string(); qDebug() << " --- XXX section created: " << section.contentType() << ":" << section.sheetRootNode()->to_string();
@@ -315,16 +326,16 @@ void XQMainWindow::onSectionToggled( const XQModelSection& section )
//qDebug() << " --- XXX section toggled: " << section.contentType() << ":" << section.sheetRootNode()->to_string(); //qDebug() << " --- XXX section toggled: " << section.contentType() << ":" << section.sheetRootNode()->to_string();
} }
QStandardItemModel* createModel() { void XQMainWindow::setChildTabByName( const QString& key )
auto* model = new QStandardItemModel; {
model->setHorizontalHeaderLabels({ "Name" }); for( int i=0; i<_documentStore.size(); ++i )
{
QStandardItem* parent = new QStandardItem("Tiere"); if( key == _documentStore[i].friendlyName)
parent->appendRow(new QStandardItem("Hund")); {
parent->appendRow(new QStandardItem("Katze")); _tabWidget->setCurrentIndex(i);
model->appendRow(parent); return;
}
return model; }
} }
void XQMainWindow::loadDocumentQML( const QString& fileName ) void XQMainWindow::loadDocumentQML( const QString& fileName )
@@ -391,13 +402,13 @@ void XQMainWindow::loadDocument( const QString& fileName )
// 'friendly Name' ist ein Link auf ein anderes Attribute // 'friendly Name' ist ein Link auf ein anderes Attribute
// das als Namen verwendet wird. // das als Namen verwendet wird.
const QString& fName = contentRoot->friendly_name(); const QString& fName = contentRoot->friendly_name();
QString pTitle = QString("Project %1: %2").arg( pID, fName ); QString pTabTitle = QString("Project %1: %2").arg( pID, fName );
// Eine neue TreeView erzeugn und im TabWidget parken. // Eine neue TreeView erzeugn und im TabWidget parken.
XQTreeTable* childTreeView = new XQTreeTable(_tabWidget); XQTreeTable* childTreeView = new XQTreeTable(_tabWidget);
_tabWidget->addTab( childTreeView, pTitle ); _tabWidget->addTab( childTreeView, pTabTitle );
_tabWidget->setCurrentWidget( childTreeView ); _tabWidget->setCurrentWidget( childTreeView );
setWindowTitle( pTitle ); setWindowTitle( pTabTitle );
// Ein neues Child-Model erzeugen // Ein neues Child-Model erzeugen
XQChildModel* childModel = new XQChildModel(this); XQChildModel* childModel = new XQChildModel(this);
@@ -413,7 +424,7 @@ void XQMainWindow::loadDocument( const QString& fileName )
// neuen eintrag im übsichts-baum erzeugen // neuen eintrag im übsichts-baum erzeugen
_currentProjectItem = _mainModel.addProjectItem( contentRoot ); _currentProjectItem = _mainModel.addProjectItem( contentRoot );
_documentStore.addDocument( fileName, pTitle, _currentProjectItem, childModel ); _documentStore.addDocument( fileName, fName, _currentProjectItem, childModel );
// die Modelstruktur anlegen // die Modelstruktur anlegen
childModel->initModel( c_ChildModelName ); childModel->initModel( c_ChildModelName );
@@ -432,7 +443,7 @@ void XQMainWindow::saveDocument( const QString& fileName )
XQNodeWriter nodeWriter; XQNodeWriter nodeWriter;
int curIdx = _tabWidget->currentIndex(); int curIdx = _tabWidget->currentIndex();
//XQNodePtr rootNode = _documentStore[curIdx].treeItem->contentNode(); //XQNodePtr rootNode = _documentStore[curIdx].treeItem->contentNode();
XQNodePtr rootNode = _documentStore[curIdx].modelView->contentRootNode(); XQNodePtr rootNode = _documentStore[curIdx].viewModel->contentRootNode();
Q_ASSERT(rootNode); Q_ASSERT(rootNode);
nodeWriter.dumpTree( rootNode, fileName ); nodeWriter.dumpTree( rootNode, fileName );
} }

View File

@@ -51,33 +51,32 @@ public slots:
void onAbout(); void onAbout();
void onExit(); void onExit();
void onTreeViewItemClicked(const XQItem& item ); void onTreeViewItemClicked( const XQItem& item );
void onTreeViewItemChanged( const XQItem& item ); void onTreeViewItemChanged( const XQItem& item );
void onChildViewItemClicked( const XQItem& item );
void onChildViewItemChanged( const XQItem& item );
void onChildViewTabClicked( int index ); void onChildViewTabClicked( int index );
//void onItemCreated( XQItem* item ); //void onItemCreated( XQItem* item );
void onSectionCreated( const XQModelSection& section); void onSectionCreated( const XQModelSection& section);
void onSectionToggled( const XQModelSection& section ); void onSectionToggled( const XQModelSection& section );
void setChildTabByName( const QString& key );
static void setupWorkingDir(); static void setupWorkingDir();
protected: protected:
// fixme implement // fixme implement
void showDocumnet( const QString& key ){} void showDocument( const QString& key ){}
void loadDocument( const QString& fileName ); void loadDocument( const QString& fileName );
void loadDocumentQML( const QString& fileName ); void loadDocumentQML( const QString& fileName );
void saveDocument( const QString& fileName ); void saveDocument( const QString& fileName );
QUndoStack _undoStack; QUndoStack _undoStack;
XQDocumentStore _documentStore; XQDocumentStore _documentStore;
XQMainModel _mainModel; XQMainModel _mainModel;
XQItem* _currentProjectItem{}; XQItem* _currentProjectItem{};
//XQChildModel* _currentChildModel{};
}; };

View File

@@ -199,7 +199,11 @@ void XQViewModel::toggleSection( const XQModelSection& section )
void XQViewModel::toggleSection( const QString& sectionKey ) void XQViewModel::toggleSection( const QString& sectionKey )
{ {
if( _sections.hasValidSection( sectionKey ) )
{
XQModelSection& section = _sections.at( sectionKey);
//section.
}
} }
/* /*

View File

@@ -73,6 +73,16 @@ public:
return _data.end(); return _data.end();
} }
auto begin() const
{
return _data.begin();
}
auto end() const
{
return _data.end();
}
inline int size() const inline int size() const
{ {
return (int) _data.size(); return (int) _data.size();
@@ -94,13 +104,11 @@ public:
return mapIndex().contains(key); return mapIndex().contains(key);
} }
inline const XQMapIndex& mapIndex() const inline const XQMapIndex& mapIndex() const
{ {
return _index; return _index;
} }
int indexOf( const QString& key ) const int indexOf( const QString& key ) const
{ {
return mapIndex().indexOf(key); return mapIndex().indexOf(key);
@@ -121,7 +129,6 @@ public:
return mapIndex().key( index ); return mapIndex().key( index );
} }
T& operator[]( int index ) T& operator[]( int index )
{ {
if( contains(index) ) if( contains(index) )
@@ -129,7 +136,6 @@ public:
throw XQException("XQMaptor operator[ int index ]: out of range"); throw XQException("XQMaptor operator[ int index ]: out of range");
} }
const T& operator[]( int index ) const const T& operator[]( int index ) const
{ {
if ( contains(index) ) if ( contains(index) )
@@ -154,7 +160,6 @@ public:
return _data[ _index[key] ]; return _data[ _index[key] ];
} }
const T& operator[]( const QString& key ) const const T& operator[]( const QString& key ) const
{ {
if (key.isEmpty() || !contains(key)) if (key.isEmpty() || !contains(key))
@@ -162,7 +167,6 @@ public:
return _data[_index[key]]; return _data[_index[key]];
} }
T& at( const QString& key ) T& at( const QString& key )
{ {
return (*this)[key]; return (*this)[key];
@@ -179,7 +183,6 @@ public:
return _data.size()-1; return _data.size()-1;
} }
virtual void addAtIndex( int index, const T& item ) virtual void addAtIndex( int index, const T& item )
{ {
if(contains(index)) if(contains(index))
@@ -187,14 +190,12 @@ public:
_data[index] = item; _data[index] = item;
} }
// convenience method to mimic QMap<T,QString> // convenience method to mimic QMap<T,QString>
virtual void insert( const T& item, const QString& key ) virtual void insert( const T& item, const QString& key )
{ {
addAtKey(key, item ); addAtKey(key, item );
} }
virtual void addAtKey( const QString& key, const T& item ) virtual void addAtKey( const QString& key, const T& item )
{ {
XQMapIndex::iterator pos = _index.find( key ); XQMapIndex::iterator pos = _index.find( key );
@@ -209,7 +210,6 @@ public:
} }
} }
bool addAlias( const QString& key, const QString& alias ) bool addAlias( const QString& key, const QString& alias )
{ {
// look for 'original' key // look for 'original' key
@@ -227,20 +227,17 @@ public:
return true; return true;
} }
void addKey( const QString& key, int index ) void addKey( const QString& key, int index )
{ {
_index.addKey( key, index ); _index.addKey( key, index );
} }
virtual void clear() virtual void clear()
{ {
_data.clear(); _data.clear();
_index.clear(); _index.clear();
} }
virtual bool killEntry( const QString& key ) virtual bool killEntry( const QString& key )
{ {
int idx = indexOf( key ); int idx = indexOf( key );
@@ -249,7 +246,6 @@ public:
return killEntry( (int) idx ); return killEntry( (int) idx );
} }
virtual bool killEntry( int index ) virtual bool killEntry( int index )
{ {
if( index >= this->_data.size() ) if( index >= this->_data.size() )
@@ -261,19 +257,16 @@ public:
return true; return true;
} }
virtual QString toString() const virtual QString toString() const
{ {
return join( ";" ); return join( ";" );
} }
virtual void dump() const virtual void dump() const
{ {
throw XQException("XQMaptor: dump not implemented!" ); throw XQException("XQMaptor: dump not implemented!" );
} }
virtual QString join( const QString& sep, int from=0, int to=-1) const virtual QString join( const QString& sep, int from=0, int to=-1) const
{ {
Q_UNUSED(sep) Q_UNUSED(sep)
@@ -283,7 +276,6 @@ public:
return "--"; return "--";
} }
int replaceKey( const QString& oldkey, const QString& newkey ) int replaceKey( const QString& oldkey, const QString& newkey )
{ {
int idx = indexOf( oldkey ); int idx = indexOf( oldkey );