このページについて

衛星情報

「衛星情報」のサンプルでは、スカイビュー、テーブルビュー、またはRSSIビューを使用して利用可能な衛星とユーザーの現在位置を表示します。これは以下の機能で実装されています Qt Positioning および Qt Quickを使用して実装されています。

このサンプルでは、 Qt Positioning QML API:

また、このサンプルでは、カスタムC++ モデルと、QML にあるカスタムプロキシモデルを組み合わせて使用する方法も示しています。

例の動作確認

このサンプルは、以下の手順で実行できます:

UIの操作手順

このサンプルでは、3つの異なるタブで衛星情報を表示しています。データは、SatelliteSource::satellitesInView およびSatelliteSource::satellitesInUse のプロパティから取得されています。

衛星画像と表のUI

「Sky View」タブでは、「Azimuth 」および「Elevation 」attributes を使用して、衛星の相対的な位置を表示します。個々の衛星オブジェクトをクリックすると、satellite identifier 、方位角、仰角が表示されたポップアップが開きます。

[Table View] タブには、検出されたすべての衛星のリストが表示され、リストの並べ替えやフィルタリングを行うことができます。

衛星信号のバーが表示されたRSSI画面

「RSSI ビュー」タブでは、signalStrength プロパティを使用して、視野内にある衛星の信号強度を表示します。バーの下にある数値は、個々のsatellite identifiers を表しています。

「Sky View」タブと「RSSI View」タブには、現在の緯度と経度も表示されます。これらの情報は、PositionSource::position プロパティを使用して抽出されます。

タブの上部にある「Status」ブロックには、現在のモードまたは直近のエラーが表示されます。

[設定] メニューでは、アプリケーションのカラーモードを切り替えたり、ヘルプ情報を表示したりできます。

このアプリケーションは、以下の3つのモードで動作します:

アプリケーションモード説明
実行中アプリケーションは、衛星情報や位置情報の更新についてシステムに継続的に問い合わせを行います。新しいデータが入手可能になると、それが表示されます。
停止アプリケーションは、衛星および位置情報の更新を停止します。
単発アプリケーションは、衛星および位置情報の更新リクエストを1回行います。

プラットフォームが衛星情報や位置情報を提供しない場合、アプリケーションは自動的にシミュレーションモードに切り替わります。シミュレーションモードでは、あらかじめ記録された NMEA データを含むNMEA プラグインが使用されます。

注:Appleは 衛星情報を取得するためのAPIを提供していないため、macOS およびiOS では、衛星情報は常に事前に記録されたデータから取得されます。これらのAPIの制限は位置情報には影響しないため、現在位置は正しく表示されます。

現在位置の取得

現在位置は、PositionSource QMLオブジェクトから取得されます。位置情報の更新を受信するには、onPositionChanged ハンドラが使用されます。緯度および経度の文字列表現は、coordinate プロパティから抽出されます。

PositionSource {
    id: positionSource
    name: root.simulation ? "nmea" : ""
    onPositionChanged: {
        let posData = position.coordinate.toString().split(", ")
        positionBox.latitudeString = posData[0]
        positionBox.longitudeString = posData[1]
    }
}

衛星情報の取得

位置と同様に、現在の衛星情報はSatelliteSource QMLオブジェクトから取得されます。onSatellitesInViewChanged ハンドラとonSatellitesInUseChanged ハンドラを使用して、それぞれ視野内の更新された衛星と使用中の衛星を取得します。この例では、データはC++ モデルに転送され、その後すべてのビューで使用されます。

SatelliteSource {
    id: satelliteSource
    name: root.simulation ? "nmea" : ""
    onSatellitesInViewChanged: root.satellitesModel.updateSatellitesInView(satellitesInView)
    onSatellitesInUseChanged: root.satellitesModel.updateSatellitesInUse(satellitesInUse)
}

注:この例では 、QML Positioning API と、C++ モデルを QML に統合する方法の両方を示しています。そのため、衛星情報はまず `QML` で取得され、次に `C++` に転送され、さらに `QML ` へ戻されてモデルで使用されます。実際には、アプリケーションで複雑な `C++ ` モデルを使用する場合は、C++ の `QGeoSatelliteInfoSource ` クラスを直接使用することを検討してください。

