diff --git a/qml/dummyview.qml b/qml/dummyview.qml index ac6c489..3cf8b1a 100644 --- a/qml/dummyview.qml +++ b/qml/dummyview.qml @@ -8,7 +8,6 @@ ApplicationWindow visible: true width: 600 height: 400 - title: "TableView mit myChildModel" TreeView { @@ -19,27 +18,39 @@ ApplicationWindow model: myChildModel + columnWidthProvider: function(column) + { + var z= 2*(width / columns); + console.log("Firz:", z); + console.log("Berechne Spaltenbreite für column:", column); + console.log("Aktuelle TreeView-Breite:", width); + return z; + } + delegate: Rectangle { - implicitWidth: 150 - implicitHeight: 40 + required property int row + required property int column + required property var model + + border.width: 0 + + implicitWidth: 30 + implicitHeight: 30 border.color: "#cccccc" //color: index % 2 === 0 ? "#f9f9f9" : "#e0e0e0" + color: TreeView.isSelected ? "#d0eaff" : (row % 2 === 0 ? "#f9f9f9" : "#ffffff") - Text { + Text + { anchors.centerIn: parent - text: display + text: display font.pixelSize: 14 } } - ScrollBar.horizontal: ScrollBar {} ScrollBar.vertical: ScrollBar {} - - - } - } diff --git a/qml/xqtreeview.qml b/qml/xqtreeview.qml new file mode 100644 index 0000000..af6e020 --- /dev/null +++ b/qml/xqtreeview.qml @@ -0,0 +1,48 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts + + +TreeView +{ + anchors.fill: parent + clip: true + columnSpacing: 1 + rowSpacing: 1 + + model: xtrChildModel + + columnWidthProvider: function(column) + { + var z= 1.7*(width / columns); + console.log("höh!"); + return z; + } + + delegate: Rectangle + { + required property int row + required property int column + required property var model + + border.width: 0 + + implicitWidth: 30 + implicitHeight: 20 + border.color: "#cccccc" + //color: index % 2 === 0 ? "#f9f9f9" : "#e0e0e0" + color: TreeView.isSelected ? "#d0eaff" : (row % 2 === 0 ? "#f9f9f9" : "#ffffff") + + Text + { + anchors.centerIn: parent + text: display + font.pixelSize: 12 + } + } + + ScrollBar.horizontal: ScrollBar {} + ScrollBar.vertical: ScrollBar {} +} + + diff --git a/src/application/xqmainwindow.cpp b/src/application/xqmainwindow.cpp index 3e3affd..98629a8 100644 --- a/src/application/xqmainwindow.cpp +++ b/src/application/xqmainwindow.cpp @@ -332,8 +332,8 @@ void XQMainWindow::loadDocumentQML( const QString& fileName ) XQQuickWidget* quickChild = new XQQuickWidget(_tabWidget); //quickChild->setResizeMode(QQuickWidget::SizeViewToRootObject); - quickChild->rootContext()->setContextProperty("myChildModel", childModel); - quickChild->setSource(QUrl("qrc:/xqtableview.qml")); + quickChild->rootContext()->setContextProperty("xtrChildModel", childModel); + quickChild->setSource(QUrl("qrc:/xqtreeview.qml")); _tabWidget->addTab( quickChild, "QML:"+fName ); _tabWidget->setCurrentWidget( quickChild ); quickChild->setResizeMode(QQuickWidget::SizeRootObjectToView); diff --git a/src/items/xqitem.h b/src/items/xqitem.h index 3ae92cb..f568c24 100644 --- a/src/items/xqitem.h +++ b/src/items/xqitem.h @@ -15,6 +15,7 @@ #ifndef XQITEM_H #define XQITEM_H +#include #include #include #include @@ -35,6 +36,8 @@ class XQItemType; class XQItem : public QStandardItem { + QML_ELEMENT + friend class XQItemFactory; public: diff --git a/src/main.cpp b/src/main.cpp index 8c49fb2..b92de74 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -74,31 +74,6 @@ XQChildModel* createChildModel() } -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[]) @@ -106,8 +81,6 @@ int main(int argc, char *argv[]) /* - - // Signal für einzelne QStandardItem-Änderungen connect(model, &QStandardItemModel::itemChanged, this, [](QStandardItem *changedItem){ @@ -116,17 +89,16 @@ 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 ); @@ -152,6 +124,7 @@ connect(model, &QStandardItemModel::itemChanged, qDebug() << " hhakl!"; +*/ return app.exec(); } diff --git a/src/model/xqcommand.cpp b/src/model/xqcommand.cpp index eb34745..d7bbb37 100644 --- a/src/model/xqcommand.cpp +++ b/src/model/xqcommand.cpp @@ -121,7 +121,7 @@ void XQCommand::saveNodes( const QModelIndexList& list ) //! erzeugt einen string aus dem command-type, fürs debuggen. -QString XQCommand::toString() +QString XQCommand::toString() const { static QMap s_CmdTypeMap diff --git a/src/model/xqcommand.h b/src/model/xqcommand.h index f68d8d0..607f186 100644 --- a/src/model/xqcommand.h +++ b/src/model/xqcommand.h @@ -80,7 +80,7 @@ public: void redo() override; void undo() override; - QString toString(); + QString toString() const; protected: diff --git a/src/model/xqviewmodel.cpp b/src/model/xqviewmodel.cpp index 683da7a..72e71dc 100644 --- a/src/model/xqviewmodel.cpp +++ b/src/model/xqviewmodel.cpp @@ -195,35 +195,10 @@ void XQViewModel::onActionTriggered(QAction* action) } -/* - switch (command.commandType()) - { - case XQCommand::cmdToggleSection: - return cmdToggleSection( command.originIndex() ); - - case XQCommand::cmdCut: - return cmdCut( command ); - - case XQCommand::cmdPaste: - return cmdPaste( command ); - - case XQCommand::cmdNew: - return cmdNew( command ); - - case XQCommand::cmdDelete: - return cmdDelete( command ); - - case XQCommand::cmdMove: - break; - - default: - qDebug() << " --- onCommandRedo: default: not handled: " << command.toString(); - } - */ //! führt die 'redo' action des gegebenen commnds aus. -void XQViewModel::onCommandRedo( XQCommand& command ) +void XQViewModel::onCommandRedo( const XQCommand& command ) { static MemCallMap redoCalls { @@ -249,45 +224,10 @@ void XQViewModel::onCommandRedo( XQCommand& command ) } } -/* - try - { - switch (command.commandType()) - { - case XQCommand::cmdToggleSection: - return cmdToggleSection( command.originIndex() ); - break; - // undo Cut -> perform undoCut - case XQCommand::cmdCut: - return cmdCutUndo( command ); - - // undo Paste -> perform Cut - case XQCommand::cmdPaste: - return cmdPasteUndo( command ); - - // undo Move -> perform move back - case XQCommand::cmdMove: - // not yet implemented - break; - - // undo New -> perform Delete - case XQCommand::cmdNew: - cmdNewUndo( command ); - break; - - // undo Delete -> perform New - case XQCommand::cmdDelete: - qDebug() << " --- onCommandUndo: delete: " << command.toString(); - return cmdDeleteUndo( command ); - - default: - qDebug() << " --- onCommandUndo: default: not handled: " << command.toString(); - } - */ //! führt die 'undo' action des gegebenen commnds aus. -void XQViewModel::onCommandUndo( XQCommand& command ) +void XQViewModel::onCommandUndo( const XQCommand& command ) { qDebug() << " --- onCommandUndo: count: " << XQNode::s_Count; @@ -319,7 +259,7 @@ void XQViewModel::onCommandUndo( XQCommand& command ) //! markierte knoten entfernen, 'command' enthält die liste -void XQViewModel::cmdCut( XQCommand& command ) +void XQViewModel::cmdCut( const XQCommand& command ) { // wir gehen rückwärts über alle gemerkten knoten ... for (auto it = command.rbegin(); it != command.rend(); ++it) @@ -340,7 +280,7 @@ void XQViewModel::cmdCut( XQCommand& command ) //! entfernte knoten wieder einfügen , 'command' enthält die liste -void XQViewModel::cmdCutUndo( XQCommand& command ) +void XQViewModel::cmdCutUndo( const XQCommand& command ) { // die anfangsposition int itmPos = command.first().itemPos; @@ -364,7 +304,7 @@ void XQViewModel::cmdCutUndo( XQCommand& command ) //! clipboard inhalte einfügen -void XQViewModel::cmdPaste( XQCommand& command ) +void XQViewModel::cmdPaste( const XQCommand& command ) { // selection holen ... QItemSelectionModel* selectionModel = treeTable()->selectionModel(); @@ -399,14 +339,16 @@ void XQViewModel::cmdPaste( XQCommand& command ) } // unsere änderungen merken fürs 'undo' - command.saveNodes( selectionModel->selectedRows() ); + + /// fix_xx + const_cast(command).saveNodes( selectionModel->selectedRows() ); } //! einfügen aus dem clipboard wieder rückgängig machen -void XQViewModel::cmdPasteUndo( XQCommand& command ) +void XQViewModel::cmdPasteUndo( const XQCommand& command ) { command.dumpList("Paste UNDO"); // wir gehen rückwärts über alle markieren knoten ... @@ -427,7 +369,7 @@ void XQViewModel::cmdPasteUndo( XQCommand& command ) //! entfernen der selection ohne copy in clipboard. -void XQViewModel::cmdDelete( XQCommand& command ) +void XQViewModel::cmdDelete( const XQCommand& command ) { // wir gehen rückwärts über alle markieren knoten ... for (auto it = command.rbegin(); it != command.rend(); ++it) @@ -444,7 +386,7 @@ void XQViewModel::cmdDelete( XQCommand& command ) //! macht 'delete' wirder rückgängig. -void XQViewModel::cmdDeleteUndo( XQCommand& command ) +void XQViewModel::cmdDeleteUndo( const XQCommand& command ) { } @@ -452,7 +394,7 @@ void XQViewModel::cmdDeleteUndo( XQCommand& command ) //! legt eine neue, leere zeile an. -void XQViewModel::cmdNew( XQCommand& command ) +void XQViewModel::cmdNew( const XQCommand& command ) { // __fix @@ -488,14 +430,14 @@ void XQViewModel::cmdNew( XQCommand& command ) //! entfernt die neu angelegte zeile. -void XQViewModel::cmdNewUndo( XQCommand& command ) +void XQViewModel::cmdNewUndo( const XQCommand& command ) { } //! schaltet eine section sichtbar oder unsichtbar. -void XQViewModel::cmdToggleSection( XQCommand& command ) +void XQViewModel::cmdToggleSection( const XQCommand& command ) { const QModelIndex& index = command.originIndex(); Q_ASSERT(index.isValid()); diff --git a/src/model/xqviewmodel.h b/src/model/xqviewmodel.h index 5a98418..0634196 100644 --- a/src/model/xqviewmodel.h +++ b/src/model/xqviewmodel.h @@ -37,7 +37,7 @@ class XQCommand; class XQViewModel : public QStandardItemModel { Q_OBJECT - //QML_ELEMENT + QML_ELEMENT public: @@ -62,15 +62,15 @@ public: // undo-/redo-able stuff - virtual void cmdToggleSection( XQCommand& command ); - virtual void cmdCut( XQCommand& command ); - virtual void cmdCutUndo( XQCommand& command ); - virtual void cmdPaste( XQCommand& command ); - virtual void cmdPasteUndo( XQCommand& command ); - virtual void cmdDelete( XQCommand& command ); - virtual void cmdDeleteUndo( XQCommand& command ); - virtual void cmdNew( XQCommand& command ); - virtual void cmdNewUndo( XQCommand& command ); + virtual void cmdToggleSection( const XQCommand& command ); + virtual void cmdCut( const XQCommand& command ); + virtual void cmdCutUndo( const XQCommand& command ); + virtual void cmdPaste( const XQCommand& command ); + virtual void cmdPasteUndo( const XQCommand& command ); + virtual void cmdDelete( const XQCommand& command ); + virtual void cmdDeleteUndo( const XQCommand& command ); + virtual void cmdNew( const XQCommand& command ); + virtual void cmdNewUndo( const XQCommand& command ); @@ -98,8 +98,8 @@ public slots: virtual void onActionTriggered(QAction* action); // handle XQCommands ( == UndoCommand ) - virtual void onCommandRedo( XQCommand& command ); - virtual void onCommandUndo( XQCommand& command ); + virtual void onCommandRedo( const XQCommand& command ); + virtual void onCommandUndo( const XQCommand& command ); signals: @@ -117,7 +117,7 @@ protected: protected: - using MemCall = void (XQViewModel::*)(XQCommand&); + using MemCall = void (XQViewModel::*)(const XQCommand&); using MemCallMap = QMap; // das eine reference auf ein globales singleton diff --git a/src/xtree.qrc b/src/xtree.qrc index 3655eb4..5ddd828 100644 --- a/src/xtree.qrc +++ b/src/xtree.qrc @@ -9,5 +9,6 @@ ../qml/XMain.qml ../qml/VerticalHeaderViewDelegate.qml ../qml/dummyview.qml + ../qml/xqtreeview.qml \ No newline at end of file