1
0
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:
Nickolay 2011-09-16 02:24:35 +03:00
parent e14e0a763b
commit c16e386e63
7 changed files with 120 additions and 93 deletions

View File

@ -12,13 +12,13 @@ HEADERS += notifyplugin.h \
notifypluginoptionspage.h \ notifypluginoptionspage.h \
notifyitemdelegate.h \ notifyitemdelegate.h \
notifytablemodel.h \ notifytablemodel.h \
NotificationItem.h notificationitem.h
SOURCES += notifyplugin.cpp \ SOURCES += notifyplugin.cpp \
notifypluginoptionspage.cpp \ notifypluginoptionspage.cpp \
notifypluginconfiguration.cpp \
notifyitemdelegate.cpp \ notifyitemdelegate.cpp \
notifytablemodel.cpp notifytablemodel.cpp \
notificationitem.cpp
OTHER_FILES += NotifyPlugin.pluginspec OTHER_FILES += NotifyPlugin.pluginspec

View File

@ -71,6 +71,26 @@ public:
void setEnableSound(bool value) {enableSound = value; } void setEnableSound(bool value) {enableSound = value; }
private: 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 configured; // just for migration,delete later
bool enableSound; bool enableSound;
QList< QList<Phonon::MediaSource>* > lstMediaSource; QList< QList<Phonon::MediaSource>* > lstMediaSource;
@ -90,21 +110,6 @@ private:
PhononObject phonon; PhononObject phonon;
NotifyPluginOptionsPage *mop; NotifyPluginOptionsPage *mop;
TelemetryManager* telMngr; 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 #endif // SOUNDNOTIFYPLUGIN_H

View File

