mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-19 04:52:12 +01:00
+reordering of table items - experimenting with D&D
This commit is contained in:
parent
e14e0a763b
commit
c16e386e63
@ -12,13 +12,13 @@ HEADERS += notifyplugin.h \
|
||||
notifypluginoptionspage.h \
|
||||
notifyitemdelegate.h \
|
||||
notifytablemodel.h \
|
||||
NotificationItem.h
|
||||
notificationitem.h
|
||||
|
||||
SOURCES += notifyplugin.cpp \
|
||||
notifypluginoptionspage.cpp \
|
||||
notifypluginconfiguration.cpp \
|
||||
notifyitemdelegate.cpp \
|
||||
notifytablemodel.cpp
|
||||
notifytablemodel.cpp \
|
||||
notificationitem.cpp
|
||||
|
||||
OTHER_FILES += NotifyPlugin.pluginspec
|
||||
|
||||
|
@ -71,6 +71,26 @@ public:
|
||||
void setEnableSound(bool value) {enableSound = value; }
|
||||
|
||||
private:
|
||||
SoundNotifyPlugin(const SoundNotifyPlugin& rhs);
|
||||
SoundNotifyPlugin& operator= (const SoundNotifyPlugin& rhs);
|
||||
|
||||
bool playNotification(NotificationItem* notification);
|
||||
void checkNotificationRule(NotificationItem* notification, UAVObject* object);
|
||||
void readConfig_0_0_0();
|
||||
|
||||
private slots:
|
||||
void onTelemetryManagerAdded(QObject* obj);
|
||||
void onAutopilotDisconnect();
|
||||
void connectNotifications();
|
||||
void updateNotificationList(QList<NotificationItem*> list);
|
||||
void resetNotification(void);
|
||||
void appendNotification(UAVObject *object);
|
||||
void repeatTimerHandler(void);
|
||||
void expireTimerHandler(void);
|
||||
void stateChanged(Phonon::State newstate, Phonon::State oldstate);
|
||||
|
||||
private:
|
||||
|
||||
bool configured; // just for migration,delete later
|
||||
bool enableSound;
|
||||
QList< QList<Phonon::MediaSource>* > lstMediaSource;
|
||||
@ -90,21 +110,6 @@ private:
|
||||
PhononObject phonon;
|
||||
NotifyPluginOptionsPage *mop;
|
||||
TelemetryManager* telMngr;
|
||||
|
||||
bool playNotification(NotificationItem* notification);
|
||||
void checkNotificationRule(NotificationItem* notification, UAVObject* object);
|
||||
void readConfig_0_0_0();
|
||||
|
||||
private slots:
|
||||
void onTelemetryManagerAdded(QObject* obj);
|
||||
void onAutopilotDisconnect();
|
||||
void connectNotifications();
|
||||
void updateNotificationList(QList<NotificationItem*> list);
|
||||
void resetNotification(void);
|
||||
void appendNotification(UAVObject *object);
|
||||
void repeatTimerHandler(void);
|
||||
void expireTimerHandler(void);
|
||||
void stateChanged(Phonon::State newstate, Phonon::State oldstate);
|
||||
};
|
||||
|
||||
#endif // SOUNDNOTIFYPLUGIN_H
|
||||
|
@ -44,24 +44,26 @@
|
||||
#include "notifyitemdelegate.h"
|
||||
#include "notifytablemodel.h"
|
||||
|
||||
NotifyPluginOptionsPage::NotifyPluginOptionsPage(/*NotificationItem *config,*/ QObject *parent) :
|
||||
IOptionsPage(parent),
|
||||
owner((SoundNotifyPlugin*)parent),
|
||||
currentCollectionPath(""),
|
||||
privListNotifications(((SoundNotifyPlugin*)parent)->getListNotifications())
|
||||
NotifyPluginOptionsPage::NotifyPluginOptionsPage(/*NotificationItem *config,*/ QObject *parent)
|
||||
: IOptionsPage(parent)
|
||||
, objManager(*ExtensionSystem::PluginManager::instance()->getObject<UAVObjectManager>())
|
||||
, owner(qobject_cast<SoundNotifyPlugin*>(parent))
|
||||
, currentCollectionPath("")
|
||||
, privListNotifications((qobject_cast<SoundNotifyPlugin*>(parent))->getListNotifications())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NotifyPluginOptionsPage::~NotifyPluginOptionsPage()
|
||||
{
|
||||
}
|
||||
|
||||
//creates options page widget (uses the UI file)
|
||||
QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent)
|
||||
{
|
||||
|
||||
options_page = new Ui::NotifyPluginOptionsPage();
|
||||
//main widget
|
||||
QWidget *optionsPageWidget = new QWidget;
|
||||
//main layout
|
||||
options_page.reset(new Ui::NotifyPluginOptionsPage());
|
||||
//main widget
|
||||
QWidget *optionsPageWidget = new QWidget;
|
||||
//main layout
|
||||
options_page->setupUi(optionsPageWidget);
|
||||
|
||||
delegateItems.clear();
|
||||
@ -73,17 +75,11 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent)
|
||||
<< "Repeat 30 seconds"
|
||||
<< "Repeat 1 minute";
|
||||
|
||||
options_page->chkEnableSound->setChecked(owner->getEnableSound());
|
||||
options_page->SoundDirectoryPathChooser->setExpectedKind(Utils::PathChooser::Directory);
|
||||
options_page->SoundDirectoryPathChooser->setPromptDialogTitle(tr("Choose sound collection directory"));
|
||||
|
||||
|
||||
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
objManager = pm->getObject<UAVObjectManager>();
|
||||
|
||||
// Fills the combo boxes for the UAVObjects
|
||||
QList< QList<UAVDataObject*> > objList = objManager->getDataObjects();
|
||||
QList< QList<UAVDataObject*> > objList = objManager.getDataObjects();
|
||||
foreach (QList<UAVDataObject*> list, objList) {
|
||||
foreach (UAVDataObject* obj, list) {
|
||||
options_page->UAVObject->addItem(obj->getName());
|
||||
@ -92,13 +88,8 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent)
|
||||
|
||||
connect(options_page->SoundDirectoryPathChooser, SIGNAL(changed(const QString&)), this, SLOT(on_buttonSoundFolder_clicked(const QString&)));
|
||||
connect(options_page->SoundCollectionList, SIGNAL(currentIndexChanged (int)), this, SLOT(on_soundLanguage_indexChanged(int)));
|
||||
connect(options_page->buttonAdd, SIGNAL(pressed()), this, SLOT(on_buttonAddNotification_clicked()));
|
||||
connect(options_page->buttonDelete, SIGNAL(pressed()), this, SLOT(on_buttonDeleteNotification_clicked()));
|
||||
connect(options_page->buttonModify, SIGNAL(pressed()), this, SLOT(on_buttonModifyNotification_clicked()));
|
||||
connect(options_page->buttonPlayNotification, SIGNAL(clicked()), this, SLOT(on_buttonTestSoundNotification_clicked()));
|
||||
connect(options_page->chkEnableSound, SIGNAL(toggled(bool)), this, SLOT(on_chkEnableSound_toggled(bool)));
|
||||
|
||||
connect(options_page->UAVObject, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_UAVObject_indexChanged(QString)));
|
||||
|
||||
connect(this, SIGNAL(updateNotifications(QList<NotificationItem*>)),
|
||||
owner, SLOT(updateNotificationList(QList<NotificationItem*>)));
|
||||
connect(this, SIGNAL(resetNotification()),owner, SLOT(resetNotification()));
|
||||
@ -115,20 +106,52 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent)
|
||||
|
||||
updateConfigView(owner->getCurrentNotification());
|
||||
|
||||
initButtons();
|
||||
initRulesTableModel();
|
||||
initRulesTableView();
|
||||
initPhononPlayer();
|
||||
|
||||
return optionsPageWidget;
|
||||
}
|
||||
|
||||
void NotifyPluginOptionsPage::initButtons()
|
||||
{
|
||||
options_page->chkEnableSound->setChecked(owner->getEnableSound());
|
||||
connect(options_page->chkEnableSound, SIGNAL(toggled(bool)), this, SLOT(on_chkEnableSound_toggled(bool)));
|
||||
|
||||
notifyRulesModel = new NotifyTableModel(&privListNotifications);
|
||||
options_page->notifyRulesView->setModel(notifyRulesModel);
|
||||
options_page->buttonModify->setEnabled(false);
|
||||
options_page->buttonDelete->setEnabled(false);
|
||||
options_page->buttonPlayNotification->setEnabled(false);
|
||||
connect(options_page->buttonAdd, SIGNAL(pressed()), this, SLOT(on_buttonAddNotification_clicked()));
|
||||
connect(options_page->buttonDelete, SIGNAL(pressed()), this, SLOT(on_buttonDeleteNotification_clicked()));
|
||||
connect(options_page->buttonModify, SIGNAL(pressed()), this, SLOT(on_buttonModifyNotification_clicked()));
|
||||
connect(options_page->buttonPlayNotification, SIGNAL(clicked()), this, SLOT(on_buttonTestSoundNotification_clicked()));
|
||||
}
|
||||
|
||||
void NotifyPluginOptionsPage::initPhononPlayer()
|
||||
{
|
||||
notifySound = Phonon::createPlayer(Phonon::NotificationCategory);
|
||||
connect(notifySound,SIGNAL(stateChanged(Phonon::State,Phonon::State)),
|
||||
this,SLOT(changeButtonText(Phonon::State,Phonon::State)));
|
||||
connect(notifySound, SIGNAL(finished(void)), this, SLOT(onFinishedPlaying(void)));
|
||||
}
|
||||
|
||||
void NotifyPluginOptionsPage::initRulesTableModel()
|
||||
{
|
||||
notifyRulesModel.reset(new NotifyTableModel(&privListNotifications));
|
||||
notifyRulesSelection = new QItemSelectionModel(notifyRulesModel.data());
|
||||
connect(notifyRulesSelection, SIGNAL(selectionChanged ( const QItemSelection &, const QItemSelection & )),
|
||||
this, SLOT(on_tableNotification_changeSelection( const QItemSelection & , const QItemSelection & )));
|
||||
connect(this, SIGNAL(entryUpdated(int)),
|
||||
notifyRulesModel.data(), SLOT(entryUpdated(int)));
|
||||
connect(this, SIGNAL(entryAdded(int)),
|
||||
notifyRulesModel.data(), SLOT(entryAdded(int)));
|
||||
}
|
||||
|
||||
void NotifyPluginOptionsPage::initRulesTableView()
|
||||
{
|
||||
options_page->notifyRulesView->setModel(notifyRulesModel.data());
|
||||
options_page->notifyRulesView->resizeRowsToContents();
|
||||
notifyRulesSelection = new QItemSelectionModel(notifyRulesModel);
|
||||
connect(notifyRulesSelection, SIGNAL(selectionChanged ( const QItemSelection &, const QItemSelection & )),
|
||||
this, SLOT(on_tableNotification_changeSelection( const QItemSelection & , const QItemSelection & )));
|
||||
connect(this, SIGNAL(entryUpdated(int)),
|
||||
notifyRulesModel, SLOT(entryUpdated(int)));
|
||||
connect(this, SIGNAL(entryAdded(int)),
|
||||
notifyRulesModel, SLOT(entryAdded(int)));
|
||||
|
||||
|
||||
options_page->notifyRulesView->setSelectionModel(notifyRulesSelection);
|
||||
options_page->notifyRulesView->setItemDelegate(new NotifyItemDelegate(delegateItems,this));
|
||||
|
||||
@ -136,17 +159,9 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent)
|
||||
options_page->notifyRulesView->setColumnWidth(eREPEAT_VALUE,120);
|
||||
options_page->notifyRulesView->setColumnWidth(eEXPIRE_TIME,100);
|
||||
options_page->notifyRulesView->setColumnWidth(eENABLE_NOTIFICATION,60);
|
||||
|
||||
options_page->buttonModify->setEnabled(false);
|
||||
options_page->buttonDelete->setEnabled(false);
|
||||
options_page->buttonPlayNotification->setEnabled(false);
|
||||
|
||||
notifySound = Phonon::createPlayer(Phonon::NotificationCategory);
|
||||
connect(notifySound,SIGNAL(stateChanged(Phonon::State,Phonon::State)),
|
||||
this,SLOT(changeButtonText(Phonon::State,Phonon::State)));
|
||||
connect(notifySound, SIGNAL(finished(void)), this, SLOT(onFinishedPlaying(void)));
|
||||
|
||||
return optionsPageWidget;
|
||||
options_page->notifyRulesView->setDragEnabled(true);
|
||||
options_page->notifyRulesView->setAcceptDrops(true);
|
||||
options_page->notifyRulesView->setDropIndicatorShown(true);
|
||||
}
|
||||
|
||||
void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notification)
|
||||
@ -183,8 +198,6 @@ void NotifyPluginOptionsPage::finish()
|
||||
notifySound->stop();
|
||||
notifySound->clear();
|
||||
}
|
||||
if (options_page)
|
||||
delete options_page;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
@ -306,7 +319,7 @@ void NotifyPluginOptionsPage::updateConfigView(NotificationItem* notification)
|
||||
// Now load the object field values:
|
||||
options_page->UAVObjectField->clear();
|
||||
QString uavDataObject = notification->getDataObject();
|
||||
UAVDataObject* obj = dynamic_cast<UAVDataObject*>( objManager->getObject(uavDataObject/*objList.at(0).at(0)->getName()*/) );
|
||||
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objManager.getObject(uavDataObject));
|
||||
if (obj != NULL ) {
|
||||
QList<UAVObjectField*> fieldList = obj->getFields();
|
||||
foreach (UAVObjectField* field, fieldList) {
|
||||
|
@ -42,16 +42,13 @@
|
||||
#include <phonon/Path>
|
||||
#include <phonon/AudioOutput>
|
||||
#include <phonon/Global>
|
||||
#include "ui_notifypluginoptionspage.h"
|
||||
//#include "notifytablemodel.h"
|
||||
|
||||
class NotifyTableModel;
|
||||
|
||||
class NotificationItem;
|
||||
class SoundNotifyPlugin;
|
||||
|
||||
namespace Ui {
|
||||
class NotifyPluginOptionsPage;
|
||||
}
|
||||
|
||||
|
||||
using namespace Core;
|
||||
|
||||
@ -60,7 +57,7 @@ class NotifyPluginOptionsPage : public IOptionsPage
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit NotifyPluginOptionsPage(/*NotificationItem *config, */QObject *parent = 0);
|
||||
|
||||
~NotifyPluginOptionsPage();
|
||||
QString id() const { return QLatin1String("settings"); }
|
||||
QString trName() const { return tr("settings"); }
|
||||
QString category() const { return QLatin1String("Notify Plugin");}
|
||||
@ -77,7 +74,14 @@ public:
|
||||
void getOptionsPageValues(NotificationItem* notification);
|
||||
|
||||
private:
|
||||
UAVObjectManager *objManager;
|
||||
//Q_DISABLE_COPY(NotifyPluginOptionsPage)
|
||||
void initButtons();
|
||||
void initPhononPlayer();
|
||||
void initRulesTableModel();
|
||||
void initRulesTableView();
|
||||
|
||||
private:
|
||||
UAVObjectManager& objManager;
|
||||
SoundNotifyPlugin* owner;
|
||||
QStringList listDirCollections;
|
||||
QStringList listSoundFiles;
|
||||
@ -88,11 +92,11 @@ private:
|
||||
Phonon::MediaObject *notifySound;
|
||||
Phonon::AudioOutput *audioOutput;
|
||||
QStringList delegateItems;
|
||||
NotifyTableModel* notifyRulesModel;
|
||||
QScopedPointer<NotifyTableModel> notifyRulesModel;
|
||||
QItemSelectionModel *notifyRulesSelection;
|
||||
QList<NotificationItem*> privListNotifications;
|
||||
|
||||
Ui::NotifyPluginOptionsPage *options_page;
|
||||
QScopedPointer<Ui::NotifyPluginOptionsPage> options_page;
|
||||
|
||||
signals:
|
||||
void updateNotifications(QList<NotificationItem*> list);
|
||||
|
@ -109,26 +109,26 @@ QVariant NotifyTableModel::headerData(int section, Qt::Orientation orientation,
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
bool NotifyTableModel::insertRows(int position, int rows, const QModelIndex &index)
|
||||
bool NotifyTableModel::insertRows(int position, int rows, const QModelIndex& index)
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
beginInsertRows(QModelIndex(), position, position+rows-1);
|
||||
endInsertRows();
|
||||
return true;
|
||||
Q_UNUSED(index);
|
||||
beginInsertRows(QModelIndex(), position, position+rows-1);
|
||||
endInsertRows();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NotifyTableModel::removeRows(int position, int rows, const QModelIndex &index)
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
beginRemoveRows(QModelIndex(), position, position+rows-1);
|
||||
bool NotifyTableModel::removeRows(int position, int rows, const QModelIndex& index)
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
beginRemoveRows(QModelIndex(), position, position+rows-1);
|
||||
|
||||
for (int row=0; row < rows; ++row) {
|
||||
_list->removeAt(position);
|
||||
}
|
||||
for (int row=0; row < rows; ++row) {
|
||||
_list->removeAt(position);
|
||||
}
|
||||
|
||||
endRemoveRows();
|
||||
return true;
|
||||
}
|
||||
endRemoveRows();
|
||||
return true;
|
||||
}
|
||||
|
||||
void NotifyTableModel::entryUpdated(int offset)
|
||||
{
|
||||
|
@ -58,11 +58,16 @@ public:
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return Qt::ItemIsEnabled;
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsDropEnabled;
|
||||
|
||||
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
|
||||
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
|
||||
}
|
||||
|
||||
Qt::DropActions supportedDropActions() const
|
||||
{
|
||||
return Qt::MoveAction;
|
||||
}
|
||||
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role);
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user