messups.
This commit is contained in:
@@ -103,6 +103,7 @@ void XQMainWindow::initMainWindow()
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
// hand over undostack
|
||||
_mainModel.setUndoStack(&_undoStack);
|
||||
// hand over left side navigation tree
|
||||
@@ -110,11 +111,16 @@ void XQMainWindow::initMainWindow()
|
||||
// #1. init the left side main tree view
|
||||
_mainModel.initModel( c_MainModelName );
|
||||
|
||||
// 1: Wiebelbach
|
||||
// 2: Gerbrunn
|
||||
// 3: TBB
|
||||
|
||||
// #2. load demo data
|
||||
loadDocument( c_DocumentFileName1 );
|
||||
loadDocumentQML( c_DocumentFileName2 );
|
||||
//loadDocument( c_DocumentFileName2, true );
|
||||
//loadDocument( c_DocumentFileName2 );
|
||||
//loadDocument( c_DocumentFileName3 );
|
||||
loadDocument( c_DocumentFileName3 );
|
||||
|
||||
|
||||
qDebug() << " --- all here: " << XQNode::s_Count;
|
||||
|
||||
@@ -297,18 +303,15 @@ void XQMainWindow::onSectionCreated( const XQModelSection& section )
|
||||
//! SLOT, der aufgerufen wird, wenn eine section getoggelt wurde.
|
||||
|
||||
void XQMainWindow::onSectionToggled( const XQModelSection& section )
|
||||
{
|
||||
qDebug() << " --- XXX section toggled: " << section.contentType() << ":" << section.sheetRootNode()->to_string();
|
||||
{
|
||||
for (int row = 0; row < _currentProjectItem->rowCount(); ++row)
|
||||
{
|
||||
for (int row = 0; row < _currentProjectItem->rowCount(); ++row)
|
||||
QStandardItem* child = _currentProjectItem->child(row);
|
||||
if (child->text() == section.contentType() )
|
||||
{
|
||||
QStandardItem* child = _currentProjectItem->child(row);
|
||||
if (child->text() == section.contentType() )
|
||||
{
|
||||
bool checked = (child->checkState() == Qt::Checked);
|
||||
child->setCheckState( checked ? Qt::Unchecked :Qt::Checked );
|
||||
break;
|
||||
}
|
||||
bool checked = (child->checkState() == Qt::Checked);
|
||||
child->setCheckState( checked ? Qt::Unchecked :Qt::Checked );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -328,6 +331,103 @@ void XQMainWindow::setChildTabByName( const QString& key )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
XQNodePtr XQMainWindow::createDataTree( const QString& fileName )
|
||||
{
|
||||
// gibts die Datei?
|
||||
if( !QFile::exists( fileName) )
|
||||
throw XQException( "no such file", fileName );
|
||||
|
||||
XQNodeFactory treeLoader;
|
||||
// xml daten laden
|
||||
XQNodePtr rawTree = treeLoader.load_tree( qPrintable(fileName) );
|
||||
// versteckten root node ignorieren
|
||||
return rawTree->first_child();
|
||||
}
|
||||
|
||||
|
||||
XQChildModel* XQMainWindow::createChildModel( const XQNodePtr& contentRoot )
|
||||
{
|
||||
// Ein neues Child-Model erzeugen
|
||||
XQChildModel* childModel = new XQChildModel(this);
|
||||
|
||||
connect( childModel, SIGNAL(sectionCreated(XQModelSection)), this, SLOT(onSectionCreated(XQModelSection)) );
|
||||
connect( childModel, SIGNAL(sectionToggled(XQModelSection)), this, SLOT(onSectionToggled(XQModelSection)) );
|
||||
|
||||
// Den globalen undo-stack ...
|
||||
childModel->setUndoStack(&_undoStack);
|
||||
|
||||
// die Modelstruktur anlegen
|
||||
childModel->initModel( c_ChildModelName );
|
||||
|
||||
// model inhalte laden
|
||||
childModel->addModelData( contentRoot->first_child() );
|
||||
|
||||
return childModel;
|
||||
|
||||
}
|
||||
|
||||
//! liest eine XML datei namens 'fileName'
|
||||
|
||||
void XQMainWindow::loadDocument( const QString& fileName, bool useQML )
|
||||
{
|
||||
|
||||
// Datenbaum laden
|
||||
XQNodePtr contentRoot = createDataTree( fileName );
|
||||
|
||||
// Falls schon vorhanden ...
|
||||
const QString& pID = contentRoot->attribute(c_ProjectID);
|
||||
int idx = _documentStore.indexOf( pID );
|
||||
if( idx > -1 )
|
||||
{
|
||||
const XQDocument& document = _documentStore.at(idx);
|
||||
QMessageBox::warning( this, "Load Document", QString("File: %1 already loaded.").arg( fileName ) );
|
||||
_mainTreeView->setCurrentIndex( document.treeItem->index() );
|
||||
_tabWidget->setCurrentIndex( idx );
|
||||
// ... wird nichts wieter unternommen
|
||||
return;
|
||||
}
|
||||
|
||||
// 'friendly Name' ist ein Link auf ein anderes Attribute
|
||||
// das als Namen verwendet wird.
|
||||
const QString& fName = contentRoot->friendly_name();
|
||||
QString pTabTitle = QString("Project %1: %2").arg( pID, fName );
|
||||
|
||||
// neuen eintrag im übsichts-baum erzeugen
|
||||
_currentProjectItem = _mainModel.addProjectItem( contentRoot );
|
||||
// Kindmodel für den Datenbaum erzeugen.
|
||||
XQChildModel* childModel = createChildModel(contentRoot);
|
||||
|
||||
_documentStore.addDocument( fileName, fName, _currentProjectItem, childModel );
|
||||
|
||||
|
||||
QWidget* childView{};
|
||||
if(useQML)
|
||||
{
|
||||
XQQuickWidget* quickView= new XQQuickWidget(_tabWidget);
|
||||
//quickChild->setResizeMode(QQuickWidget::SizeViewToRootObject);
|
||||
|
||||
quickView->rootContext()->setContextProperty("xtrChildModel", childModel);
|
||||
quickView->setSource(QUrl("qrc:/xqtreeview.qml"));
|
||||
childView = quickView;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Eine neue TreeView erzeugn und im TabWidget parken.
|
||||
XQTreeTable* treeTable = new XQTreeTable(_tabWidget);
|
||||
// und die TreeView übergeben
|
||||
childModel->setTreeTable(treeTable);
|
||||
childView = treeTable;
|
||||
}
|
||||
|
||||
_tabWidget->addTab( childView, pTabTitle );
|
||||
_tabWidget->setCurrentWidget( childView );
|
||||
setWindowTitle( pTabTitle );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void XQMainWindow::loadDocumentQML( const QString& fileName )
|
||||
{
|
||||
// gibts die Datei?
|
||||
@@ -356,74 +456,13 @@ void XQMainWindow::loadDocumentQML( const QString& fileName )
|
||||
//quickChild->setResizeMode(QQuickWidget::SizeViewToRootObject);
|
||||
|
||||
quickChild->rootContext()->setContextProperty("xtrChildModel", childModel);
|
||||
quickChild->setSource(QUrl("qrc:/xqtreeview.qml"));
|
||||
quickChild->setSource(QUrl("qrc:/xqtreeview.qml"));
|
||||
_tabWidget->addTab( quickChild, "QML:"+fName );
|
||||
_tabWidget->setCurrentWidget( quickChild );
|
||||
quickChild->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
||||
|
||||
}
|
||||
|
||||
//! liest eine XML datei namens 'fileName'
|
||||
|
||||
void XQMainWindow::loadDocument( const QString& fileName )
|
||||
{
|
||||
|
||||
// gibts die Datei?
|
||||
if( !QFile::exists( fileName) )
|
||||
throw XQException( "no such file", fileName );
|
||||
|
||||
XQNodeFactory treeLoader;
|
||||
// xml daten laden
|
||||
XQNodePtr rawTree = treeLoader.load_tree( qPrintable(fileName) );
|
||||
// versteckten root node ignorieren
|
||||
XQNodePtr contentRoot = rawTree->first_child();
|
||||
// Project-ID behandeln
|
||||
const QString& pID = contentRoot->attribute(c_ProjectID);
|
||||
int idx = _documentStore.indexOf( pID );
|
||||
if( idx > -1 )
|
||||
{
|
||||
const XQDocument& document = _documentStore.at(idx);
|
||||
QMessageBox::warning( this, "Load Document", QString("File: %1 already loaded.").arg( fileName ) );
|
||||
_mainTreeView->setCurrentIndex( document.treeItem->index() );
|
||||
_tabWidget->setCurrentIndex( idx );
|
||||
return;
|
||||
}
|
||||
|
||||
// 'friendly Name' ist ein Link auf ein anderes Attribute
|
||||
// das als Namen verwendet wird.
|
||||
const QString& fName = contentRoot->friendly_name();
|
||||
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, pTabTitle );
|
||||
_tabWidget->setCurrentWidget( childTreeView );
|
||||
setWindowTitle( pTabTitle );
|
||||
|
||||
// Ein neues Child-Model erzeugen
|
||||
XQChildModel* childModel = new XQChildModel(this);
|
||||
|
||||
connect( childModel, SIGNAL(sectionCreated(XQModelSection)), this, SLOT(onSectionCreated(XQModelSection)) );
|
||||
connect( childModel, SIGNAL(sectionToggled(XQModelSection)), this, SLOT(onSectionToggled(XQModelSection)) );
|
||||
|
||||
// Den globalen undo-stack ...
|
||||
childModel->setUndoStack(&_undoStack);
|
||||
|
||||
// und die TreeView übergeben
|
||||
childModel->setTreeTable(childTreeView);
|
||||
|
||||
// neuen eintrag im übsichts-baum erzeugen
|
||||
_currentProjectItem = _mainModel.addProjectItem( contentRoot );
|
||||
_documentStore.addDocument( fileName, fName, _currentProjectItem, childModel );
|
||||
|
||||
// die Modelstruktur anlegen
|
||||
childModel->initModel( c_ChildModelName );
|
||||
|
||||
// model inhalte laden
|
||||
childModel->addModelData( contentRoot->first_child() );
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//! speichert ein XML unter dem 'filename'
|
||||
|
@@ -61,15 +61,21 @@ public slots:
|
||||
|
||||
void setChildTabByName( const QString& key );
|
||||
|
||||
// fixme implement
|
||||
//void showDocument( const QString& key ){}
|
||||
void loadDocument( const QString& fileName, bool useQML=false );
|
||||
void loadDocumentQML( const QString& fileName );
|
||||
void saveDocument( const QString& fileName );
|
||||
|
||||
static void setupWorkingDir();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// fixme implement
|
||||
void showDocument( const QString& key ){}
|
||||
void loadDocument( const QString& fileName );
|
||||
void loadDocumentQML( const QString& fileName );
|
||||
void saveDocument( const QString& fileName );
|
||||
XQNodePtr createDataTree( const QString& fileName );
|
||||
XQChildModel* createChildModel( const XQNodePtr& contentRoot );
|
||||
|
||||
|
||||
|
||||
QUndoStack _undoStack;
|
||||
XQDocumentStore _documentStore;
|
||||
|
Reference in New Issue
Block a user