1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-02 10:24:11 +01:00

Changed conditions base on strings to enums.

This commit is contained in:
zedamota 2011-12-06 09:59:28 +00:00
parent 78e25b1b8c
commit b45044b8c3
6 changed files with 74 additions and 106 deletions

View File

@ -49,7 +49,10 @@ class NotificationItem : public QObject
public:
enum { eDefaultTimeout = 15 }; // in sec
enum {equal,bigger,smaller,inrange};
enum {never,beforeFirst,beforeSecond,afterSecond};
enum {repeatOncePerUpdate,repeatOnce,repeatInstantly,repeat10seconds,
repeat30seconds,repeat1minute};
explicit NotificationItem(QObject *parent = 0);
void copyTo(NotificationItem*) const;
@ -64,8 +67,8 @@ public:
int getCondition() const { return _condition; }
void setCondition(int value) { _condition = value; }
QString getSayOrder() const { return _sayOrder; }
void setSayOrder(QString text) { _sayOrder = text; }
int getSayOrder() const { return _sayOrder; }
void setSayOrder(int text) { _sayOrder = text; }
QVariant singleValue() const { return _singleValue; }
void setSingleValue(QVariant value) { _singleValue = value; }
@ -88,8 +91,8 @@ public:
QStringList getMessageSequence() const { return _messageSequence; }
void setMessageSequence(QStringList sequence) { _messageSequence = sequence; }
QString retryString() const { return _repeatString; }
void setRetryString(QString value) { _repeatString = value; }
int retryValue() const { return _repeatValue; }
void setRetryValue(int value) { _repeatValue = value; }
int lifetime() const { return _expireTimeout; }
void setLifetime(int value) { _expireTimeout = value; }
@ -189,7 +192,7 @@ private:
QString _sound3;
//! order in what sounds 1-3 will be played
QString _sayOrder;
int _sayOrder;
//! one-side range, value(numeric or ENUM type) maybe lower, greater or in range
QVariant _singleValue;
@ -199,7 +202,7 @@ private:
double _valueRange2;
//! how often or what periodicaly notification should be played
QString _repeatString;
int _repeatValue;
//! time after event occured till notification became invalid
//! and will be removed from list

View File

