1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-21 11:54:15 +01:00

OP-1119 Added real-time updates of the flights combobox. Added some cleanup code.

This commit is contained in:
m_thread 2013-11-26 22:52:24 +01:00
parent 7bb127445d
commit 144b2c587d
3 changed files with 63 additions and 24 deletions

View File

@ -120,14 +120,7 @@ Rectangle {
ComboBox { ComboBox {
id: flightCombo id: flightCombo
enabled: !logManager.disableControls enabled: !logManager.disableControls
property ListModel dataModel: ListModel {} model: logManager.flightEntries
model: dataModel
Component.onCompleted: {
dataModel.append({"value": "All"})
for (var a = 0; a <= logStatus.Flight ; a++) {
dataModel.append({"value": (a + 1).toString()})
}
}
} }
} }
RowLayout { RowLayout {
@ -158,6 +151,13 @@ Rectangle {
activeFocusOnPress: true activeFocusOnPress: true
onClicked: logManager.exportLogs() onClicked: logManager.exportLogs()
} }
Button {
id: clearButton
enabled: !logManager.disableControls
text: qsTr("Clear all logs")
activeFocusOnPress: true
onClicked: logManager.clearAllLogs()
}
Rectangle { Rectangle {
Layout.fillWidth: true Layout.fillWidth: true
} }

View File

@ -46,9 +46,12 @@ FlightLogManager::FlightLogManager(QObject *parent) :
m_flightLogStatus = DebugLogStatus::GetInstance(m_objectManager); m_flightLogStatus = DebugLogStatus::GetInstance(m_objectManager);
Q_ASSERT(m_flightLogStatus); Q_ASSERT(m_flightLogStatus);
connect(m_flightLogStatus, SIGNAL(FlightChanged(quint16)), this, SLOT(updateFlightEntries(quint16)));
m_flightLogEntry = DebugLogEntry::GetInstance(m_objectManager); m_flightLogEntry = DebugLogEntry::GetInstance(m_objectManager);
Q_ASSERT(m_flightLogEntry); Q_ASSERT(m_flightLogEntry);
updateFlightEntries(m_flightLogStatus->getFlight());
} }
FlightLogManager::~FlightLogManager() FlightLogManager::~FlightLogManager()
@ -58,30 +61,35 @@ FlightLogManager::~FlightLogManager()
} }
} }
void addEntries(QQmlListProperty<ExtendedDebugLogEntry> *list, ExtendedDebugLogEntry *entry) void addLogEntries(QQmlListProperty<ExtendedDebugLogEntry> *list, ExtendedDebugLogEntry *entry)
{ {
Q_UNUSED(list); Q_UNUSED(list);
Q_UNUSED(entry); Q_UNUSED(entry);
} }
int countEntries(QQmlListProperty<ExtendedDebugLogEntry> *list) int countLogEntries(QQmlListProperty<ExtendedDebugLogEntry> *list)
{ {
return static_cast< QList<ExtendedDebugLogEntry *> *>(list->data)->size(); return static_cast< QList<ExtendedDebugLogEntry *> *>(list->data)->size();
} }
ExtendedDebugLogEntry *entryAt(QQmlListProperty<ExtendedDebugLogEntry> *list, int index) ExtendedDebugLogEntry *logEntryAt(QQmlListProperty<ExtendedDebugLogEntry> *list, int index)
{ {
return static_cast< QList<ExtendedDebugLogEntry *> *>(list->data)->at(index); return static_cast< QList<ExtendedDebugLogEntry *> *>(list->data)->at(index);
} }
void clearEntries(QQmlListProperty<ExtendedDebugLogEntry> *list) void clearLogEntries(QQmlListProperty<ExtendedDebugLogEntry> *list)
{ {
return static_cast< QList<ExtendedDebugLogEntry *> *>(list->data)->clear(); return static_cast< QList<ExtendedDebugLogEntry *> *>(list->data)->clear();
} }
QQmlListProperty<ExtendedDebugLogEntry> FlightLogManager::logEntries() QQmlListProperty<ExtendedDebugLogEntry> FlightLogManager::logEntries()
{ {
return QQmlListProperty<ExtendedDebugLogEntry>(this, &m_logEntries, &addEntries, &countEntries, &entryAt, &clearEntries); return QQmlListProperty<ExtendedDebugLogEntry>(this, &m_logEntries, &addLogEntries, &countLogEntries, &logEntryAt, &clearLogEntries);
}
QStringList FlightLogManager::flightEntries()
{
return m_flightEntries;
} }
void FlightLogManager::clearAllLogs() void FlightLogManager::clearAllLogs()
@ -96,17 +104,26 @@ void FlightLogManager::clearAllLogs()
m_flightLogControl->setEntry(0); m_flightLogControl->setEntry(0);
m_flightLogControl->setOperation(DebugLogControl::OPERATION_FORMATFLASH); m_flightLogControl->setOperation(DebugLogControl::OPERATION_FORMATFLASH);
if (updateHelper.doObjectAndWait(m_flightLogControl, UAVTALK_TIMEOUT) == UAVObjectUpdaterHelper::SUCCESS) { if (updateHelper.doObjectAndWait(m_flightLogControl, UAVTALK_TIMEOUT) == UAVObjectUpdaterHelper::SUCCESS) {
// Then delete locally // Then empty locally
while (!m_logEntries.isEmpty()) { clearLogList();
delete m_logEntries.takeFirst();
}
emit logEntriesChanged();
} }
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
setDisableControls(false); setDisableControls(false);
} }
void FlightLogManager::clearLogList()
{
QList<ExtendedDebugLogEntry*> tmpList(m_logEntries);
m_logEntries.clear();
emit logEntriesChanged();
while (!tmpList.isEmpty()) {
delete tmpList.takeFirst();
}
}
void FlightLogManager::retrieveLogs(int flightToRetrieve) void FlightLogManager::retrieveLogs(int flightToRetrieve)
{ {
setDisableControls(true); setDisableControls(true);
@ -115,11 +132,7 @@ void FlightLogManager::retrieveLogs(int flightToRetrieve)
UAVObjectUpdaterHelper updateHelper; UAVObjectUpdaterHelper updateHelper;
UAVObjectRequestHelper requestHelper; UAVObjectRequestHelper requestHelper;
// Get logs from flight side clearLogList();
while (!m_logEntries.isEmpty()) {
delete m_logEntries.takeFirst();
}
emit logEntriesChanged();
// Set up what to retrieve // Set up what to retrieve
int startFlight = (flightToRetrieve == -1) ? 0 : flightToRetrieve; int startFlight = (flightToRetrieve == -1) ? 0 : flightToRetrieve;
@ -164,6 +177,23 @@ void FlightLogManager::retrieveLogs(int flightToRetrieve)
void FlightLogManager::exportLogs() void FlightLogManager::exportLogs()
{} {}
void FlightLogManager::updateFlightEntries(quint16 currentFlight)
{
Q_UNUSED(currentFlight);
int flights = m_flightLogStatus->getFlight();
if (m_flightEntries.count() == 0 || (m_flightEntries.count() - 1 != flights)) {
m_flightEntries.clear();
m_flightEntries << tr("All");
for(int i = 0; i <= flights; i++) {
m_flightEntries << QString::number(i + 1);
}
emit flightEntriesChanged();
}
}
ExtendedDebugLogEntry::ExtendedDebugLogEntry() : DebugLogEntry(), ExtendedDebugLogEntry::ExtendedDebugLogEntry() : DebugLogEntry(),
m_objectManager(0), m_object(0) m_objectManager(0), m_object(0)
{} {}

View File

@ -69,6 +69,7 @@ private:
class FlightLogManager : public QObject { class FlightLogManager : public QObject {
Q_OBJECT Q_PROPERTY(DebugLogStatus *flightLogStatus READ flightLogStatus) Q_OBJECT Q_PROPERTY(DebugLogStatus *flightLogStatus READ flightLogStatus)
Q_PROPERTY(QQmlListProperty<ExtendedDebugLogEntry> logEntries READ logEntries NOTIFY logEntriesChanged) Q_PROPERTY(QQmlListProperty<ExtendedDebugLogEntry> logEntries READ logEntries NOTIFY logEntriesChanged)
Q_PROPERTY(QStringList flightEntries READ flightEntries NOTIFY flightEntriesChanged)
Q_PROPERTY(bool disableControls READ disableControls WRITE setDisableControls NOTIFY disableControlsChanged) Q_PROPERTY(bool disableControls READ disableControls WRITE setDisableControls NOTIFY disableControlsChanged)
public: public:
@ -76,6 +77,7 @@ public:
~FlightLogManager(); ~FlightLogManager();
QQmlListProperty<ExtendedDebugLogEntry> logEntries(); QQmlListProperty<ExtendedDebugLogEntry> logEntries();
QStringList flightEntries();
DebugLogStatus *flightLogStatus() const DebugLogStatus *flightLogStatus() const
{ {
@ -87,11 +89,14 @@ public:
return m_disableControls; return m_disableControls;
} }
void clearLogList();
signals: signals:
void logEntriesChanged(); void logEntriesChanged();
void flightEntriesChanged();
void disableControlsChanged(bool arg); void disableControlsChanged(bool arg);
public slots: public slots:
void clearAllLogs(); void clearAllLogs();
void retrieveLogs(int flightToRetrieve = -1); void retrieveLogs(int flightToRetrieve = -1);
@ -105,12 +110,16 @@ public slots:
} }
} }
private slots:
void updateFlightEntries(quint16 currentFlight);
private: private:
UAVObjectManager *m_objectManager; UAVObjectManager *m_objectManager;
DebugLogControl *m_flightLogControl; DebugLogControl *m_flightLogControl;
DebugLogStatus *m_flightLogStatus; DebugLogStatus *m_flightLogStatus;
DebugLogEntry *m_flightLogEntry; DebugLogEntry *m_flightLogEntry;
QList<ExtendedDebugLogEntry *> m_logEntries; QList<ExtendedDebugLogEntry *> m_logEntries;
QStringList m_flightEntries;
static const int UAVTALK_TIMEOUT = 4000; static const int UAVTALK_TIMEOUT = 4000;
bool m_disableControls; bool m_disableControls;