/***************************************************************************

    source::worx xtree
    Copyright © 2024-2025 c.holzheuer
    christoph.holzheuer@gmail.com

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

***************************************************************************/


#include <QDebug>
#include <QApplication>
#include <QMetaType>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QUrl>
#include <QQmlContext>
#include <QStyleFactory>

#include <xqchildmodel.h>
#include <xqquickwidget.h>

#include <xqmainwindow.h>


/*

  TODO:

  - kann ich die Enums auto generieren?
      - entries einfach abzählen,
      - einen enum als type
      - auf diesen type drauf-casten, siehe qtglobal.h

  - FIX! in reality, we have nested types, also.
  - done: reference style
  - done: shared_ptr

  - try QML
  - try 'model->readMore'

doc:
 - vorhandenes xnode konzept soll am qt angebunden werden
 - datensparsam: flyweight pattern & pointer auf orig

who is who:

- item
-itemtype
 - factory
 - model
 -  section

*/

XQChildModel* createChildModel()
{
  XQChildModel* myModel = new XQChildModel();

  myModel->initModel( c_ChildModelName );

  XQNodeFactory treeLoader;
  // xml daten laden
  XQNodePtr rawTree = treeLoader.load_tree( qPrintable(c_DocumentFileName1) );
  // versteckten root node ignorieren
  XQNodePtr contentRoot = rawTree->first_child();
  myModel->addModelData( contentRoot->first_child() );

  return myModel;

}


using namespace Qt::Literals::StringLiterals;

int main(int argc, char *argv[])
{

  QApplication app(argc, argv);
  //qDebug() << QStyleFactory::keys();
  //QApplication::setStyle("fusion");
  //QApplication::setStyle("windowsvista");
  //QApplication::setStyle("windows");

  XQMainWindow window;
  window.show();

  /*
  QApplication app(argc, argv);

  XQMainWindow::setupWorkingDir();
  XQItemFactory::instance().initItemFactory( c_ModelSheetFileName );

  XQChildModel* myModel = createChildModel();
  qmlRegisterType< XQChildModel>("MyApp.Models", 1, 0, "MyChildModel");


  QQmlApplicationEngine engine;

    engine.rootContext()->setContextProperty("myChildModel", myModel);

    QObject::connect(
      &engine,
      &QQmlApplicationEngine::objectCreationFailed,
      &app,
      []() { QCoreApplication::exit(-1); },
      Qt::QueuedConnection);

    qDebug() << " fitz!";

    engine.load( QUrl(QStringLiteral("qrc:/dummyview.qml")) );
    //engine.load( QUrl(QStringLiteral("qrc:/xqtableview.qml")) );

    qDebug() << " hhakl!";

*/
  return app.exec();

}






