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

    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.

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


#ifndef XQMAINWINDOW_H
#define XQMAINWINDOW_H

#include <QMainWindow>
#include <ui_xqmainwindow.h>
#include <xqdocumentstore.h>
#include <xqmainmodel.h>
#include <xqchildmodel.h>
#include <xqappdata.h>

class XQMainWindow : public QMainWindow, public Ui_XQMainWindow
{
  Q_OBJECT

public:

  XQMainWindow( QWidget* parent = nullptr );
  virtual ~XQMainWindow() = default;

  void initMainWindow();

public slots:

  virtual void onMyFirz(XQItem& item)
  {
    qDebug() << " --- myFirz: " << item.text();
  }

  void onUndo();
  void onRedo();

  void onCreateDocument();
  void onOpenDocument();
  void onSaveDocument();
  void onSaveDocumentAs();
  void onCloseDocument();
  void onAbout();
  void onExit();

  void onTreeViewItemClicked( const XQItem& item );
  void onTreeViewItemChanged( 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 );

  // fixme implement
  //void showDocument( const QString& key ){}
  void loadDocument( const QString& fileName, bool useQML=false );
  void saveDocument( const QString& fileName );

  static void setupWorkingDir();

protected:

  XQNodePtr     createDataTree( const QString& fileName );
  XQChildModel* createChildModel( const XQNodePtr& contentRoot );



  QUndoStack      _undoStack;
  XQDocumentStore _documentStore;

  XQMainModel     _mainModel;
  XQItem*         _currentProjectItem{};
  //XQChildModel*   _currentChildModel{};

};

#endif // XQMAINWINDOW_H
