From f83c13ad852b2f21c0884b212a0931ad3afbe2f6 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 5 Jul 2018 20:11:35 -0700 Subject: [PATCH] Cleanup ComputerModel and remove root Frame from PcView --- app/gui/PcView.qml | 154 +++++++++++++++++++------------------- app/gui/computermodel.cpp | 6 +- app/gui/computermodel.h | 4 +- 3 files changed, 80 insertions(+), 84 deletions(-) diff --git a/app/gui/PcView.qml b/app/gui/PcView.qml index 22c0a4d9..80e09012 100644 --- a/app/gui/PcView.qml +++ b/app/gui/PcView.qml @@ -5,100 +5,96 @@ import QtQuick.Layouts 1.11 import ComputerModel 1.0 -Frame { +GridView { anchors.fill: parent + anchors.leftMargin: 5 + anchors.topMargin: 5 + anchors.rightMargin: 5 + anchors.bottomMargin: 5 + cellWidth: 350; cellHeight: 350; + focus: true - GridView { - anchors.fill: parent - anchors.leftMargin: 5 - anchors.topMargin: 5 - anchors.rightMargin: 5 - anchors.bottomMargin: 5 - cellWidth: 350; cellHeight: 350; - focus: true + model: ComputerModel {} - model: ComputerModel {} + delegate: Item { + width: 300; height: 300; - delegate: Item { - width: 300; height: 300; - - Image { - id: pcIcon - anchors.horizontalCenter: parent.horizontalCenter; - source: { - model.addPc ? "ic_add_to_queue_white_48px.svg" : "ic_tv_white_48px.svg" - } - sourceSize { - width: 200 - height: 200 - } + Image { + id: pcIcon + anchors.horizontalCenter: parent.horizontalCenter; + source: { + model.addPc ? "ic_add_to_queue_white_48px.svg" : "ic_tv_white_48px.svg" } - - Text { - id: pcNameText - text: model.name - color: "white" - - width: parent.width - anchors.top: pcIcon.bottom - minimumPointSize: 12 - font.pointSize: 48 - horizontalAlignment: Text.AlignHCenter - fontSizeMode: Text.HorizontalFit + sourceSize { + width: 200 + height: 200 } + } - Text { - function getStatusText(model) - { - if (model.online) { - var text = "Online" - text += " - " - if (model.paired) { - text += "Paired" - } - else if (model.busy) { - text += "Busy" - } - else { - text += "Not Paired" - } - return text + Text { + id: pcNameText + text: model.name + color: "white" + + width: parent.width + anchors.top: pcIcon.bottom + minimumPointSize: 12 + font.pointSize: 48 + horizontalAlignment: Text.AlignHCenter + fontSizeMode: Text.HorizontalFit + } + + Text { + function getStatusText(model) + { + if (model.online) { + var text = "Online" + text += " - " + if (model.paired) { + text += "Paired" + } + else if (model.busy) { + text += "Busy" } else { - return "Offline"; + text += "Not Paired" } + return text + } + else { + return "Offline"; } - - id: pcPairedText - text: getStatusText(model) - visible: !model.addPc - - width: parent.width - anchors.top: pcNameText.bottom - minimumPointSize: 12 - font.pointSize: 36 - horizontalAlignment: Text.AlignHCenter - fontSizeMode: Text.HorizontalFit } - MouseArea { - anchors.fill: parent - onClicked: { - parent.GridView.view.currentIndex = index - if(model.addPc) { - // TODO: read the output of the dialog - inputDialog.on - inputDialog.open() + id: pcPairedText + text: getStatusText(model) + visible: !model.addPc - } else if(!model.paired && !model.busy) { + width: parent.width + anchors.top: pcNameText.bottom + minimumPointSize: 12 + font.pointSize: 36 + horizontalAlignment: Text.AlignHCenter + fontSizeMode: Text.HorizontalFit + } - // TODO: generate pin - pairDialog.text = pairDialog.text.replace("XXXX", "1234") - // TODO: initiate pairing request - pairDialog.open() - } else if (model.online) { - // go to game view - } + MouseArea { + anchors.fill: parent + onClicked: { + parent.GridView.view.currentIndex = index + if(model.addPc) { + // TODO: read the output of the dialog + inputDialog.on + inputDialog.open() + + } else if(!model.paired && !model.busy) { + + // TODO: generate pin + pairDialog.text = pairDialog.text.replace("XXXX", "1234") + // TODO: initiate pairing request + pairDialog.open() + } else if (model.online) { + // go to game view } } } diff --git a/app/gui/computermodel.cpp b/app/gui/computermodel.cpp index 5fa57cdc..284b0346 100644 --- a/app/gui/computermodel.cpp +++ b/app/gui/computermodel.cpp @@ -27,10 +27,8 @@ QVariant ComputerModel::data(const QModelIndex& index, int role) const return QVariant(); } } - else if (index.row() > m_Computers.count()) { - qWarning() << "Index out of bounds: " << index.row(); - return QVariant(); - } + + Q_ASSERT(index.row() < m_Computers.count()); NvComputer* computer = m_Computers[index.row()]; QReadLocker lock(&computer->lock); diff --git a/app/gui/computermodel.h b/app/gui/computermodel.h index d60ddab2..340da6df 100644 --- a/app/gui/computermodel.h +++ b/app/gui/computermodel.h @@ -4,6 +4,8 @@ class ComputerModel : public QAbstractListModel { + Q_OBJECT + enum Roles { NameRole = Qt::UserRole, @@ -14,7 +16,7 @@ class ComputerModel : public QAbstractListModel }; public: - ComputerModel(QObject* object = nullptr); + explicit ComputerModel(QObject* object = nullptr); QVariant data(const QModelIndex &index, int role) const override;