2021-08-14 13:32:33 +00:00
/ * *
2022-03-05 16:49:35 +00:00
* LogarithmPlotter - 2 D plotter software to make BODE plots , sequences and distribution functions .
2024-01-10 23:11:09 +00:00
* Copyright ( C ) 2021 - 2024 Ad5001
2021-08-14 13:32:33 +00:00
*
* 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 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < https: //www.gnu.org/licenses/>.
* /
2023-05-21 22:15:09 +00:00
import QtQuick
// import QtQuick.Dialogs 1.3 as D
import QtQuick . Controls
2022-01-31 16:15:33 +00:00
import eu . ad5001 . LogarithmPlotter . Setting 1.0 as Setting
2022-10-18 14:43:39 +00:00
import eu . ad5001 . LogarithmPlotter . ObjectLists . Editor 1.0 as Editor
2021-08-14 13:32:33 +00:00
import "../js/objects.js" as Objects
2022-01-29 17:17:19 +00:00
/ * !
\ qmltype ObjectLists
2022-10-18 14:43:39 +00:00
\ inqmlmodule eu . ad5001 . LogarithmPlotter . ObjectLists
2022-01-29 17:17:19 +00:00
\ brief Tab of the drawer that allows the user to manage the objects .
2021-08-14 13:32:33 +00:00
2022-10-17 23:12:24 +00:00
This item allows the user to synthetically see all objects , while giving the user the ability
2022-01-29 17:17:19 +00:00
to show , hide , delete , change the location and color , as well as opening the editor dialog
for each object .
\ sa LogarithmPlotter , ObjectCreationGrid , ObjectLists
* /
2022-02-01 16:33:36 +00:00
ScrollView {
2021-08-14 13:32:33 +00:00
id: objectListList
signal changed ( )
property var listViews: { '' : '' } // Needs to be initialized or will be undefined -_-
2022-02-01 16:33:36 +00:00
ScrollBar.horizontal.visible: false
ScrollBar.vertical.visible: true
ListView {
id: objectsListView
model: Object . keys ( Objects . types )
2022-10-18 00:00:56 +00:00
//width: implicitWidth //objectListList.width - (implicitHeight > objectListList.parent.height ? 20 : 0)
2022-10-19 21:44:04 +00:00
implicitHeight: contentItem . childrenRect . height + footerItem . height + 10
2021-08-14 13:32:33 +00:00
2022-02-01 16:33:36 +00:00
delegate: ListView {
id: objTypeList
property string objType: objectsListView . model [ index ]
property var editingRows: [ ]
model: Objects . currentObjects [ objType ]
width: objectsListView . width
implicitHeight: contentItem . childrenRect . height
visible: model != undefined && model . length > 0
interactive: false
2021-08-14 13:32:33 +00:00
2022-02-01 16:33:36 +00:00
Component.onCompleted: objectListList . listViews [ objType ] = objTypeList // Listing in order to be refreshed
2021-08-14 13:32:33 +00:00
2022-02-01 16:33:36 +00:00
header: Row {
width: typeHeaderText . width + typeVisibilityCheckBox . visible
height: visible ? 20 : 0
visible: objTypeList . visible
CheckBox {
id: typeVisibilityCheckBox
checked: Objects . currentObjects [ objType ] != undefined ? Objects . currentObjects [ objType ] . every ( obj = > obj . visible ) : true
onClicked: {
for ( var obj of Objects . currentObjects [ objType ] ) obj . visible = this . checked
for ( var obj of objTypeList . editingRows ) obj . objVisible = this . checked
objectListList . changed ( )
}
ToolTip.visible: hovered
ToolTip.text: checked ? qsTr ( "Hide all %1" ) . arg ( Objects . types [ objType ] . displayTypeMultiple ( ) ) : qsTr ( "Show all %1" ) . arg ( Objects . types [ objType ] . displayTypeMultiple ( ) )
2021-08-14 13:32:33 +00:00
}
2022-02-01 16:33:36 +00:00
Label {
id: typeHeaderText
verticalAlignment: TextInput . AlignVCenter
text: qsTranslate ( "control" , "%1: " ) . arg ( Objects . types [ objType ] . displayTypeMultiple ( ) )
font.pixelSize: 20
}
2021-08-14 13:32:33 +00:00
}
2022-10-17 23:12:24 +00:00
delegate: ObjectRow {
2022-02-01 16:33:36 +00:00
id: controlRow
width: objTypeList . width
2022-10-17 23:12:24 +00:00
obj: Objects . currentObjects [ objType ] [ index ]
posPicker: positionPicker
2022-02-01 16:33:36 +00:00
2022-10-17 23:12:24 +00:00
onChanged: {
2022-10-18 20:40:49 +00:00
obj = Objects . currentObjects [ objType ] [ index ]
2022-10-17 23:12:24 +00:00
objectListList . update ( )
2021-08-14 13:32:33 +00:00
}
2022-10-17 23:12:24 +00:00
Component.onCompleted: objTypeList . editingRows . push ( controlRow )
2021-08-14 13:32:33 +00:00
}
}
2022-02-01 16:33:36 +00:00
// Create items
footer: ObjectCreationGrid {
id: createRow
width: objectsListView . width
objectEditor: objEditor
objectLists: objectListList
2023-10-08 20:36:23 +00:00
posPicker: positionPicker
2022-02-01 16:33:36 +00:00
}
2021-08-14 13:32:33 +00:00
}
// Object editor
2022-10-18 14:43:39 +00:00
Editor . Dialog {
2021-08-14 13:32:33 +00:00
id: objEditor
2023-05-24 01:51:42 +00:00
posPicker: positionPicker
2021-08-14 13:32:33 +00:00
}
2022-01-29 17:17:19 +00:00
/ * !
\ qmlmethod void ObjectLists: : update ( )
Updates the view of the ObjectLists .
* /
2021-08-14 13:32:33 +00:00
function update ( ) {
objectListList . changed ( )
for ( var objType in objectListList . listViews ) {
objectListList . listViews [ objType ] . model = Objects . currentObjects [ objType ]
}
}
2022-01-29 17:17:19 +00:00
/ * !
\ qmlmethod void ObjectLists: : paramTypeIn ( var parameter , var types )
Checks if the type of the provided \ c parameter is in \ c types .
\ note The type can be normal string types ( 'boolean' , 'string' , 'number' . . . ) or object types ( Enum , Dictionay , Object types . . . ) . If the latter , only the type of object type should be provided in \ c types . E.g: if you want to check if the parameter is an enum , add "Enum" to types .
* /
2021-08-14 13:32:33 +00:00
function paramTypeIn ( parameter , types = [ ] ) {
if ( types . includes ( parameter . toString ( ) ) ) return true
if ( typeof parameter == 'object' && 'type' in parameter )
return types . includes ( parameter . type )
return false
}
}