@ -40,18 +40,7 @@
#include "notifylogging.h"
static const QString cStrNever("Never");
static const QString cStrBefore1st("Before first");
static const QString cStrBefore2nd("Before second");
static const QString cStrAfter2nd("After second");
static const QString cStrRetryOncePUpdate("Repeat Once per update");
static const QString cStrRetryOnce("Repeat Once");
static const QString cStrRetryInstantly("Repeat Instantly");
static const QString cStrRetry10sec("Repeat 10 seconds");
static const QString cStrRetry30sec("Repeat 30 seconds");
static const QString cStrRetry1min("Repeat 1 minute");
QStringList NotificationItem::sayOrderValues;
@ -73,26 +62,27 @@ NotificationItem::NotificationItem(QObject *parent)
, _sound1("")
, _sound2("")
, _sound3("")
, _sayOrder(cStrNever)
, _sayOrder(never)
, _singleValue(0)
, _valueRange2(0)
, _repeatString(cStrRetryInstantly)
, _repeatValue(repeatInstantly)
, _expireTimeout(eDefaultTimeout)
, _mute(false)
{
NotificationItem::sayOrderValues.clear();
NotificationItem::sayOrderValues.append(cStrNever);
NotificationItem::sayOrderValues.append(cStrBefore1st);
NotificationItem::sayOrderValues.append(cStrBefore2nd);
NotificationItem::sayOrderValues.append(cStrAfter2nd);
NotificationItem::sayOrderValues.insert(never,QString(tr("Never")));
NotificationItem::sayOrderValues.insert(beforeFirst,QString(tr("Before first")));
NotificationItem::sayOrderValues.insert(beforeSecond,QString(tr("Before second")));
NotificationItem::sayOrderValues.insert(afterSecond,QString(tr("After second")));
NotificationItem::retryValues.clear();
NotificationItem::retryValues.append(cStrRetryOnce);
NotificationItem::retryValues.append(cStrRetryOncePUpdate);
NotificationItem::retryValues.append(cStrRetryInstantly);
NotificationItem::retryValues.append(cStrRetry10sec);
NotificationItem::retryValues.append(cStrRetry30sec);
NotificationItem::retryValues.append(cStrRetry1min);
NotificationItem::retryValues.insert(repeatOnce,QString(tr("Repeat Once")));
NotificationItem::retryValues.insert(repeatOncePerUpdate,QString(tr("Repeat Once per update")));
NotificationItem::retryValues.insert(repeatInstantly,QString(tr("Repeat Instantly")));
NotificationItem::retryValues.insert(repeat10seconds,QString(tr("Repeat 10 seconds")));
NotificationItem::retryValues.insert(repeat30seconds,QString(tr("Repeat 30 seconds")));
NotificationItem::retryValues.insert(repeat1minute,QString(tr("Repeat 1 minute")));
}
@ -112,7 +102,7 @@ void NotificationItem::copyTo(NotificationItem* that) const
that->_sayOrder = _sayOrder;
that->_singleValue = _singleValue;
that->_valueRange2 = _valueRange2;
that->_repeatString = _repeatString;
that->_repeatValue = _repeatValue;
that->_expireTimeout = _expireTimeout;
that->_mute = _mute;
@ -132,7 +122,7 @@ void NotificationItem::saveState(QSettings* settings) const
settings->setValue(QLatin1String("Sound2"), getSound2());
settings->setValue(QLatin1String("Sound3"), getSound3());
settings->setValue(QLatin1String("SayOrder"), getSayOrder());
settings->setValue(QLatin1String("Repeat"), retryString());
settings->setValue(QLatin1String("Repeat"), retryValue());
settings->setValue(QLatin1String("ExpireTimeout"), lifetime());
settings->setValue(QLatin1String("Mute"), mute());
}
@ -148,11 +138,11 @@ void NotificationItem::restoreState(QSettings* settings)
setSound1(settings->value(QLatin1String("Sound1"), tr("")).toString());
setSound2(settings->value(QLatin1String("Sound2"), tr("")).toString());
setSound3(settings->value(QLatin1String("Sound3"), tr("")).toString());
setSayOrder(settings->value(QLatin1String("SayOrder"), tr("")).toString());
setSayOrder(settings->value(QLatin1String("SayOrder"), tr("")).toInt());
QVariant value = settings->value(QLatin1String("Value1"), tr(""));
setSingleValue(value);
setValueRange2(settings->value(QLatin1String("Value2"), tr("")).toDouble());
setRetryString(settings->value(QLatin1String("Repeat"), tr("")).toString());
setRetryValue(settings->value(QLatin1String("Repeat"), tr("")).toInt());
setLifetime(settings->value(QLatin1String("ExpireTimeout"), tr("")).toInt());
setMute(settings->value(QLatin1String("Mute"), tr("")).toInt());
}
@ -171,7 +161,7 @@ void NotificationItem::serialize(QDataStream& stream)
stream << this->_sayOrder;
stream << this->_singleValue;
stream << this->_valueRange2;
stream << this->_repeatString;
stream << this->_repeatValue;
stream << this->_expireTimeout;
stream << this->_mute;
}
@ -189,7 +179,7 @@ void NotificationItem::deserialize(QDataStream& stream)
stream >> this->_sayOrder;
stream >> this->_singleValue;
stream >> this->_valueRange2;
stream >> this->_repeatString;
stream >> this->_repeatValue;
stream >> this->_expireTimeout;
stream >> this->_mute;
}
@ -356,7 +346,7 @@ QString NotificationItem::toString()
UAVObjectField* field = getUAVObjectField();
QString value = stringFromValue(singleValue(), field);
int pos = getValuePosition(getSayOrder().trimmed());
int pos = getSayOrder()-1;
QStringList lst;
lst.append(getSoundCaption(getSound1()));
lst.append(getSoundCaption(getSound2()));
@ -391,7 +381,7 @@ QStringList& NotificationItem::toSoundList()
// generate queue of sound files to play
_messageSequence.clear();
int pos = getValuePosition(getSayOrder().trimmed());
int pos = getSayOrder()-1;
QStringList lst;
if(!getSound1().isEmpty())
lst.append(getSound1());