カスタム C++ モデルの使用

この例では、SatelliteModel とSortFilterModel の 2 つのカスタムモデルを使用しています。

Satellite モデル

SatelliteModel クラスはQAbstractListModel から派生しており、衛星情報を表現するためにrowCount()、data()、およびroleNames()メソッドを再実装しています。QAbstractListModel を基底クラスとして使用することで、QML 、ListView 、およびRepeater の各型と組み合わせてモデルを簡単に利用できます。カスタムプロパティsize は、RSSI Viewタブ内でのみ使用され、タブバーの幅を動的に計算するために用いられます。

class SatelliteModel : public QAbstractListModel
{
    Q_OBJECT
    Q_PROPERTY(int size READ rowCount NOTIFY sizeChanged)
    QML_ELEMENT
public:
    explicit SatelliteModel(QObject *parent = nullptr);

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
    QHash<int, QByteArray> roleNames() const override;

public slots:
    void updateSatellitesInView(const QList<QGeoSatelliteInfo> &inView);
    void updateSatellitesInUse(const QList<QGeoSatelliteInfo> &inUse);

signals:
    void sizeChanged();
};

roleNames() メソッドは、モデルの役割をプロパティ名にマッピングするために使用され、QML からモデルデータにアクセスするために利用できます。例えば、id という名前は衛星識別子を抽出するために使用され、rssi という名前は信号強度を取得するために使用されます。

QHash<int, QByteArray> SatelliteModel::roleNames() const
{
    return {
        {Roles::IdRole, "id"},
        {Roles::RssiRole, "rssi"},
        {Roles::AzimuthRole, "azimuth"},
        {Roles::ElevationRole, "elevation"},
        {Roles::SystemRole, "system"},
        {Roles::SystemIdRole, "systemId"},
        {Roles::InUseRole, "inUse"},
        {Roles::VisibleNameRole, "name"}
    };
}

QML 側では、これらの名前を使用して実際の値を取得できます。例えば、RSSI Viewの実装では、rssi 、inUse 、およびid というロール名を使用して、個々の衛星を表すバーを描画しています:

Repeater {
    id: repeater
    model: root.satellitesModel
    delegate: Rectangle {
        required property var modelData
        height: rect.height
        width: view.singleWidth
        color: "transparent"
        SemiRoundedRectangle {
            anchors.bottom: satId.top
            width: parent.width
            height: (parent.height - satId.height)
                    * Math.min(parent.modelData.rssi, rect.maxVisibleLevel)
                    / rect.maxVisibleLevel
            color: parent.modelData.inUse ? root.inUseColor : root.inViewColor
        }
        Text {
            id: satId
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.bottom: parent.bottom
            text: parent.modelData.id
            color: Theme.textSecondaryColor
            font.pixelSize: Theme.smallFontSize
            font.weight: Theme.fontLightWeight
        }
    }
}
プロキシモデル

SortFilterModel クラスは、「Table View」タブに表示される衛星オブジェクトに対して、カスタムソートやフィルタリングを行うために使用されます。

このモデルは `QSortFilterProxyModel ` を継承しており、フィルタリングとソート機能を提供するために `filterAcceptsRow()` および `lessThan()` メソッドを再実装しています。また、このモデルはフィルタリングおよびソートの動作を調整するためのいくつかの `slots ` を公開しています。

class SortFilterModel : public QSortFilterProxyModel
{
    Q_OBJECT
    QML_ELEMENT
public:
    explicit SortFilterModel(QObject *parent = nullptr);

public slots:
    void updateFilterString(const QString &str);
    void updateShowInView(bool show);
    void updateShowInUse(bool show);
    void updateSelectedSystems(int id, bool show);
    void updateSortRoles(int role, bool use);

protected:
    bool filterAcceptsRow(int row, const QModelIndex &parent) const override;
    bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
};

