qml WIFI列表过滤当前正在连接的wifi

import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import SortFilterProxyModel 0.2
import Wifi 1.0
import "qrc:/Ui_Controls"

Rectangle {
    anchors.fill: parent
    color: "black"

    function f_setWifiFilter(wifiStatus)
    {
        if (wifiStatus === WifiManage.WifiConnected ||
            wifiStatus === WifiManage.WifiRouterConnected ||
            wifiStatus === WifiManage.WifiLinking) {
            if (WifiManage.currWifi.mac != "") {
                // 将当前wifi过滤
                wifiProxyModel.filterStr = String("^((?!%1).)*$").arg(WifiManage.currWifi.mac)
            }
        } else {
            wifiProxyModel.filterStr = "[\\s\\S]"
        }
    }

    Component.onCompleted: {
        globalJs.f_getWifiList()
        busyIndicator.isRunning = true
        f_setWifiFilter(WifiManage.wifiStatus)
    }

    Connections {
        target: dlg

        function onSig_accetped(flag) {
            if (flag) {
                if (WifiManage.currWifi.mac != "") {
                    // 将当前wifi过滤
                    wifiProxyModel.filterStr = String("^((?!%1).)*$").arg(WifiManage.currWifi.mac)
                }
            }
        }
    }

    Connections {
        target: WifiManage
        function onGetWifiListEnd() {
            if (visible) {
                busyIndicator.isRunning = false
            }
        }

        function onWifiStatusChanged(wifiStatus) {
            if (wifiStatus === WifiManage.WifiConnected ||
                wifiStatus === WifiManage.WifiRouterConnected ||
                wifiStatus === WifiManage.WifiLinking) {
                console.log("________________", WifiManage.currWifi.mac)
                if (WifiManage.currWifi.mac != "") {
                    // 将当前wifi过滤
                    wifiProxyModel.filterStr = String("^((?!%1).)*$").arg(WifiManage.currWifi.mac)
                }
            } else {
                wifiProxyModel.filterStr = "[\\s\\S]"
            }
        }
    }

    // <返回
    Item {
        id: backItem
        width: parent.width
        height: lineHeight

        MouseArea {
            anchors.fill: parent
            onClicked: {
                wifiStackView.f_pop()
            }
        }

        Image {
            anchors.left: parent.left
            anchors.leftMargin: 30
            anchors.verticalCenter: parent.verticalCenter
            source: "qrc:/img/rightArrow.png"
            sourceSize: Qt.size(64, 64)
            mirror: true
        }

        Text {
            anchors.centerIn: parent
            text: qsTr("Wifi")
            font.pixelSize: 30
            color: "white"
        }
    }

    SortFilterProxyModel {
        id: wifiProxyModel

        property string filterStr: "[\\s\\S]"

        sourceModel: wifiModel
        filters: RegExpFilter {
            roleName: "mac"
            pattern: wifiProxyModel.filterStr
            caseSensitivity: Qt.CaseInsensitive
        }
        sorters: RoleSorter  { roleName: "rssi"; sortOrder: Qt.DescendingOrder  }
    }

    Flickable {
        id: wifiFlick
        clip: true
        anchors.top: backItem.bottom
        width: parent.width
        height: parent.height-backItem.height
        contentWidth: width
        contentHeight: colLay.height
        ScrollBar.vertical: ScrollBar{}

        ColumnLayout {
            id: colLay

            Item {
                id: currWifiItem
                width: wifiFlick.width
                height: 120
                visible: {
                    if (WifiManage.wifiStatus == WifiManage.WifiConnected ||
                        WifiManage.wifiStatus == WifiManage.WifiRouterConnected ||
                        WifiManage.wifiStatus == WifiManage.WifiLinking) {
                        return true
                    } else {
                        return false
                    }
                }

                Loader {
                    id: wifiStatusLoader
                    anchors.verticalCenter: parent.verticalCenter
                    sourceComponent: {
                        if (WifiManage.wifiStatus == WifiManage.WifiLinking) {
                            return connectingCom
                        } else {
                            return connectStatusCom
                        }
                    }

                    Component {
                        id: connectingCom

                        Item {
                            width: 94
                            height: lineHeight

                            Component.onCompleted: {
                                wifiBusy.isRunning = true
                            }

                            Ui_BusyIndicator {
                                id: wifiBusy
                                anchors.left: parent.left
                                anchors.leftMargin: 30
                                anchors.verticalCenter: parent.verticalCenter
                            }

                            Timer {
                                interval: 15000
                                running: wifiBusy.isRunning
                                repeat: false
                                onTriggered: {
                                    WifiManage.wifiStatus = WifiManage.WifiNoConnected
                                    wifiBusy.isRunning = false
                                }
                            }
                        }
                    }

                    Component {
                        id: connectStatusCom

                        Item {
                            width: 94
                            height: lineHeight

                            Image {
                                anchors.left: parent.left
                                anchors.leftMargin: 30
                                anchors.verticalCenter: parent.verticalCenter
                                sourceSize: Qt.size(44, 44)
                                source: {
                                    if (WifiManage.wifiStatus == WifiManage.WifiConnected) {
                                        return "qrc:/img/pass.png"
                                    } else {
                                        return "qrc:/img/wifi_error3.png"
                                    }
                                }
                            }
                        }
                    }
                }

                Rectangle {
                    anchors.centerIn: parent
                    width: parent.width
                    height: lineHeight
                    color: listBkgColor

                    Text {
                        anchors.left: parent.left
                        anchors.leftMargin: wifiStatusLoader.width
                        anchors.verticalCenter: parent.verticalCenter
                        text: WifiManage.currWifi.name
                        font.pixelSize: 30
                        color: "white"
                    }

                    Row {
                        anchors.right: parent.right
                        anchors.rightMargin: 30
                        anchors.verticalCenter: parent.verticalCenter
                        spacing: 20

                        Image {
                            visible: WifiManage.currWifi.isLock
                            source: "qrc:/img/lock.png"
                            sourceSize: Qt.size(64, 64)
                        }

                        Image {
                            anchors.verticalCenter: parent.verticalCenter
                            source: switch (WifiManage.currWifi.rssi) {
                                    case 1:
                                        return "qrc:/img/RSSI_1.png"
                                    case 2:
                                        return "qrc:/img/RSSI_2.png"
                                    case 3:
                                        return "qrc:/img/RSSI_3.png"
                                    case 4:
                                        return "qrc:/img/RSSI_4.png"
                                    default:
                                        return "qrc:/img/RSSI.png"
                                    }
                            sourceSize: Qt.size(64, 64)
                        }

                        Image {
                            source: "qrc:/img/info.png"
                            sourceSize: Qt.size(64, 64)
                        }
                    }
                }
            }

            // 网络
            Item {
                width: wifiFlick.width
                height: 60

                Row {
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.left: parent.left
                    anchors.leftMargin: 30
                    spacing: 20

                    Text {
                        anchors.verticalCenter: parent.verticalCenter
                        text: qsTr("Network")
                        font.pixelSize: 30
                        color: "white"
                    }

                    Timer {
                        interval: 15000
                        running: busyIndicator.isRunning
                        repeat: false
                        onTriggered: {
                            busyIndicator.isRunning = false
                        }
                    }

                    Ui_BusyIndicator {
                        id: busyIndicator
                        anchors.verticalCenter: parent.verticalCenter
                    }
                }
            }

            ListView {
                id: wifiView
                interactive: false
                width: wifiFlick.width
                height: count*90
                model: wifiProxyModel
                delegate: Item {
                    width: wifiView.width
                    height: lineHeight

                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            var obj = {}
                            obj.name = name
                            obj.isLock = isLock
                            obj.rssi = rssi
                            obj.mac = mac
                            obj.ip = ip
                            dlg.f_openDlg(0, obj)
                        }
                    }

                    Text {
                        anchors.left: parent.left
                        anchors.leftMargin: wifiStatusLoader.width
                        anchors.verticalCenter: parent.verticalCenter
                        text: name
                        font.pixelSize: 30
                        color: "white"
                    }

                    Row {
                        anchors.right: parent.right
                        anchors.rightMargin: 30
                        anchors.verticalCenter: parent.verticalCenter
                        spacing: 20

                        Image {
                            visible: isLock
                            source: "qrc:/img/lock.png"
                            sourceSize: Qt.size(64, 64)
                        }

                        Image {
                            anchors.verticalCenter: parent.verticalCenter
                            source: switch (rssi) {
                                    case 1:
                                        return "qrc:/img/RSSI_1.png"
                                    case 2:
                                        return "qrc:/img/RSSI_2.png"
                                    case 3:
                                        return "qrc:/img/RSSI_3.png"
                                    case 4:
                                        return "qrc:/img/RSSI_4.png"
                                    default:
                                        return "qrc:/img/RSSI.png"
                                    }
                            sourceSize: Qt.size(64, 64)
                        }

                        Image {
                            source: "qrc:/img/info.png"
                            sourceSize: Qt.size(64, 64)
                        }
                    }

                    Rectangle {
                        anchors.bottom: parent.bottom
                        anchors.right: parent.right
                        width: parent.width-wifiStatusLoader.width
                        height: 1
                        color: "#30FFFFFF"
                    }
                }
            }

            Item {
                width: wifiFlick.width
                height: 270
            }
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值