View File

@ -246,8 +246,8 @@ void SoundNotifyPlugin::on_arrived_Notification(UAVObject *object)
// notification can be accepted again;
// 2. Once time notifications, they removed immediately after first playing;
// 3. Instant notifications(played one by one without interval);
if (ntf->retryString() != "Repeat Instantly" && ntf->retryString() != "Repeat Once per update" &&
ntf->retryString() != "Repeat Once" && ntf->_isPlayed)
if (ntf->retryValue() != NotificationItem::repeatInstantly && ntf->retryValue() != NotificationItem::repeatOncePerUpdate &&
ntf->retryValue() != NotificationItem::repeatOnce && ntf->_isPlayed)
continue;
qNotifyDebug() << QString("new notification: | %1 | %2 | val1: %3 | val2: %4")
@ -363,7 +363,7 @@ bool checkRange(QString fieldValue, QString enumValue, QStringList values, int d
bool ret = false;
switch(direction)
{
case NotificationItem::equal:
case NotifyPluginOptionsPage::equal:
ret = !QString::compare(enumValue, fieldValue, Qt::CaseInsensitive) ? true : false;
break;
@ -377,18 +377,18 @@ bool checkRange(QString fieldValue, QString enumValue, QStringList values, int d
bool checkRange(double fieldValue, double min, double max, int direction)
{
bool ret = false;
Q_ASSERT(min < max);
//Q_ASSERT(min < max);
switch(direction)
{
case NotificationItem::equal:
case NotifyPluginOptionsPage::equal:
ret = (fieldValue == min);
break;
case NotificationItem::bigger:
case NotifyPluginOptionsPage::bigger:
ret = (fieldValue > min);
break;
case NotificationItem::smaller:
case NotifyPluginOptionsPage::smaller:
ret = (fieldValue < min);
break;
@ -445,7 +445,7 @@ void SoundNotifyPlugin::checkNotificationRule(NotificationItem* notification, UA
notification->setCurrentUpdatePlayed(false);
return;
}
if(notification->retryString() == "Repeat Once per update" && notification->getCurrentUpdatePlayed())
if(notification->retryValue() == NotificationItem::repeatOncePerUpdate && notification->getCurrentUpdatePlayed())
return;
volatile QMutexLocker lock(&_mutex);
@ -484,17 +484,17 @@ bool SoundNotifyPlugin::playNotification(NotificationItem* notification)
_nowPlayingNotification = notification;
notification->stopExpireTimer();
if (notification->retryString() == "Repeat Once") {
if (notification->retryValue() == NotificationItem::repeatOnce) {
_toRemoveNotifications.append(_notificationList.takeAt(_notificationList.indexOf(notification)));
}
else if(notification->retryString() == "Repeat Once per update")
else if(notification->retryValue() == NotificationItem::repeatOncePerUpdate)
notification->setCurrentUpdatePlayed(true);
else {
if (notification->retryString() != "Repeat Instantly") {
if (notification->retryValue() != NotificationItem::repeatInstantly) {
QRegExp rxlen("(\\d+)");
QString value;
int timer_value;
int pos = rxlen.indexIn(notification->retryString());
int timer_value=0;
int pos = rxlen.indexIn(NotificationItem::retryValues.at(notification->retryValue()));
if (pos > -1) {
value = rxlen.cap(1); // "189"

View File

@ -47,11 +47,7 @@
#include "notifytablemodel.h"
#include "notifylogging.h"
static const char* cStrEqualTo = "Equal to";
static const char* cStrLargeThan = "Large than";
static const char* cStrLowerThan = "Lower than";
static const char* cStrInRange = "In range";
QStringList NotifyPluginOptionsPage::conditionValues;
NotifyPluginOptionsPage::NotifyPluginOptionsPage(QObject *parent)
: IOptionsPage(parent)
@ -63,7 +59,13 @@ NotifyPluginOptionsPage::NotifyPluginOptionsPage(QObject *parent)
, _sayOrder(NULL)
, _form(NULL)
, _selectedNotification(NULL)
{}
{
NotifyPluginOptionsPage::conditionValues.insert(equal,tr("Equal to"));
NotifyPluginOptionsPage::conditionValues.insert(bigger,tr("Large than"));
NotifyPluginOptionsPage::conditionValues.insert(smaller,tr("Lower than"));
NotifyPluginOptionsPage::conditionValues.insert(inrange,tr("In range"));
}
NotifyPluginOptionsPage::~NotifyPluginOptionsPage()
{}
@ -246,41 +248,19 @@ void NotifyPluginOptionsPage::addDynamicField(UAVObjectField* objField)
}
disconnect(_dynamicFieldCondition, SIGNAL(currentIndexChanged(QString)),
this, SLOT(on_changedIndex_rangeValue(QString)));
this, SLOT(on_changedIndex_rangeValue(QString)));
_dynamicFieldCondition->clear();
QStringList rangeValues;
QList<int> rangeCode;
_dynamicFieldCondition->addItems(NotifyPluginOptionsPage::conditionValues);
if (UAVObjectField::ENUM == objField->getType()) {
rangeValues << cStrEqualTo << cStrInRange;
rangeCode<<NotificationItem::equal<<NotificationItem::inrange;
int x=0;
int selected=0;
foreach (QString value, rangeValues) {
_dynamicFieldCondition->addItem(value,rangeCode[x]);
if(_selectedNotification->getCondition()==rangeCode[x])
selected=x;
++x;
}
qNotifyDebug()<<"setcurrentindex"<<x;
_dynamicFieldCondition->setCurrentIndex(selected);
} else {
rangeValues << cStrEqualTo << cStrLargeThan << cStrLowerThan << cStrInRange;
rangeCode<<NotificationItem::equal<<NotificationItem::bigger<<NotificationItem::smaller<<NotificationItem::inrange;
int x=0;
int selected=0;
foreach (QString value, rangeValues) {
_dynamicFieldCondition->addItem(value,rangeCode[x]);
if(_selectedNotification->getCondition()==rangeCode[x])
selected=x;
++x;
}
qNotifyDebug()<<"setcurrentindex"<<x;
_dynamicFieldCondition->setCurrentIndex(selected);
connect(_dynamicFieldCondition, SIGNAL(currentIndexChanged(QString)),
this, SLOT(on_changedIndex_rangeValue(QString)));
_dynamicFieldCondition->removeItem(smaller);
_dynamicFieldCondition->removeItem(bigger);
}
_dynamicFieldCondition->setCurrentIndex(_dynamicFieldCondition->findText(NotifyPluginOptionsPage::conditionValues.at(_selectedNotification->getCondition())));
connect(_dynamicFieldCondition, SIGNAL(currentIndexChanged(QString)),
this, SLOT(on_changedIndex_rangeValue(QString)));
addDynamicFieldWidget(objField);
}
@ -315,7 +295,7 @@ void NotifyPluginOptionsPage::addDynamicFieldWidget(UAVObjectField* objField)
default:
Q_ASSERT(_dynamicFieldCondition);
if (_dynamicFieldCondition->currentText() == cStrInRange) {
if (NotifyPluginOptionsPage::conditionValues.indexOf(_dynamicFieldCondition->currentText()) == NotifyPluginOptionsPage::inrange) {
_dynamicFieldWidget = new QLineEdit(_form);
(static_cast<QLineEdit*>(_dynamicFieldWidget))->setInputMask("#999.99 : #999.99;");
@ -369,9 +349,8 @@ void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notificatio
notification->setSound1(_optionsPage->Sound1->currentText());
notification->setSound2(_optionsPage->Sound2->currentText());
notification->setSound3(_optionsPage->Sound3->currentText());
notification->setSayOrder(_sayOrder->currentText());
notification->setCondition(_dynamicFieldCondition->itemData(_dynamicFieldCondition->currentIndex()).toInt());
qNotifyDebug()<<"getOptionsPageValues SETRANGE"<<_dynamicFieldCondition->currentIndex()<<_dynamicFieldCondition->itemData(_dynamicFieldCondition->currentIndex()).toInt();
notification->setSayOrder(_sayOrder->currentIndex());
notification->setCondition(NotifyPluginOptionsPage::conditionValues.indexOf(_dynamicFieldCondition->currentText()));
if (QDoubleSpinBox* spinValue = dynamic_cast<QDoubleSpinBox*>(_dynamicFieldWidget))
notification->setSingleValue(spinValue->value());
else {
@ -455,15 +434,10 @@ void NotifyPluginOptionsPage::updateConfigView(NotificationItem* notification)
_optionsPage->SoundCollectionList->setCurrentIndex(_optionsPage->SoundCollectionList->findText("default"));
_optionsPage->Sound3->setCurrentIndex(_optionsPage->Sound3->findText(notification->getSound3()));
}
for(int x=0;x<_dynamicFieldCondition->count();++x)
{
if (_dynamicFieldCondition->itemData(x)==notification->getCondition()) {
_dynamicFieldCondition->setCurrentIndex(x);
}
}
if (-1 != _sayOrder->findText(notification->getSayOrder())) {
_sayOrder->setCurrentIndex(_sayOrder->findText(notification->getSayOrder()));
}
_dynamicFieldCondition->setCurrentIndex(_dynamicFieldCondition->findText(NotifyPluginOptionsPage::conditionValues.at(notification->getCondition())));
_sayOrder->setCurrentIndex(notification->getSayOrder());
setDynamicFieldValue(notification);
@ -613,7 +587,7 @@ void NotifyPluginOptionsPage::on_clicked_buttonAddNotification()
delete notification;
return;
} else {
notification->setSayOrder(_sayOrder->currentText());
notification->setSayOrder(_sayOrder->currentIndex());
}
_notifyRulesModel->entryAdded(notification);
@ -638,7 +612,7 @@ void NotifyPluginOptionsPage::on_clicked_buttonModifyNotification()
{
NotificationItem* notification = new NotificationItem;
getOptionsPageValues(notification);
notification->setRetryString(_privListNotifications.at(_notifyRulesSelection->currentIndex().row())->retryString());
notification->setRetryValue(_privListNotifications.at(_notifyRulesSelection->currentIndex().row())->retryValue());
notification->setLifetime(_privListNotifications.at(_notifyRulesSelection->currentIndex().row())->lifetime());
notification->setMute(_privListNotifications.at(_notifyRulesSelection->currentIndex().row())->mute());

View File

@ -60,7 +60,7 @@ class NotifyPluginOptionsPage : public IOptionsPage
Q_OBJECT
public:
enum {equal,bigger,smaller,inrange};
explicit NotifyPluginOptionsPage(QObject *parent = 0);
~NotifyPluginOptionsPage();
QString id() const { return QLatin1String("settings"); }
@ -72,6 +72,7 @@ public:
void apply();
void finish();
void restoreFromSettings();
static QStringList conditionValues;
signals:
void updateNotifications(QList<NotificationItem*> list);

View File

@ -52,7 +52,7 @@ bool NotifyTableModel::setData(const QModelIndex &index,
}
if (index.isValid() && role == Qt::EditRole) {
if (eRepeatValue == index.column())
_list.at(index.row())->setRetryString(value.toString());
_list.at(index.row())->setRetryValue(NotificationItem::retryValues.indexOf(value.toString()));
else {
if (eExpireTimer == index.column())
_list.at(index.row())->setLifetime(value.toInt());
@ -85,7 +85,7 @@ QVariant NotifyTableModel::data(const QModelIndex &index, int role) const
return _list.at(index.row())->toString();
case eRepeatValue:
return _list.at(index.row())->retryString();
return (NotificationItem::retryValues.at(_list.at(index.row())->retryValue()));
case eExpireTimer:
return _list.at(index.row())->lifetime();