1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-20 10:54:14 +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 {
id: flightCombo
enabled: !logManager.disableControls
property ListModel dataModel: ListModel {}
model: dataModel
Component.onCompleted: {
dataModel.append({"value": "All"})
for (var a = 0; a <= logStatus.Flight ; a++) {
dataModel.append({"value": (a + 1).toString()})
}
}
model: logManager.flightEntries
}
}
RowLayout {
@ -158,6 +151,13 @@ Rectangle {
activeFocusOnPress: true
onClicked: logManager.exportLogs()
}
Button {
id: clearButton
enabled: !logManager.disableControls
text: qsTr("Clear all logs")
activeFocusOnPress: true
onClicked: logManager.clearAllLogs()
}
Rectangle {
Layout.fillWidth: true
}

View File

@ -46,9 +46,12 @@ FlightLogManager::FlightLogManager(QObject *parent) :
m_flightLogStatus = DebugLogStatus::GetInstance(m_objectManager);
Q_ASSERT(m_flightLogStatus);
connect(m_flightLogStatus, SIGNAL(FlightChanged(quint16)), this, SLOT(updateFlightEntries(quint16)));
m_flightLogEntry = DebugLogEntry::GetInstance(m_objectManager);
Q_ASSERT(m_flightLogEntry);
updateFlightEntries(m_flightLogStatus->getFlight());
}
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(entry);
}
int countEntries(QQmlListProperty<ExtendedDebugLogEntry> *list)
int countLogEntries(QQmlListProperty<ExtendedDebugLogEntry> *list)
{
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);
}
void clearEntries(QQmlListProperty<ExtendedDebugLogEntry> *list)
void clearLogEntries(QQmlListProperty<ExtendedDebugLogEntry> *list)
{
return static_cast< QList<ExtendedDebugLogEntry *> *>(list->data)->clear();
}
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()
@ -96,17 +104,26 @@ void FlightLogManager::clearAllLogs()
m_flightLogControl->setEntry(0);
m_flightLogControl->setOperation(DebugLogControl::OPERATION_FORMATFLASH);
if (updateHelper.doObjectAndWait(m_flightLogControl, UAVTALK_TIMEOUT) == UAVObjectUpdaterHelper::SUCCESS) {
// Then delete locally
while (!m_logEntries.isEmpty()) {
delete m_logEntries.takeFirst();
}
emit logEntriesChanged();
// Then empty locally
clearLogList();
}
QApplication::restoreOverrideCursor();
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)
{
setDisableControls(true);
@ -115,11 +132,7 @@ void FlightLogManager::retrieveLogs(int flightToRetrieve)
UAVObjectUpdaterHelper updateHelper;
UAVObjectRequestHelper requestHelper;
// Get logs from flight side
while (!m_logEntries.isEmpty()) {
delete m_logEntries.takeFirst();
}
emit logEntriesChanged();
clearLogList();
// Set up what to retrieve
int startFlight = (flightToRetrieve == -1) ? 0 : flightToRetrieve;
@ -164,6 +177,23 @@ void FlightLogManager::retrieveLogs(int flightToRetrieve)
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(),
m_objectManager(0), m_object(0)
{}

View File

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