これらのスロットは、C++ およびQML の両方から呼び出すことができます。たとえば、Satellite Identifierデリゲートは、updateSelectedSystems() スロットを使用して、特定の衛星システムに属する衛星に関する情報を表示または非表示にします。同様に、Satellite Statusデリゲートは、updateShowInView() およびupdateShowInUse() スロットを使用して、特定のステータスを持つ衛星をフィルタリングします。

Repeater {
    model: root.satelliteSystemModel
    delegate: CheckElement {
        required property var modelData
        text: modelData.name
        Layout.alignment: Qt.AlignRight
        onCheckedChanged: {
            root.sortFilterModel.updateSelectedSystems(modelData.id, checked)
        }
    }
}
    ...
CheckElement {
    text: qsTr("In View")
    Layout.alignment: Qt.AlignRight
    onCheckedChanged: root.sortFilterModel.updateShowInView(checked)
}
CheckElement {
    text: qsTr("In Use")
    Layout.alignment: Qt.AlignRight
    onCheckedChanged: root.sortFilterModel.updateShowInUse(checked)
}

QML モジュールの登録

CMake によるビルド

CMake ベースのビルドを行うには、CMakeLists.txt に以下を追加する必要があります:

qt_add_qml_module(satelliteinfo
    URI SatelliteInformation
    VERSION 1.0
    SOURCES
        roles.h
        satellitemodel.cpp satellitemodel.h
        sortfiltermodel.cpp sortfiltermodel.h
    QML_FILES
        ApplicationScreen.qml
        Button.qml
        Header.qml
        HelpPopup.qml
        LegendBox.qml
        Main.qml
        RssiView.qml
        PageButton.qml
        PermissionsScreen.qml
        PositionBox.qml
        SatelliteView.qml
        SettingsView.qml
        SkyView.qml
        Theme.qml
        ViewSwitch.qml
    RESOURCES
        icons/checkbox.svg
        icons/checkbox_blank.svg
        icons/darkmode.svg
        icons/filter.svg
        icons/help.svg
        icons/lightmode.svg
        icons/place.svg
        icons/qtlogo_green.png
        icons/qtlogo_white.png
        icons/rssiview.svg
        icons/satellite_small.png
        icons/satellite1.png
        icons/satellite2.png
        icons/search.svg
        icons/settings.svg
        icons/skyview.svg
        icons/sort.svg
        icons/tableview.svg
)
qmake ビルド

qmake によるビルドの場合、satelliteinfo.pro ファイルを次のように変更する必要があります:

CONFIG += qmltypes
QML_IMPORT_NAME = SatelliteInformation
QML_IMPORT_MAJOR_VERSION = 1

qml_resources.files = \
    qmldir \
    ApplicationScreen.qml \
    Button.qml \
    Header.qml \
    HelpPopup.qml \
    LegendBox.qml \
    Main.qml \
    RssiView.qml \
    PageButton.qml \
    PermissionsScreen.qml \
    PositionBox.qml \
    SatelliteView.qml \
    SettingsView.qml \
    SkyView.qml \
    Theme.qml \
    ViewSwitch.qml

qml_resources.prefix = /qt/qml/SatelliteInformation

RESOURCES += qml_resources

icon_resources.files = \
    icons/checkbox.svg \
    icons/checkbox_blank.svg \
    icons/darkmode.svg \
    icons/filter.svg \
    icons/help.svg \
    icons/lightmode.svg \
    icons/place.svg \
    icons/qtlogo_green.png \
    icons/qtlogo_white.png \
    icons/rssiview.svg \
    icons/satellite_small.png \
    icons/satellite1.png \
    icons/satellite2.png \
    icons/search.svg \
    icons/settings.svg \
    icons/skyview.svg \
    icons/sort.svg \
    icons/tableview.svg

icon_resources.prefix = /qt/qml/SatelliteInformation

RESOURCES += icon_resources

ソースファイル

code.qt.io のサンプルプロジェクト

関連項目: すべての Qt サンプル、Qt Positioning サンプル、およびQt Quick のサンプルとチュートリアル。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.