@ -44,24 +44,26 @@
#include "notifyitemdelegate.h" #include "notifyitemdelegate.h"
#include "notifytablemodel.h" #include "notifytablemodel.h"
NotifyPluginOptionsPage::NotifyPluginOptionsPage(/*NotificationItem *config,*/ QObject *parent) : NotifyPluginOptionsPage::NotifyPluginOptionsPage(/*NotificationItem *config,*/ QObject *parent)
IOptionsPage(parent), : IOptionsPage(parent)
owner((SoundNotifyPlugin*)parent), , objManager(*ExtensionSystem::PluginManager::instance()->getObject<UAVObjectManager>())
currentCollectionPath(""), , owner(qobject_cast<SoundNotifyPlugin*>(parent))
privListNotifications(((SoundNotifyPlugin*)parent)->getListNotifications()) , currentCollectionPath("")
, privListNotifications((qobject_cast<SoundNotifyPlugin*>(parent))->getListNotifications())
{ {
} }
NotifyPluginOptionsPage::~NotifyPluginOptionsPage()
{
}
//creates options page widget (uses the UI file) //creates options page widget (uses the UI file)
QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent) QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent)
{ {
options_page.reset(new Ui::NotifyPluginOptionsPage());
options_page = new Ui::NotifyPluginOptionsPage(); //main widget
//main widget QWidget *optionsPageWidget = new QWidget;
QWidget *optionsPageWidget = new QWidget; //main layout
//main layout
options_page->setupUi(optionsPageWidget); options_page->setupUi(optionsPageWidget);
delegateItems.clear(); delegateItems.clear();
@ -73,17 +75,11 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent)
<< "Repeat 30 seconds" << "Repeat 30 seconds"
<< "Repeat 1 minute"; << "Repeat 1 minute";
options_page->chkEnableSound->setChecked(owner->getEnableSound());
options_page->SoundDirectoryPathChooser->setExpectedKind(Utils::PathChooser::Directory); options_page->SoundDirectoryPathChooser->setExpectedKind(Utils::PathChooser::Directory);
options_page->SoundDirectoryPathChooser->setPromptDialogTitle(tr("Choose sound collection 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 // 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 (QList<UAVDataObject*> list, objList) {
foreach (UAVDataObject* obj, list) { foreach (UAVDataObject* obj, list) {
options_page->UAVObject->addItem(obj->getName()); 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->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->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(options_page->UAVObject, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_UAVObject_indexChanged(QString)));
connect(this, SIGNAL(updateNotifications(QList<NotificationItem*>)), connect(this, SIGNAL(updateNotifications(QList<NotificationItem*>)),
owner, SLOT(updateNotificationList(QList<NotificationItem*>))); owner, SLOT(updateNotificationList(QList<NotificationItem*>)));
connect(this, SIGNAL(resetNotification()),owner, SLOT(resetNotification())); connect(this, SIGNAL(resetNotification()),owner, SLOT(resetNotification()));
@ -115,20 +106,52 @@ QWidget *NotifyPluginOptionsPage::createPage(QWidget *parent)
updateConfigView(owner->getCurrentNotification()); updateConfigView(owner->getCurrentNotification());
initButtons();
initRulesTableModel();
initRulesTableView();
initPhononPlayer();
return optionsPageWidget;
}
void NotifyPluginOptionsPage::initButtons()
{
options_page->chkEnableSound->setChecked(owner->getEnableSound()); 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->buttonModify->setEnabled(false);
options_page->notifyRulesView->setModel(notifyRulesModel); 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(); 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->setSelectionModel(notifyRulesSelection);
options_page->notifyRulesView->setItemDelegate(new NotifyItemDelegate(delegateItems,this)); 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(eREPEAT_VALUE,120);
options_page->notifyRulesView->setColumnWidth(eEXPIRE_TIME,100); options_page->notifyRulesView->setColumnWidth(eEXPIRE_TIME,100);
options_page->notifyRulesView->setColumnWidth(eENABLE_NOTIFICATION,60); options_page->notifyRulesView->setColumnWidth(eENABLE_NOTIFICATION,60);
options_page->notifyRulesView->setDragEnabled(true);
options_page->buttonModify->setEnabled(false); options_page->notifyRulesView->setAcceptDrops(true);
options_page->buttonDelete->setEnabled(false); options_page->notifyRulesView->setDropIndicatorShown(true);
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;
} }
void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notification) void NotifyPluginOptionsPage::getOptionsPageValues(NotificationItem* notification)
@ -183,8 +198,6 @@ void NotifyPluginOptionsPage::finish()
notifySound->stop(); notifySound->stop();
notifySound->clear(); notifySound->clear();
} }
if (options_page)
delete options_page;
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -306,7 +319,7 @@ void NotifyPluginOptionsPage::updateConfigView(NotificationItem* notification)
// Now load the object field values: // Now load the object field values:
options_page->UAVObjectField->clear(); options_page->UAVObjectField->clear();
QString uavDataObject = notification->getDataObject(); 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 ) { if (obj != NULL ) {
QList<UAVObjectField*> fieldList = obj->getFields(); QList<UAVObjectField*> fieldList = obj->getFields();
foreach (UAVObjectField* field, fieldList) { foreach (UAVObjectField* field, fieldList) {

View File

@ -42,16 +42,13 @@
#include <phonon/Path> #include <phonon/Path>
#include <phonon/AudioOutput> #include <phonon/AudioOutput>
#include <phonon/Global> #include <phonon/Global>
#include "ui_notifypluginoptionspage.h"
//#include "notifytablemodel.h"
class NotifyTableModel; class NotifyTableModel;
class NotificationItem; class NotificationItem;
class SoundNotifyPlugin; class SoundNotifyPlugin;
namespace Ui {
class NotifyPluginOptionsPage;
}
using namespace Core; using namespace Core;
@ -60,7 +57,7 @@ class NotifyPluginOptionsPage : public IOptionsPage
Q_OBJECT Q_OBJECT
public: public:
explicit NotifyPluginOptionsPage(/*NotificationItem *config, */QObject *parent = 0); explicit NotifyPluginOptionsPage(/*NotificationItem *config, */QObject *parent = 0);
~NotifyPluginOptionsPage();
QString id() const { return QLatin1String("settings"); } QString id() const { return QLatin1String("settings"); }
QString trName() const { return tr("settings"); } QString trName() const { return tr("settings"); }
QString category() const { return QLatin1String("Notify Plugin");} QString category() const { return QLatin1String("Notify Plugin");}
@ -77,7 +74,14 @@ public:
void getOptionsPageValues(NotificationItem* notification); void getOptionsPageValues(NotificationItem* notification);
private: private:
UAVObjectManager *objManager; //Q_DISABLE_COPY(NotifyPluginOptionsPage)
void initButtons();
void initPhononPlayer();
void initRulesTableModel();
void initRulesTableView();
private:
UAVObjectManager& objManager;
SoundNotifyPlugin* owner; SoundNotifyPlugin* owner;
QStringList listDirCollections; QStringList listDirCollections;
QStringList listSoundFiles; QStringList listSoundFiles;
@ -88,11 +92,11 @@ private:
Phonon::MediaObject *notifySound; Phonon::MediaObject *notifySound;
Phonon::AudioOutput *audioOutput; Phonon::AudioOutput *audioOutput;
QStringList delegateItems; QStringList delegateItems;
NotifyTableModel* notifyRulesModel; QScopedPointer<NotifyTableModel> notifyRulesModel;
QItemSelectionModel *notifyRulesSelection; QItemSelectionModel *notifyRulesSelection;
QList<NotificationItem*> privListNotifications; QList<NotificationItem*> privListNotifications;
Ui::NotifyPluginOptionsPage *options_page; QScopedPointer<Ui::NotifyPluginOptionsPage> options_page;
signals: signals:
void updateNotifications(QList<NotificationItem*> list); void updateNotifications(QList<NotificationItem*> list);

View File

@ -109,26 +109,26 @@ QVariant NotifyTableModel::headerData(int section, Qt::Orientation orientation,
return QVariant(); 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); Q_UNUSED(index);
beginInsertRows(QModelIndex(), position, position+rows-1); beginInsertRows(QModelIndex(), position, position+rows-1);
endInsertRows(); endInsertRows();
return true; return true;
} }
bool NotifyTableModel::removeRows(int position, int rows, const QModelIndex &index) bool NotifyTableModel::removeRows(int position, int rows, const QModelIndex& index)
{ {
Q_UNUSED(index); Q_UNUSED(index);
beginRemoveRows(QModelIndex(), position, position+rows-1); beginRemoveRows(QModelIndex(), position, position+rows-1);
for (int row=0; row < rows; ++row) { for (int row=0; row < rows; ++row) {
_list->removeAt(position); _list->removeAt(position);
} }
endRemoveRows(); endRemoveRows();
return true; return true;
} }
void NotifyTableModel::entryUpdated(int offset) void NotifyTableModel::entryUpdated(int offset)
{ {

View File

@ -58,11 +58,16 @@ public:
Qt::ItemFlags flags(const QModelIndex &index) const Qt::ItemFlags flags(const QModelIndex &index) const
{ {
if (!index.isValid()) 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); bool setData(const QModelIndex &index, const QVariant &value, int role);
QVariant data(const QModelIndex &index, int role) const; QVariant data(const QModelIndex &index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const;