looking better.
This commit is contained in:
@@ -8,7 +8,6 @@ ApplicationWindow
|
|||||||
visible: true
|
visible: true
|
||||||
width: 600
|
width: 600
|
||||||
height: 400
|
height: 400
|
||||||
title: "TableView mit myChildModel"
|
|
||||||
|
|
||||||
TreeView
|
TreeView
|
||||||
{
|
{
|
||||||
@@ -19,27 +18,39 @@ ApplicationWindow
|
|||||||
|
|
||||||
model: myChildModel
|
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
|
delegate: Rectangle
|
||||||
{
|
{
|
||||||
implicitWidth: 150
|
required property int row
|
||||||
implicitHeight: 40
|
required property int column
|
||||||
|
required property var model
|
||||||
|
|
||||||
|
border.width: 0
|
||||||
|
|
||||||
|
implicitWidth: 30
|
||||||
|
implicitHeight: 30
|
||||||
border.color: "#cccccc"
|
border.color: "#cccccc"
|
||||||
//color: index % 2 === 0 ? "#f9f9f9" : "#e0e0e0"
|
//color: index % 2 === 0 ? "#f9f9f9" : "#e0e0e0"
|
||||||
|
color: TreeView.isSelected ? "#d0eaff" : (row % 2 === 0 ? "#f9f9f9" : "#ffffff")
|
||||||
|
|
||||||
Text {
|
Text
|
||||||
|
{
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
text: display
|
text: display
|
||||||
font.pixelSize: 14
|
font.pixelSize: 14
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ScrollBar.horizontal: ScrollBar {}
|
ScrollBar.horizontal: ScrollBar {}
|
||||||
ScrollBar.vertical: ScrollBar {}
|
ScrollBar.vertical: ScrollBar {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
48
qml/xqtreeview.qml
Normal file
48
qml/xqtreeview.qml
Normal file
@@ -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 {}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@@ -332,8 +332,8 @@ void XQMainWindow::loadDocumentQML( const QString& fileName )
|
|||||||
XQQuickWidget* quickChild = new XQQuickWidget(_tabWidget);
|
XQQuickWidget* quickChild = new XQQuickWidget(_tabWidget);
|
||||||
//quickChild->setResizeMode(QQuickWidget::SizeViewToRootObject);
|
//quickChild->setResizeMode(QQuickWidget::SizeViewToRootObject);
|
||||||
|
|
||||||
quickChild->rootContext()->setContextProperty("myChildModel", childModel);
|
quickChild->rootContext()->setContextProperty("xtrChildModel", childModel);
|
||||||
quickChild->setSource(QUrl("qrc:/xqtableview.qml"));
|
quickChild->setSource(QUrl("qrc:/xqtreeview.qml"));
|
||||||
_tabWidget->addTab( quickChild, "QML:"+fName );
|
_tabWidget->addTab( quickChild, "QML:"+fName );
|
||||||
_tabWidget->setCurrentWidget( quickChild );
|
_tabWidget->setCurrentWidget( quickChild );
|
||||||
quickChild->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
quickChild->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
#ifndef XQITEM_H
|
#ifndef XQITEM_H
|
||||||
#define XQITEM_H
|
#define XQITEM_H
|
||||||
|
|
||||||
|
#include <QtQmlIntegration>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QStandardItem>
|
#include <QStandardItem>
|
||||||
@@ -35,6 +36,8 @@ class XQItemType;
|
|||||||
class XQItem : public QStandardItem
|
class XQItem : public QStandardItem
|
||||||
{
|
{
|
||||||
|
|
||||||
|
QML_ELEMENT
|
||||||
|
|
||||||
friend class XQItemFactory;
|
friend class XQItemFactory;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
33
src/main.cpp
33
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;
|
using namespace Qt::Literals::StringLiterals;
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
@@ -106,8 +81,6 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Signal für einzelne QStandardItem-Änderungen
|
// Signal für einzelne QStandardItem-Änderungen
|
||||||
connect(model, &QStandardItemModel::itemChanged,
|
connect(model, &QStandardItemModel::itemChanged,
|
||||||
this, [](QStandardItem *changedItem){
|
this, [](QStandardItem *changedItem){
|
||||||
@@ -116,17 +89,16 @@ connect(model, &QStandardItemModel::itemChanged,
|
|||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
//app.setStyle("fusion");
|
//app.setStyle("fusion");
|
||||||
XQMainWindow window;
|
XQMainWindow window;
|
||||||
window.show();
|
window.show();
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
|
|
||||||
XQMainWindow::setupWorkingDir();
|
XQMainWindow::setupWorkingDir();
|
||||||
XQItemFactory::instance().initItemFactory( c_ModelSheetFileName );
|
XQItemFactory::instance().initItemFactory( c_ModelSheetFileName );
|
||||||
|
|
||||||
@@ -152,6 +124,7 @@ connect(model, &QStandardItemModel::itemChanged,
|
|||||||
|
|
||||||
qDebug() << " hhakl!";
|
qDebug() << " hhakl!";
|
||||||
|
|
||||||
|
*/
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -121,7 +121,7 @@ void XQCommand::saveNodes( const QModelIndexList& list )
|
|||||||
|
|
||||||
//! erzeugt einen string aus dem command-type, fürs debuggen.
|
//! erzeugt einen string aus dem command-type, fürs debuggen.
|
||||||
|
|
||||||
QString XQCommand::toString()
|
QString XQCommand::toString() const
|
||||||
{
|
{
|
||||||
|
|
||||||
static QMap<CmdType,QString> s_CmdTypeMap
|
static QMap<CmdType,QString> s_CmdTypeMap
|
||||||
|
@@ -80,7 +80,7 @@ public:
|
|||||||
void redo() override;
|
void redo() override;
|
||||||
void undo() override;
|
void undo() override;
|
||||||
|
|
||||||
QString toString();
|
QString toString() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@@ -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.
|
//! führt die 'redo' action des gegebenen commnds aus.
|
||||||
|
|
||||||
void XQViewModel::onCommandRedo( XQCommand& command )
|
void XQViewModel::onCommandRedo( const XQCommand& command )
|
||||||
{
|
{
|
||||||
static MemCallMap redoCalls
|
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.
|
//! 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;
|
qDebug() << " --- onCommandUndo: count: " << XQNode::s_Count;
|
||||||
|
|
||||||
@@ -319,7 +259,7 @@ void XQViewModel::onCommandUndo( XQCommand& command )
|
|||||||
|
|
||||||
//! markierte knoten entfernen, 'command' enthält die liste
|
//! 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 ...
|
// wir gehen rückwärts über alle gemerkten knoten ...
|
||||||
for (auto it = command.rbegin(); it != command.rend(); ++it)
|
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
|
//! entfernte knoten wieder einfügen , 'command' enthält die liste
|
||||||
|
|
||||||
void XQViewModel::cmdCutUndo( XQCommand& command )
|
void XQViewModel::cmdCutUndo( const XQCommand& command )
|
||||||
{
|
{
|
||||||
// die anfangsposition
|
// die anfangsposition
|
||||||
int itmPos = command.first().itemPos;
|
int itmPos = command.first().itemPos;
|
||||||
@@ -364,7 +304,7 @@ void XQViewModel::cmdCutUndo( XQCommand& command )
|
|||||||
|
|
||||||
//! clipboard inhalte einfügen
|
//! clipboard inhalte einfügen
|
||||||
|
|
||||||
void XQViewModel::cmdPaste( XQCommand& command )
|
void XQViewModel::cmdPaste( const XQCommand& command )
|
||||||
{
|
{
|
||||||
// selection holen ...
|
// selection holen ...
|
||||||
QItemSelectionModel* selectionModel = treeTable()->selectionModel();
|
QItemSelectionModel* selectionModel = treeTable()->selectionModel();
|
||||||
@@ -399,14 +339,16 @@ void XQViewModel::cmdPaste( XQCommand& command )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// unsere änderungen merken fürs 'undo'
|
// unsere änderungen merken fürs 'undo'
|
||||||
command.saveNodes( selectionModel->selectedRows() );
|
|
||||||
|
/// fix_xx
|
||||||
|
const_cast<XQCommand&>(command).saveNodes( selectionModel->selectedRows() );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! einfügen aus dem clipboard wieder rückgängig machen
|
//! 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");
|
command.dumpList("Paste UNDO");
|
||||||
// wir gehen rückwärts über alle markieren knoten ...
|
// 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.
|
//! 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 ...
|
// wir gehen rückwärts über alle markieren knoten ...
|
||||||
for (auto it = command.rbegin(); it != command.rend(); ++it)
|
for (auto it = command.rbegin(); it != command.rend(); ++it)
|
||||||
@@ -444,7 +386,7 @@ void XQViewModel::cmdDelete( XQCommand& command )
|
|||||||
|
|
||||||
//! macht 'delete' wirder rückgängig.
|
//! 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.
|
//! legt eine neue, leere zeile an.
|
||||||
|
|
||||||
void XQViewModel::cmdNew( XQCommand& command )
|
void XQViewModel::cmdNew( const XQCommand& command )
|
||||||
{
|
{
|
||||||
|
|
||||||
// __fix
|
// __fix
|
||||||
@@ -488,14 +430,14 @@ void XQViewModel::cmdNew( XQCommand& command )
|
|||||||
|
|
||||||
//! entfernt die neu angelegte zeile.
|
//! entfernt die neu angelegte zeile.
|
||||||
|
|
||||||
void XQViewModel::cmdNewUndo( XQCommand& command )
|
void XQViewModel::cmdNewUndo( const XQCommand& command )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//! schaltet eine section sichtbar oder unsichtbar.
|
//! schaltet eine section sichtbar oder unsichtbar.
|
||||||
|
|
||||||
void XQViewModel::cmdToggleSection( XQCommand& command )
|
void XQViewModel::cmdToggleSection( const XQCommand& command )
|
||||||
{
|
{
|
||||||
const QModelIndex& index = command.originIndex();
|
const QModelIndex& index = command.originIndex();
|
||||||
Q_ASSERT(index.isValid());
|
Q_ASSERT(index.isValid());
|
||||||
|
@@ -37,7 +37,7 @@ class XQCommand;
|
|||||||
class XQViewModel : public QStandardItemModel
|
class XQViewModel : public QStandardItemModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
//QML_ELEMENT
|
QML_ELEMENT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -62,15 +62,15 @@ public:
|
|||||||
|
|
||||||
// undo-/redo-able stuff
|
// undo-/redo-able stuff
|
||||||
|
|
||||||
virtual void cmdToggleSection( XQCommand& command );
|
virtual void cmdToggleSection( const XQCommand& command );
|
||||||
virtual void cmdCut( XQCommand& command );
|
virtual void cmdCut( const XQCommand& command );
|
||||||
virtual void cmdCutUndo( XQCommand& command );
|
virtual void cmdCutUndo( const XQCommand& command );
|
||||||
virtual void cmdPaste( XQCommand& command );
|
virtual void cmdPaste( const XQCommand& command );
|
||||||
virtual void cmdPasteUndo( XQCommand& command );
|
virtual void cmdPasteUndo( const XQCommand& command );
|
||||||
virtual void cmdDelete( XQCommand& command );
|
virtual void cmdDelete( const XQCommand& command );
|
||||||
virtual void cmdDeleteUndo( XQCommand& command );
|
virtual void cmdDeleteUndo( const XQCommand& command );
|
||||||
virtual void cmdNew( XQCommand& command );
|
virtual void cmdNew( const XQCommand& command );
|
||||||
virtual void cmdNewUndo( XQCommand& command );
|
virtual void cmdNewUndo( const XQCommand& command );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -98,8 +98,8 @@ public slots:
|
|||||||
virtual void onActionTriggered(QAction* action);
|
virtual void onActionTriggered(QAction* action);
|
||||||
|
|
||||||
// handle XQCommands ( == UndoCommand )
|
// handle XQCommands ( == UndoCommand )
|
||||||
virtual void onCommandRedo( XQCommand& command );
|
virtual void onCommandRedo( const XQCommand& command );
|
||||||
virtual void onCommandUndo( XQCommand& command );
|
virtual void onCommandUndo( const XQCommand& command );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ protected:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
using MemCall = void (XQViewModel::*)(XQCommand&);
|
using MemCall = void (XQViewModel::*)(const XQCommand&);
|
||||||
using MemCallMap = QMap<XQCommand::CmdType,MemCall>;
|
using MemCallMap = QMap<XQCommand::CmdType,MemCall>;
|
||||||
|
|
||||||
// das eine reference auf ein globales singleton
|
// das eine reference auf ein globales singleton
|
||||||
|
@@ -9,5 +9,6 @@
|
|||||||
<file alias="XMain.qml">../qml/XMain.qml</file>
|
<file alias="XMain.qml">../qml/XMain.qml</file>
|
||||||
<file alias="VerticalHeaderViewDelegate.qml">../qml/VerticalHeaderViewDelegate.qml</file>
|
<file alias="VerticalHeaderViewDelegate.qml">../qml/VerticalHeaderViewDelegate.qml</file>
|
||||||
<file alias="dummyview.qml">../qml/dummyview.qml</file>
|
<file alias="dummyview.qml">../qml/dummyview.qml</file>
|
||||||
|
<file alias="xqtreeview.qml">../qml/xqtreeview.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
Reference in New Issue
Block a user