import Felgo import QtMultimedia import QtQuick import QtQuick.Controls import EasyModel 1.0 import com.example.database 1.0 import "../controls" import "../common" import "../model" AppPage { id: page_sys title: qsTr("系统设置") backgroundColor: app.theme_backgroundColor navigationBarHidden: true property var picinfo_list:[] signal logoutClicked signal themChange(string mode) MediaPlayer{ id: audio audioOutput: AudioOutput{} source: Qt.resolvedUrl("../../assets/mp3/button.mp3") } Connections { target: mqtt } Component { id: sqlite_component AppPage { id: sqlite_page implicitHeight: 800 implicitWidth: 1280 rightBarItem: IconButtonBarItem { iconType: IconType.paintbrush onClicked: { console.log("database") sqliteModal.open() } } //行表头-竖向的 property int verHeaderHeight: 30 property int verHeaderWidth: 150 //列表头-横向的 property int horHeaderHeight: 30 //滚动条 property color scrollBarColor: "cyan" property int scrollBarWidth: 6 //列宽 property variant columnWidthArr: [30,100,100,100,100,100,200,100,100,100,100,100,100] property variant table_mqtt_Value: ["id","dtype","ip","port","imei","uid","pwd","clientid","qos","keepalive","sub","pub","offline"] property variant table_ftp_Value: ["id","ip","port","dir","uid","pwd","mode"] property variant table_location_Value: ["id","lbs_lat","lbs_lng","gps_lat","gps_lng","gps_elevation"] property variant table_camera_Value: ["camera_type","mode","stitch_photonum","photo_width","photo_height","auto_focus"] property variant table_json_Value: ["id","datetime","json_data","json_data"] property int datacount: 1 DatabaseInterface { id: db_cfg } EasyTableModel{ id: table_model horHeader: table_mqtt_Value //initData: []//myClass.getdata_JsonArray() //initData: [] } //表格内容(不包含表头) TableView{ id: table_view height: sqlite_page.implicitHeight anchors{ left: parent.left right: parent.right top: parent.top leftMargin: 30 topMargin: sqlite_page.horHeaderHeight } clip: true boundsBehavior: Flickable.StopAtBounds columnSpacing: 1 rowSpacing: 1 //视图的高度 //contentHeight: rowHeightProvider(0) * rows + rowHeightProvider(rows-1) //视图的宽度 //contentWidth: //content内容区域边距,但是不影响滚动条的位置 //leftMargin: //topMargin: //此属性可以包含一个函数,该函数返回模型中每行的行高 rowHeightProvider: function (row) { return sqlite_page.verHeaderHeight; } //此属性可以保存一个函数,该函数返回模型中每个列的列宽 columnWidthProvider: function (column) { return sqlite_page.columnWidthArr[column]; //return Math.max(1, (table_view.width - leftMargin) / table_view.columns) } ScrollBar.vertical: ScrollBar { id: scroll_vertical anchors.right: parent.right anchors.rightMargin: 2 //active: table_view.ScrollBar.vertical.active //policy: ScrollBar.AsNeeded contentItem: Rectangle{ visible: (scroll_vertical.size<1.0) implicitWidth: sqlite_page.scrollBarWidth color: sqlite_page.scrollBarColor } } ScrollBar.horizontal: ScrollBar { id: scroll_horizontal anchors.bottom: parent.bottom anchors.bottomMargin: 2 //active: table_view.ScrollBar.vertical.active //policy: ScrollBar.AsNeeded contentItem: Rectangle{ visible: (scroll_horizontal.size<1.0) implicitHeight: sqlite_page.scrollBarWidth color: sqlite_page.scrollBarColor } } //model是在C++中定义的,和QtC++是类似的 model: table_model delegate: Rectangle { color: (model.row%2)?"orange":Qt.darker("orange") //根据行数设置背景颜色 AppText{ id : value_text anchors.centerIn: parent verticalAlignment: Text.AlignVCenter // 水平居中对齐 horizontalAlignment: Text.AlignHCenter //elide: Text.ElideRight // selectByMouse: true // selectedTextColor: "black" // selectionColor: "white" //获取单元格对应的值 text: model.value AppButton { onClicked: { var dialog = InputDialog.inputTextSingleLine(app, "请输入要修改内容", value_text.text, function(ok,text){ if(ok){ value_text.text = text model.edit=text; //将改变写入到数据库中 console.log("edit",model.value) if(sqlite_switch.checked) { if(table_combox.displayText===table_combox.model[0]||table_combox.displayText===table_combox.model[1]) { columnWidthArr = [30,100,100,100,100,100,200,100,100,100,100,100,100] db_cfg.updateData(table_combox.displayText,table_mqtt_Value[index],model.value) } if(table_combox.displayText===table_combox.model[2]||table_combox.displayText===table_combox.model[3]) { db_cfg.updateData(table_combox.displayText,table_ftp_Value[index],model.value) } if(table_combox.displayText===table_combox.model[4]) { db_cfg.updateData(table_combox.displayText,table_location_Value[index],model.value) } if(table_combox.displayText===table_combox.model[5]){ db_cfg.updateData(table_combox.displayText,table_camera_Value[index],model.value) } } } }) // Disable the negative action dialog.negativeAction = false // Dismiss when touched outside dialog.outsideTouchable = true } } // onEditingFinished: { // model.edit=text; // //将改变写入到数据库中 // console.log("edit",model.value) // if(sqlite_switch.checked) // { // if(table_combox.displayText===table_combox.model[0]||table_combox.displayText===table_combox.model[1]) // { // db_cfg.updateData(table_combox.displayText,table_mqtt_Value[index],model.value) // } // if(table_combox.displayText===table_combox.model[2]||table_combox.displayText===table_combox.model[3]) // { // db_cfg.updateData(table_combox.displayText,table_ftp_Value[index],model.value) // } // if(table_combox.displayText===table_combox.model[4]) // { // db_cfg.updateData(table_combox.displayText,table_location_Value[index],model.value) // } // } // } } } } //横项表头 Item{ id: header_horizontal anchors{ left: parent.left right: parent.right leftMargin: 30//control.verHeaderWidth } height: sqlite_page.horHeaderHeight z: 2 //暂存鼠标拖动的位置 property int posXTemp: 0 MouseArea{ anchors.fill: parent onPressed: { header_horizontal.posXTemp=mouseX; } onPositionChanged: { if(table_view.contentX+(header_horizontal.posXTemp-mouseX)>0){ table_view.contentX+=(header_horizontal.posXTemp-mouseX); }else{ table_view.contentX=0; } header_horizontal.posXTemp=mouseX; } } Row { id: header_horizontal_row anchors.fill: parent leftPadding: -table_view.contentX clip: true spacing: 0 Repeater { model: table_view.columns > 0 ? table_view.columns : 0 Rectangle { id: header_horizontal_item width: table_view.columnWidthProvider(index)+table_view.columnSpacing height: sqlite_page.horHeaderHeight color: "purple" AppText { anchors.centerIn: parent text: table_model.headerData(index, Qt.Horizontal) } Rectangle{ width: 1 height: parent.height anchors.right: parent.right color: "black" opacity: 0.5 } MouseArea{ width: 3 height: parent.height anchors.right: parent.right cursorShape: Qt.SplitHCursor onPressed: header_horizontal.posXTemp=mouseX; onPositionChanged: { if((header_horizontal_item.width-(header_horizontal.posXTemp-mouseX))>10){ header_horizontal_item.width-=(header_horizontal.posXTemp-mouseX); }else{ header_horizontal_item.width=10; } header_horizontal.posXTemp=mouseX; sqlite_page.columnWidthArr[index]=(header_horizontal_item.width-table_view.columnSpacing); //刷新布局,这样宽度才会改变 table_view.forceLayout(); } } } } } } //竖向表头 Column { id: header_verical height: sqlite_page.implicitHeight anchors{ left: parent.left top: parent.top //bottom: parent.bottom topMargin: sqlite_page.horHeaderHeight } topPadding: -table_view.contentY z: 2 clip: true spacing: 1 Repeater { model: table_view.rows > 0 ? table_view.rows : 0 Rectangle { width: 30 height: table_view.rowHeightProvider(index) color: "green" Text { anchors.centerIn: parent text: table_model.headerData(index, Qt.Vertical) } } } } // JsonListModel { // id: jsonModel // source: table_model.initData // keyField: "id" // } // AppListView { // anchors.fill: parent // bottomMargin: nativeUtils.safeAreaInsets.bottom // model: jsonModel // delegate: SimpleRow { // text: model.sub // } // // Transition animation for adding items // add: Transition { // NumberAnimation { // property: "opacity" // from: 0 // to: 1 // duration: 1000 // easing.type: Easing.OutQuad // } // } // } AppModal { id: sqliteModal fullscreen: false modalHeight: dp(380) + nativeUtils.safeAreaInsets.bottom NavigationStack { AppPage { title: "配置信息管理" rightBarItem: TextButtonBarItem { text: "关闭" textItem.font.pixelSize: sp(16) onClicked: sqliteModal.close() } Column { id: sqliteColumn width: parent.width Section { title: "数据库" ComboBox { id: sqlite_combox height: dp(40) width: parent.width/2 model: ["config.db", "data.db"] } } Section { title: "数据表" ComboBox { id: table_combox height: dp(40) width: parent.width/2 model: ["mqtt", "mqtt_other","ftp","ftp_other","location","camera","data"] onActivated: { console.log(displayText) table_model.table_name = displayText if(displayText===model[0]||displayText===model[1]) { columnWidthArr = [30,100,100,100,100,100,200,100,100,100,100,100,100] table_model.horHeader = table_mqtt_Value } else if(displayText===model[2]||displayText===model[3]) { table_model.horHeader = table_ftp_Value } else if(displayText===model[4]) { table_model.horHeader = table_location_Value }else if(displayText===model[5]){ columnWidthArr = [100,100,150,100,100,100] table_model.horHeader = table_camera_Value } else if(displayText===model[6]) { table_model.horHeader = table_json_Value } table_model.initData=db_cfg.queryData(displayText,datacount) } } } AppText { id: sqlite_text text: "开关:" } AppSwitch { id: sqlite_switch anchors.left: sqlite_text.light anchors.leftMargin: 10 onToggled: { if(sqlite_switch.checked){ var dbs = db_cfg.openDatabase(sqlite_combox.displayText) if(dbs){ console.log("打开数据库成功"); sqlite_combox.enabled = false table_combox.enabled = true if(sqlite_combox.displayText==="data.db") { table_combox.displayText=table_combox.model[6]; } table_model.table_name = table_combox.displayText table_model.initData=db_cfg.queryData(table_combox.displayText,datacount) //text_row_count.text = db_cfg.getTable_row(table_combox.displayText) //rowindex_text.text = datacount }else{ sqlite_switch.checked = false sqlite_combox.enabled = true; console.log("打开数据库失败"); } }else{ sqlite_combox.enabled = true; db_cfg.closeDatabase() console.log("关闭数据库"); } } } } } } } } } Grid { anchors.fill: parent anchors.leftMargin: 5 anchors.topMargin:5 //anchors.horizontalCenter: parent.horizontalCenter columns: 1 rows: 3 columnSpacing: 10 rowSpacing: 5 horizontalItemAlignment: Grid.AlignHCenter Rectangle { radius: 5 width: parent.width * 0.995 height: parent.height*0.18 color: app.cardColor Timer { interval: 1000 running: true repeat: true onTriggered: { picinfo_list = serial.pathinfo() text_info.text = "占用大小:" + picinfo_list[2] + "(Mb)" + "文件数量:" + picinfo_list[1] text_pathinfo.text = "图片存储目录:" + picinfo_list[0] } } AppImage { anchors.verticalCenter: parent.verticalCenter anchors.left: parent.left // fillMode: Image.PreserveAspectFit // 保持纵横比适应 source: "../../assets/floder.svg" } Column{ id: column_info anchors.verticalCenter: parent.verticalCenter // 在垂直方向上居中 anchors.left: parent.left // anchors.leftMargin: 100 AppText{ id: text_info text: "存储占用:" + "" color: app.fontColor font.bold: true } AppText{ id: text_pathinfo text:"图片存储目录:" fontSize: 10 color: "gray" } } AppButton { id:btn_fresh anchors.verticalCenter: parent.verticalCenter // 在垂直方向上居中 anchors.left: column_info.right anchors.leftMargin: dp(50) text: "刷新" flat: false textColor: "black" backgroundColor: "#e9e9e9" borderColor: "white" onClicked: { serial.readPathinfo() } } AppButton { id:btn_clear anchors.verticalCenter: parent.verticalCenter // 在垂直方向上居中 anchors.left: btn_fresh.right text: "清理" flat: false textColor: "white" backgroundColor: "#0aa26b" borderColor: "white" onClicked: { serial.removepic() } } } Row{ //anchors.fill: parent width: parent.width height: parent.height*0.35 spacing:5 Rectangle { width: parent.width*0.245 height: parent.height color: app.cardColor radius: 5 Column{ anchors.fill: parent spacing: 5 AppImage { anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示 // 将元素的顶部锚定到父元素的顶部 fillMode: Image.PreserveAspectFit // 保持纵横比适应 source: "../../assets/ztl.svg" } AppText{ anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示 text: "状态栏开关" color: app.fontColor font.bold: true } Switch{ anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示 objectName: "openbar_btn" id: openbar_btn signal opernBar signal closeBar onClicked: { if(openbar_btn.checked==true){ console.log("打开状态栏") opernBar() }else{ console.log("关闭状态栏") closeBar() } } } } } Rectangle { radius: 5 width: parent.width*0.245 height: parent.height color: app.cardColor Column{ anchors.fill: parent spacing: 5 AppImage { anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示 fillMode: Image.PreserveAspectFit // 保持纵横比适应 source: "../../assets/dhl.svg" } AppText{ anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示 id: net_sta text: "导航栏开关" color: app.fontColor font.bold: true } Switch{ id: opennav_btn objectName: "opennav_btn" signal opernNav signal closeNav anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示 onClicked: { if(opennav_btn.checked==true){ console.log("打开导航栏") opernNav() }else{ console.log("关闭导航栏") closeNav() } } } } } Rectangle { radius: 5 width: parent.width*0.245 height: parent.height color: app.cardColor MouseArea{ anchors.fill: parent onClicked: { appimage_theme.visible = false apptext_title.visible = false apptext_select.visible = false row_select.visible = true } } Column { id: row_select visible: false anchors.fill: parent spacing: 5 Component.onCompleted: { app.theme_md = settings.getValue("theme_mode") if(app.theme_md==="auto"){ auto_rdb.checked = true rec_auto_rdb.border.color = "#0aa26b" apptext_select.text = "当前:自动" }else if(theme_md==="day"){ day_rdb.checked = true; rec_day_rdb.border.color = "#0aa26b" apptext_select.text = "当前:白天" }else if(theme_md==="night"){ night_rdb.checked = true; rec_night_rdb.border.color = "#0aa26b" apptext_select.text = "当前:黑夜" } } AppText{ id: apptext_title_mode anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示 text: "设置模式" font.bold: true } CustomRadioButton { id: auto_rdb anchors.horizontalCenter: parent.horizontalCenter width: parent.width*0.8 checked: true text: "自动" Rectangle { id: rec_auto_rdb anchors.fill: parent color: "#f5f5f5" radius: 5 border.color: "#f5f5f5" border.width: 2 } onCheckedChanged: { if(auto_rdb.checked){ rec_auto_rdb.border.color = "#0aa26b" settings.setValue("theme_mode","auto") themChange("auto") apptext_select.text = "当前:自动" }else{ rec_auto_rdb.border.color = "#f5f5f5" } row_select.visible = false rec_theme.color = app.cardColor appimage_theme.visible = true apptext_title.visible = true apptext_select.visible = true } } CustomRadioButton { id: night_rdb anchors.horizontalCenter: parent.horizontalCenter width: parent.width*0.8 text: "黑夜" Rectangle { id: rec_night_rdb anchors.fill: parent color: "#f5f5f5" radius: 5 border.color: "#f5f5f5" border.width: 2 } onCheckedChanged: { if(night_rdb.checked){ settings.setValue("theme_mode","night") rec_night_rdb.border.color = "#0aa26b" themChange("night") apptext_select.text = "当前:黑夜" }else{ rec_night_rdb.border.color = "#f5f5f5" } row_select.visible = false rec_theme.color = app.cardColor appimage_theme.visible = true apptext_title.visible = true apptext_select.visible = true } } CustomRadioButton { id: day_rdb anchors.horizontalCenter: parent.horizontalCenter width: parent.width*0.8 text: "白天" Rectangle { id: rec_day_rdb anchors.fill: parent color: "#f5f5f5" radius: 5 border.color: "#f5f5f5" border.width: 2 } onCheckedChanged: { if(day_rdb.checked){ settings.setValue("theme_mode","day") rec_day_rdb.border.color = "#0aa26b" themChange("day") apptext_select.text = "当前:白天" }else{ rec_day_rdb.border.color = "#f5f5f5" } row_select.visible = false rec_theme.color = app.cardColor appimage_theme.visible = true apptext_title.visible = true apptext_select.visible = true } } } Column { anchors.fill: parent spacing: 5 AppImage { id: appimage_theme anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示 fillMode: Image.PreserveAspectFit // 保持纵横比适应 source: "../../assets/themset.svg" } AppText{ id: apptext_title anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示 text: "设置主题" color: app.fontColor font.bold: true } AppText { id: apptext_select anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示 text: "当前:" + settings.getValue("theme_mode") fontSize: 10 font.bold: false color: "gray" } } } Rectangle { radius: 5 width: parent.width*0.245 height: parent.height color: app.cardColor Column { anchors.fill: parent spacing: 10 AppButton { anchors.fill: parent onClicked: { logoutClicked() } } AppImage { anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示 fillMode: Image.PreserveAspectFit // 保持纵横比适应 source: "../../assets/logout.svg" } AppText{ anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示 text: "退出登录" color: app.fontColor font.bold: true } } } } Row { width: parent.width height: parent.height*0.43 spacing: 5 Rectangle { radius: 5 width: parent.width*0.245 height: parent.height color: app.cardColor Column { id: column_bi anchors.fill: parent MouseArea { anchors.fill: parent onClicked: { column_bi.visible = false column_bi.enabled = false column_bu.visible = true column_bu.enabled = true } } AppText{ anchors.centerIn: parent text: "控制系统版本:" + app.boardversionText fontSize: 20 font.bold: true color: app.fontColor } } Column { id: column_bu visible: false anchors.fill: parent spacing: 10 AppButton { anchors.fill: parent onClicked: { column_bi.visible = true column_bi.enabled = true column_bu.visible = false column_bu.enabled = false var dialog = InputDialog.inputTextSingleLine(page_sys, "请输入密钥!", "Input here", function(ok,text){ if(ok){ if(text==="2024"){ mqtt.sendUpdatesBoard() }else{ /* 0:普通消息框,只有一个“确定”按钮。 1:警告消息框,通常用于提醒用户注意。 2:确认消息框,包含“是”和“否”两个按钮。 3:询问消息框,包含“是”、“否”和“取消”三个按钮。 4:错误消息框,用于显示错误或异常情况。 */ nativeUtils.displayMessageBox("密钥校验错误!", "", 1) } } } ) } } AppImage { anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示 fillMode: Image.PreserveAspectFit // 保持纵横比适应 source: "../../assets/updateboard.svg" } AppText{ anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示 text: "升级主板" color: app.fontColor font.bold: true } } } Rectangle { radius: 5 width: parent.width*0.245 height: parent.height color: app.cardColor Column { id: column_ai spacing: 10 anchors.fill: parent MouseArea { anchors.fill: parent onClicked: { column_ai.visible = false column_ai.enabled = false column_au.visible = true column_au.enabled = true } } AppText{ anchors.centerIn: parent text: "App版本:" + app.appversionText fontSize: 20 font.bold: true color: app.fontColor } } Column { id: column_au visible: false spacing: 10 anchors.fill: parent AppButton { anchors.fill: parent onClicked: { column_ai.visible = true column_ai.enabled = true column_au.visible = false column_au.enabled = false var dialog = InputDialog.inputTextSingleLine(page_sys, "请输入密钥!", "Input here", function(ok,text){ if(ok){ if(text==="2024"){ mqtt.sendUpdateApp() }else{ nativeUtils.displayMessageBox("密钥校验错误!", "", 1) } } } ) } } AppImage { anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示 fillMode: Image.PreserveAspectFit // 保持纵横比适应 source: "../../assets/updateapp.svg" } AppText{ anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示 text: "升级App" color: app.fontColor font.bold: true } } } Rectangle { id: rec_theme radius: 5 width: parent.width*0.245 height: parent.height color: app.cardColor Column { anchors.fill: parent spacing: 10 AppButton { id: button_reboot anchors.fill: parent onClicked:{ serial.reboot() } } AppImage { id: image_reboot anchors.centerIn: parent //anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示 fillMode: Image.PreserveAspectFit // 保持纵横比适应 source: "../../assets/reboot.svg" } AppText{ id: text_reboot anchors.horizontalCenter: parent.horizontalCenter //垂直居中显示 anchors.top: image_reboot.bottom anchors.topMargin: 10 text: "系统重启" color: app.fontColor font.bold: true } } } Rectangle { radius: 5 width: parent.width*0.245 height: parent.height color: app.cardColor MouseArea { anchors.fill: parent onClicked: { if(column_di.visible === false){ column_di.visible = true column_di.enabled = true column_debug.visible = false column_debug.enabled = false } } } Column { id: column_di spacing: 10 anchors.fill: parent AppButton { anchors.centerIn: parent text: "高级功能" textColor: app.fontColor flat: false borderColor: "green" fontBold: true onClicked: { var dialog = InputDialog.inputTextSingleLine(page_sys, "请输入密钥!", "Input here", function(ok,text){ if(ok){ if(text==="2024"){ column_di.visible = false column_di.enabled = false column_debug.visible = true column_debug.enabled = true }else{ nativeUtils.displayMessageBox("密钥校验错误!", "", 1) } } } ) } } } Column { id: column_debug spacing: 10 visible: false enabled: false anchors.fill: parent AppCheckBox { id: acb_log text: "日志" anchors.horizontalCenter: parent.horizontalCenter onCheckedChanged: { if(acb_log.checked){ app.log_enable = true console.log("日志开") }else{ app.log_enable = false console.log("日志关") } } } AppCheckBox { id: acb_stitch text: "拼接" anchors.horizontalCenter: parent.horizontalCenter onCheckedChanged: { if(acb_stitch.checked){ app.stitch_enable = true console.log("拼接参数开") }else{ app.stitch_enable = false console.log("拼接参数关") } } } AppCheckBox { id: acb_pqt text: "清晰度" anchors.horizontalCenter: parent.horizontalCenter onCheckedChanged: { if(acb_pqt.checked){ app.photoclarity = true console.log("拼接参数开") }else{ app.photoclarity = false console.log("拼接参数关") } } } AppButton { anchors.horizontalCenter: parent.horizontalCenter text: "SQLITE" implicitHeight: 25 implicitWidth: 40 flat: false onClicked: { //打开SQLIT界面 page_sys.navigationStack.push(sqlite_component) // var component = Qt.createComponent("SqlScreen.qml") // if(component.status === Component.Ready){ // var SqlScreen = component.createObject(parent) // if(SqlScreen!==null){ // SqlScreen.show() // } // } } } } } } } }