Files
pyqcrm/Gui/ObjectsTable.qml
2025-03-24 11:36:09 +01:00

139 lines
4.1 KiB
QML

import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import Qt.labs.qmlmodels
ColumnLayout {
spacing: Dimensions.l
function onObjectContactAdded(added) {
console.log(added);
if (added)
object_model.viewCriterion("");
}
Component.onCompleted: {
contact_model.objectContactAdded.connect(onObjectContactAdded);
objectsStack.pop();
}
RowLayout {
Layout.fillWidth: true
spacing: Dimensions.l
SearchBar {
}
Button {
id: addObjectBtn
Layout.alignment: Qt.AlignRight
icon.source: "qrc:/images/PlusCircle.svg"
text: qsTr("Objekt Hinzufügen")
onClicked: appLoader.source = "AddObject.qml"
}
}
ColumnLayout {
id: tableColumn
Layout.fillWidth: true
Layout.fillHeight: true
Layout.verticalStretchFactor: 1
clip: true
HorizontalHeaderView {
id: horizontalHeaderview
Layout.fillWidth: true
implicitHeight: 40
movableColumns: true //@disable-check M16
syncView: objectTable
delegate: Rectangle {
Layout.fillWidth: true
border.color: addObjectBtn.palette.base
color: addObjectBtn.palette.alternateBase
implicitHeight: 40
implicitWidth: 1
Text {
color: addObjectBtn.palette.text
elide: Text.ElideRight
height: parent.height
horizontalAlignment: Text.AlignHCenter
text: model.display
verticalAlignment: Text.AlignVCenter
width: parent.width
}
}
}
TableView {
id: objectTable
property real newWidth: 0
Layout.fillWidth: true
Layout.fillHeight: true
alternatingRows: true
columnSpacing: 1
height: parent.height - horizontalHeaderview.height
model: object_model
resizableColumns: true // @disable-check M16
rowSpacing: 2
selectionBehavior: TableView.SelectRows
z: 0
ScrollBar.vertical: ScrollBar {
policy: objectTable.contentHeight > objectTable.height ? ScrollBar.AlwaysOn : ScrollBar.AlwaysOff
}
delegate: Rectangle {
required property bool current
required property bool selected
color: selected ? addObjectBtn.palette.highlight
: (objectTable.alternatingRows && row % 2 !== 0 ? addObjectBtn.palette.base
: addObjectBtn.palette.alternateBase)
implicitHeight: 25
implicitWidth: objectTable.width / objectTable.columns
Text {
color: addObjectBtn.palette.text
elide: Text.ElideRight
height: parent.height
leftPadding: 9 //@disable-check M16
text: (model.display === null || model.display === undefined) ? "" : model.display
verticalAlignment: Text.AlignVCenter
width: parent.width
}
MouseArea {
id: mouseArea
property bool hovered: false
anchors.fill: parent
hoverEnabled: true
onDoubleClicked: {
objectsStack.push("ObjectDetails.qml", {
selectedObject: row
});
}
onEntered: {
objectTable.selectionModel.select(objectTable.model.index(row, 0), ItemSelectionModel.SelectCurrent | ItemSelectionModel.Rows);
}
}
}
selectionModel: ItemSelectionModel {
id: obmodel
model: objectTable.model
}
}
Item {
Layout.fillWidth: true
}
}
}