cleanups, added const iterators to xqmaptor
This commit is contained in:
@@ -38,6 +38,7 @@ const QString c_ProjectID = "ProjectID";
|
||||
const QString c_ModelSheetFileName = "xml/modelsheets.xml";
|
||||
const QString c_ModelDummyFileName = "xml/saved_testfile.xtr";
|
||||
const QString c_DocumentDirectory = "xml/";
|
||||
|
||||
const QString c_DocumentFileName1 = "xml/modeldata1.xtr";
|
||||
const QString c_DocumentFileName2 = "xml/modeldata2.xtr";
|
||||
const QString c_DocumentFileName3 = "xml/modeldata3.xtr";
|
||||
|
@@ -18,8 +18,8 @@
|
||||
|
||||
//! erzeugt ein docukument
|
||||
|
||||
XQDocument::XQDocument(const QString& aFileName, const QString& aFriendlyName, XQItem* aTreeItem, XQViewModel* aModelView )
|
||||
: fileName{ aFileName }, friendlyName{ aFriendlyName }, treeItem{ aTreeItem }, modelView{ aModelView }
|
||||
XQDocument::XQDocument(const QString& aFileName, const QString& aFriendlyName, XQItem* aTreeItem, XQViewModel* aViewModel )
|
||||
: fileName{ aFileName }, friendlyName{ aFriendlyName }, treeItem{ aTreeItem }, viewModel{ aViewModel }
|
||||
{
|
||||
|
||||
}
|
||||
@@ -44,9 +44,9 @@ XQDocumentStore::~XQDocumentStore()
|
||||
|
||||
//! 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 );
|
||||
// attention: this assumes the presence of the 'ProjectID' value
|
||||
//addAlias( aFileName, aTreeItem->attribute(c_ProjectID) );
|
||||
|
@@ -28,12 +28,10 @@ struct XQDocument
|
||||
XQDocument() = default;
|
||||
XQDocument( const QString& aFileName, const QString& aFriendlyName, XQItem* aTreeItem, XQViewModel* aModelView );
|
||||
|
||||
virtual ~XQDocument() = default;
|
||||
|
||||
QString fileName; // also used as key
|
||||
QString friendlyName;
|
||||
XQItem* treeItem{};
|
||||
XQViewModel* modelView{};
|
||||
XQViewModel* viewModel{};
|
||||
|
||||
};
|
||||
|
||||
@@ -46,11 +44,7 @@ public:
|
||||
XQDocumentStore() = default;
|
||||
virtual ~ XQDocumentStore();
|
||||
|
||||
void addDocument( const QString& aFileName, const QString& aFriendlyName, XQItem* aTreeItem, XQViewModel* aModelView );
|
||||
|
||||
protected:
|
||||
|
||||
XQNode _treeRootNode{ "treeRootNode" };
|
||||
void addDocument( const QString& aFileName, const QString& aFriendlyName, XQItem* aTreeItem, XQViewModel* aViewModel );
|
||||
|
||||
};
|
||||
|
||||
|
@@ -98,7 +98,7 @@ void XQMainWindow::initMainWindow()
|
||||
|
||||
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
|
||||
loadDocument( c_DocumentFileName1 );
|
||||
loadDocumentQML( c_DocumentFileName2 );
|
||||
//loadDocumentQML( c_DocumentFileName2 );
|
||||
loadDocument( c_DocumentFileName2 );
|
||||
|
||||
qDebug() << " --- all here: " << XQNode::s_Count;
|
||||
|
||||
@@ -259,48 +260,58 @@ void XQMainWindow::onAbout()
|
||||
|
||||
void XQMainWindow::onTreeViewItemClicked( const XQItem& item )
|
||||
{
|
||||
|
||||
qDebug() << " --- XXX mainWindow onTreeItemClicked:" << item.text();
|
||||
/*
|
||||
_mainTreeView->selectionModel()->select(item.index(), QItemSelectionModel::Select);
|
||||
|
||||
if( XQNodePtr contentNode = item.contentNode() )
|
||||
{
|
||||
//XQNodePtr contentNode = item.contentNode()
|
||||
QString key = contentNode->attribute(c_ProjectID);
|
||||
qDebug() << " --- FIRZ: key: " << key;
|
||||
|
||||
bool isThere = _documentStore.contains(key);
|
||||
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();
|
||||
}
|
||||
|
||||
void XQMainWindow::onChildViewItemClicked( const XQItem& item )
|
||||
{
|
||||
qDebug() << " --- MAIN WINDOW on CHILD item CLICK:" << item.text();
|
||||
}
|
||||
|
||||
void XQMainWindow::onChildViewItemChanged(const XQItem &item )
|
||||
{
|
||||
qDebug() << " --- MAIN WINDOW on CHILD 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());
|
||||
onTreeViewItemClicked( *xqItem );
|
||||
//if( item.itemType().text() == "TreeSectionType" )
|
||||
{
|
||||
int idx = _tabWidget->currentIndex();
|
||||
if(_documentStore.contains(idx) )
|
||||
{
|
||||
qDebug() << " --- should toggle: " << item.text();
|
||||
XQViewModel& childModel = *_documentStore[idx].viewModel;
|
||||
childModel.toggleSection(item.text());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//! 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;
|
||||
//const QString& key = _documentStore[index].treeItem->attribute( c_ProjectID );
|
||||
//qDebug() << " ---- tab clicked: " << index << " : " << _documentStore[index].friendlyName;// << ": " << key;
|
||||
//_mainTreeView->setCurrentIndex( _documentStore[index]->treeTtem.index() );
|
||||
if(_documentStore.contains(idx) )
|
||||
{
|
||||
QModelIndex treeIndex =_documentStore[idx].treeItem->index();
|
||||
_mainModel.expandNewItem( treeIndex );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//! firz
|
||||
|
||||
void XQMainWindow::onSectionCreated( const XQModelSection& section )
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
QStandardItemModel* createModel() {
|
||||
auto* model = new QStandardItemModel;
|
||||
model->setHorizontalHeaderLabels({ "Name" });
|
||||
|
||||
QStandardItem* parent = new QStandardItem("Tiere");
|
||||
parent->appendRow(new QStandardItem("Hund"));
|
||||
parent->appendRow(new QStandardItem("Katze"));
|
||||
model->appendRow(parent);
|
||||
|
||||
return model;
|
||||
void XQMainWindow::setChildTabByName( const QString& key )
|
||||
{
|
||||
for( int i=0; i<_documentStore.size(); ++i )
|
||||
{
|
||||
if( key == _documentStore[i].friendlyName)
|
||||
{
|
||||
_tabWidget->setCurrentIndex(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
// das als Namen verwendet wird.
|
||||
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.
|
||||
XQTreeTable* childTreeView = new XQTreeTable(_tabWidget);
|
||||
_tabWidget->addTab( childTreeView, pTitle );
|
||||
_tabWidget->addTab( childTreeView, pTabTitle );
|
||||
_tabWidget->setCurrentWidget( childTreeView );
|
||||
setWindowTitle( pTitle );
|
||||
setWindowTitle( pTabTitle );
|
||||
|
||||
// Ein neues Child-Model erzeugen
|
||||
XQChildModel* childModel = new XQChildModel(this);
|
||||
@@ -413,7 +424,7 @@ void XQMainWindow::loadDocument( const QString& fileName )
|
||||
|
||||
// neuen eintrag im übsichts-baum erzeugen
|
||||
_currentProjectItem = _mainModel.addProjectItem( contentRoot );
|
||||
_documentStore.addDocument( fileName, pTitle, _currentProjectItem, childModel );
|
||||
_documentStore.addDocument( fileName, fName, _currentProjectItem, childModel );
|
||||
|
||||
// die Modelstruktur anlegen
|
||||
childModel->initModel( c_ChildModelName );
|
||||
@@ -432,7 +443,7 @@ void XQMainWindow::saveDocument( const QString& fileName )
|
||||
XQNodeWriter nodeWriter;
|
||||
int curIdx = _tabWidget->currentIndex();
|
||||
//XQNodePtr rootNode = _documentStore[curIdx].treeItem->contentNode();
|
||||
XQNodePtr rootNode = _documentStore[curIdx].modelView->contentRootNode();
|
||||
XQNodePtr rootNode = _documentStore[curIdx].viewModel->contentRootNode();
|
||||
Q_ASSERT(rootNode);
|
||||
nodeWriter.dumpTree( rootNode, fileName );
|
||||
}
|
||||
|
@@ -51,33 +51,32 @@ public slots:
|
||||
void onAbout();
|
||||
void onExit();
|
||||
|
||||
void onTreeViewItemClicked(const XQItem& item );
|
||||
void onTreeViewItemClicked( const XQItem& item );
|
||||
void onTreeViewItemChanged( const XQItem& item );
|
||||
void onChildViewItemClicked( const XQItem& item );
|
||||
void onChildViewItemChanged( const XQItem& item );
|
||||
void onChildViewTabClicked( int index );
|
||||
|
||||
//void onItemCreated( XQItem* item );
|
||||
void onSectionCreated( const XQModelSection& section);
|
||||
void onSectionToggled( const XQModelSection& section );
|
||||
|
||||
void setChildTabByName( const QString& key );
|
||||
|
||||
static void setupWorkingDir();
|
||||
|
||||
protected:
|
||||
|
||||
// fixme implement
|
||||
void showDocumnet( const QString& key ){}
|
||||
void showDocument( const QString& key ){}
|
||||
void loadDocument( const QString& fileName );
|
||||
void loadDocumentQML( const QString& fileName );
|
||||
void saveDocument( const QString& fileName );
|
||||
|
||||
|
||||
QUndoStack _undoStack;
|
||||
XQDocumentStore _documentStore;
|
||||
|
||||
XQMainModel _mainModel;
|
||||
XQItem* _currentProjectItem{};
|
||||
|
||||
//XQChildModel* _currentChildModel{};
|
||||
|
||||
};
|
||||
|
||||
|
@@ -199,7 +199,11 @@ void XQViewModel::toggleSection( const XQModelSection& section )
|
||||
|
||||
void XQViewModel::toggleSection( const QString& sectionKey )
|
||||
{
|
||||
|
||||
if( _sections.hasValidSection( sectionKey ) )
|
||||
{
|
||||
XQModelSection& section = _sections.at( sectionKey);
|
||||
//section.
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -73,6 +73,16 @@ public:
|
||||
return _data.end();
|
||||
}
|
||||
|
||||
auto begin() const
|
||||
{
|
||||
return _data.begin();
|
||||
}
|
||||
|
||||
auto end() const
|
||||
{
|
||||
return _data.end();
|
||||
}
|
||||
|
||||
inline int size() const
|
||||
{
|
||||
return (int) _data.size();
|
||||
@@ -94,13 +104,11 @@ public:
|
||||
return mapIndex().contains(key);
|
||||
}
|
||||
|
||||
|
||||
inline const XQMapIndex& mapIndex() const
|
||||
{
|
||||
return _index;
|
||||
}
|
||||
|
||||
|
||||
int indexOf( const QString& key ) const
|
||||
{
|
||||
return mapIndex().indexOf(key);
|
||||
@@ -121,7 +129,6 @@ public:
|
||||
return mapIndex().key( index );
|
||||
}
|
||||
|
||||
|
||||
T& operator[]( int index )
|
||||
{
|
||||
if( contains(index) )
|
||||
@@ -129,7 +136,6 @@ public:
|
||||
throw XQException("XQMaptor operator[ int index ]: out of range");
|
||||
}
|
||||
|
||||
|
||||
const T& operator[]( int index ) const
|
||||
{
|
||||
if ( contains(index) )
|
||||
@@ -154,7 +160,6 @@ public:
|
||||
return _data[ _index[key] ];
|
||||
}
|
||||
|
||||
|
||||
const T& operator[]( const QString& key ) const
|
||||
{
|
||||
if (key.isEmpty() || !contains(key))
|
||||
@@ -162,7 +167,6 @@ public:
|
||||
return _data[_index[key]];
|
||||
}
|
||||
|
||||
|
||||
T& at( const QString& key )
|
||||
{
|
||||
return (*this)[key];
|
||||
@@ -179,7 +183,6 @@ public:
|
||||
return _data.size()-1;
|
||||
}
|
||||
|
||||
|
||||
virtual void addAtIndex( int index, const T& item )
|
||||
{
|
||||
if(contains(index))
|
||||
@@ -187,14 +190,12 @@ public:
|
||||
_data[index] = item;
|
||||
}
|
||||
|
||||
|
||||
// convenience method to mimic QMap<T,QString>
|
||||
virtual void insert( const T& item, const QString& key )
|
||||
{
|
||||
addAtKey(key, item );
|
||||
}
|
||||
|
||||
|
||||
virtual void addAtKey( const QString& key, const T& item )
|
||||
{
|
||||
XQMapIndex::iterator pos = _index.find( key );
|
||||
@@ -209,7 +210,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool addAlias( const QString& key, const QString& alias )
|
||||
{
|
||||
// look for 'original' key
|
||||
@@ -227,20 +227,17 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void addKey( const QString& key, int index )
|
||||
{
|
||||
_index.addKey( key, index );
|
||||
}
|
||||
|
||||
|
||||
virtual void clear()
|
||||
{
|
||||
_data.clear();
|
||||
_index.clear();
|
||||
}
|
||||
|
||||
|
||||
virtual bool killEntry( const QString& key )
|
||||
{
|
||||
int idx = indexOf( key );
|
||||
@@ -249,7 +246,6 @@ public:
|
||||
return killEntry( (int) idx );
|
||||
}
|
||||
|
||||
|
||||
virtual bool killEntry( int index )
|
||||
{
|
||||
if( index >= this->_data.size() )
|
||||
@@ -261,19 +257,16 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
virtual QString toString() const
|
||||
{
|
||||
return join( ";" );
|
||||
}
|
||||
|
||||
|
||||
virtual void dump() const
|
||||
{
|
||||
throw XQException("XQMaptor: dump not implemented!" );
|
||||
}
|
||||
|
||||
|
||||
virtual QString join( const QString& sep, int from=0, int to=-1) const
|
||||
{
|
||||
Q_UNUSED(sep)
|
||||
@@ -283,7 +276,6 @@ public:
|
||||
return "--";
|
||||
}
|
||||
|
||||
|
||||
int replaceKey( const QString& oldkey, const QString& newkey )
|
||||
{
|
||||
int idx = indexOf( oldkey );
|
||||
|
Reference in New Issue
Block a user