little breakthrought im QML Layouts
This commit is contained in:
@@ -117,7 +117,7 @@ void XQMainWindow::initMainWindow()
|
||||
|
||||
// #2. load demo data
|
||||
loadDocument( c_DocumentFileName1 );
|
||||
//loadDocumentQML( c_DocumentFileName2 );
|
||||
loadDocumentQML( c_DocumentFileName2 );
|
||||
|
||||
qDebug() << " --- all here: " << XQNode::s_Count;
|
||||
|
||||
@@ -131,6 +131,9 @@ void XQMainWindow::initMainWindow()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//! slot für zentrales undo
|
||||
|
||||
void XQMainWindow::onUndo()
|
||||
@@ -319,8 +322,6 @@ void XQMainWindow::loadDocumentQML( const QString& fileName )
|
||||
// das als Namen verwendet wird.
|
||||
const QString& fName = contentRoot->friendly_name();
|
||||
|
||||
QStandardItemModel* model = createModel();
|
||||
|
||||
// Ein neues Child-Model erzeugen
|
||||
XQChildModel* childModel = new XQChildModel(this);
|
||||
// die Modelstruktur anlegen
|
||||
@@ -331,13 +332,12 @@ void XQMainWindow::loadDocumentQML( const QString& fileName )
|
||||
XQQuickWidget* quickChild = new XQQuickWidget(_tabWidget);
|
||||
//quickChild->setResizeMode(QQuickWidget::SizeViewToRootObject);
|
||||
|
||||
quickChild->rootContext()->setContextProperty("meinModel", childModel);
|
||||
quickChild->setSource(QUrl(QStringLiteral("qrc:/quickview.qml")));
|
||||
_tabWidget->addTab( quickChild, "Fitze!" );
|
||||
quickChild->rootContext()->setContextProperty("myChildModel", childModel);
|
||||
quickChild->setSource(QUrl("qrc:/xqtableview.qml"));
|
||||
_tabWidget->addTab( quickChild, "QML:"+fName );
|
||||
_tabWidget->setCurrentWidget( quickChild );
|
||||
quickChild->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//! liest eine XML datei namens 'fileName'
|
||||
|
@@ -52,10 +52,11 @@ public slots:
|
||||
void onSectionCreated( const XQModelSection& section);
|
||||
void onSectionToggled( const XQModelSection& section );
|
||||
|
||||
static void setupWorkingDir();
|
||||
|
||||
protected:
|
||||
|
||||
void setupWorkingDir();
|
||||
|
||||
|
||||
// fixme implement
|
||||
void showDocumnet( const QString& key ){}
|
||||
|
90
src/main.cpp
90
src/main.cpp
@@ -15,6 +15,13 @@
|
||||
#include <QDebug>
|
||||
#include <QApplication>
|
||||
#include <QMetaType>
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QUrl>
|
||||
#include <QQmlContext>
|
||||
|
||||
#include <xqchildmodel.h>
|
||||
#include <xqquickwidget.h>
|
||||
|
||||
#include <xqmainwindow.h>
|
||||
|
||||
@@ -49,12 +56,58 @@ who is who:
|
||||
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
class DummyModel : public XQChildModel
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
DummyModel()
|
||||
{
|
||||
|
||||
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();
|
||||
addModelData( contentRoot->first_child() );
|
||||
|
||||
//XQTreeTable* treeTable = new XQTreeTable;
|
||||
//treeTable->setModel(this);
|
||||
//setTreeTable( treeTable );
|
||||
|
||||
//treeTable->show();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
QApplication app(argc, argv);
|
||||
|
||||
/*
|
||||
|
||||
|
||||
|
||||
// Signal für einzelne QStandardItem-Änderungen
|
||||
connect(model, &QStandardItemModel::itemChanged,
|
||||
this, [](QStandardItem *changedItem){
|
||||
@@ -63,10 +116,41 @@ connect(model, &QStandardItemModel::itemChanged,
|
||||
});
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
QApplication app(argc, argv);
|
||||
//app.setStyle("fusion");
|
||||
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();
|
||||
|
||||
|
@@ -31,7 +31,7 @@ void XQNodeStore::dumpList( const QString& title ) const
|
||||
//! kostruktor. übergibt command-type und die aufrufende modelView.
|
||||
|
||||
XQCommand::XQCommand(CmdType cmdType, XQViewModel* modelView )
|
||||
: _cmdType{ cmdType }, _model(modelView)
|
||||
: _cmdType{ cmdType }, _viewModel(modelView)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -66,7 +66,7 @@ void XQCommand::setCommandType( XQCommand::CmdType cmdType )
|
||||
|
||||
void XQCommand::redo()
|
||||
{
|
||||
_model->onCommandRedo( *this );
|
||||
_viewModel->onCommandRedo( *this );
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ void XQCommand::redo()
|
||||
|
||||
void XQCommand::undo()
|
||||
{
|
||||
_model->onCommandUndo( *this );
|
||||
_viewModel->onCommandUndo( *this );
|
||||
}
|
||||
|
||||
|
||||
|
@@ -84,9 +84,9 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
CmdType _cmdType{cmdInvalid};
|
||||
XQViewModel* _model{}; // needed for redo() / undo()
|
||||
QModelIndex _originIndex;
|
||||
CmdType _cmdType{cmdInvalid};
|
||||
XQViewModel* _viewModel{}; // needed for redo() / undo()
|
||||
QModelIndex _originIndex;
|
||||
|
||||
/*
|
||||
|
||||
|
@@ -40,9 +40,9 @@ bool XQModelSection::isValid() const
|
||||
return _modelIndex.isValid() && _sectionRootNode;
|
||||
}
|
||||
|
||||
const QModelIndex& XQModelSection::modelIndex() const
|
||||
QModelIndex XQModelSection::persistentModelIndex() const
|
||||
{
|
||||
return _modelIndex;
|
||||
return _modelIndex.operator QModelIndex();
|
||||
}
|
||||
|
||||
XQNodePtr XQModelSection::sectionRootNode() const
|
||||
@@ -129,7 +129,7 @@ const XQModelSection& XQModelSectionList::sectionFromRow(int itemRow ) const
|
||||
int i = size() - 1;
|
||||
for (; i >= 0; --i)
|
||||
{
|
||||
if ( at(i).modelIndex().row() < itemRow )
|
||||
if ( at(i).persistentModelIndex().row() < itemRow )
|
||||
return at(i);
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ int XQModelSectionList::lastRow(const XQModelSection& section ) const
|
||||
{
|
||||
// last section? return last row of model
|
||||
if (index == size() - 1)
|
||||
return section.modelIndex().model()->rowCount();// - 1;
|
||||
return section.persistentModelIndex().model()->rowCount();// - 1;
|
||||
// return row above the row of the next section -> last row of given section
|
||||
return at(index+1).row();
|
||||
}
|
||||
@@ -185,7 +185,7 @@ void XQModelSectionList::dump() const
|
||||
qDebug() << " --- sections dump(): " <<size() << " entries.";
|
||||
for( int i = 0; i<size(); ++i )
|
||||
{
|
||||
QModelIndex idx = at(i).modelIndex();
|
||||
QModelIndex idx = at(i).persistentModelIndex();
|
||||
qDebug() << " --- sections:" << i << "row: " << idx.row() << " keyOf(i): " << keyOf(i) << " indexData: "<< idx.data().toString() << " itemData: " << XQItem::xqItemFromIndex(idx).data(Qt::DisplayRole).toString();
|
||||
}
|
||||
|
||||
|
@@ -37,7 +37,7 @@ public:
|
||||
bool isValid() const;
|
||||
int row() const;
|
||||
|
||||
const QModelIndex& modelIndex() const;
|
||||
QModelIndex persistentModelIndex() const;
|
||||
XQNodePtr sectionRootNode() const;
|
||||
XQNodePtr sheetRootNode() const;
|
||||
XQNodePtr contentRootNode() const;
|
||||
|
@@ -19,6 +19,7 @@
|
||||
#include <QMenu>
|
||||
#include <QStandardItemModel>
|
||||
#include <QAbstractItemView>
|
||||
#include <QtQmlIntegration>
|
||||
|
||||
#include <xqsimpleclipboard.h>
|
||||
#include <xqmodelsectionlist.h>
|
||||
@@ -36,12 +37,15 @@ class XQCommand;
|
||||
class XQViewModel : public QStandardItemModel
|
||||
{
|
||||
Q_OBJECT
|
||||
//QML_ELEMENT
|
||||
|
||||
public:
|
||||
|
||||
XQViewModel(QObject* parent = nullptr);
|
||||
virtual ~XQViewModel() = default;
|
||||
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
XQTreeTable* treeTable();
|
||||
virtual void setTreeTable( XQTreeTable* mainView );
|
||||
|
||||
@@ -68,7 +72,7 @@ public:
|
||||
virtual void cmdNew( XQCommand& command );
|
||||
virtual void cmdNewUndo( XQCommand& command );
|
||||
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
|
||||
/*!
|
||||
|
||||
@@ -106,7 +110,7 @@ signals:
|
||||
protected:
|
||||
|
||||
void addSection(const XQItemList& list, const XQNodePtr& sheetNode );
|
||||
virtual void initContextMenu() = 0;
|
||||
virtual void initContextMenu(){}
|
||||
|
||||
// __fixme: should be created from xml
|
||||
virtual void setupViewProperties();
|
||||
|
@@ -1,7 +1,10 @@
|
||||
QT += core gui widgets quick quickwidgets
|
||||
# widgets-private
|
||||
|
||||
CONFIG += c++20
|
||||
CONFIG += c++20 qmltypes
|
||||
|
||||
QML_IMPORT_NAME = org.sourceworx.qmlcomponents
|
||||
QML_IMPORT_MAJOR_VERSION = 1
|
||||
|
||||
# You can make your code fail to compile if it uses deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
|
@@ -1,10 +1,13 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file alias="modeldata1.xtr">../xml/modeldata1.xtr</file>
|
||||
<file alias="modeldata2.xtr">../xml/modeldata2.xtr</file>
|
||||
<file alias="modeldata3.xtr">../xml/modeldata3.xtr</file>
|
||||
<file alias="modelsheet.xml">../xml/modelsheets.xml</file>
|
||||
<file alias="quickview.qml">../quick/quickview.qml</file>
|
||||
|
||||
</qresource>
|
||||
</RCC>
|
||||
<qresource prefix="/">
|
||||
<file alias="modeldata1.xtr">../xml/modeldata1.xtr</file>
|
||||
<file alias="modeldata2.xtr">../xml/modeldata2.xtr</file>
|
||||
<file alias="modeldata3.xtr">../xml/modeldata3.xtr</file>
|
||||
<file alias="modelsheet.xml">../xml/modelsheets.xml</file>
|
||||
<file alias="xqtableview.qml">../qml/xqtableview.qml</file>
|
||||
<file alias="HorizontalHeaderViewDelegate.qml">../qml/HorizontalHeaderViewDelegate.qml</file>
|
||||
<file alias="XMain.qml">../qml/XMain.qml</file>
|
||||
<file alias="VerticalHeaderViewDelegate.qml">../qml/VerticalHeaderViewDelegate.qml</file>
|
||||
<file alias="dummyview.qml">../qml/dummyview.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
Reference in New Issue
Block a user