defuze.me  Client
listsmodel.hpp
00001 /**************************************************************************
00002 ** defuze.me Epitech Innovative Project
00003 **
00004 ** Copyright 2010-2012
00005 **   Athena Calmettes - Jocelyn De La Rosa - Francois Gaillard
00006 **   Adrien Jarthon - Alexandre Moore - Luc Peres - Arnaud Sellier
00007 **
00008 ** All rights reserved.
00009 **************************************************************************/
00010 
00011 #ifndef LISTSMODEL_HPP
00012 #define LISTSMODEL_HPP
00013 
00014 #include "editabletreemodel.hpp"
00015 #include "listsitem.hpp"
00016 #include <QHash>
00017 #include <QItemSelectionModel>
00018 
00019 namespace Lists
00020 {
00021     class ListsPlugin;
00022 
00023     class ListsModel : public EditableTreeModel
00024     {
00025         Q_OBJECT
00026     public:
00027         enum DropAction {
00028             INVALID_DROP_ACTION,
00029             ADD_TO_NORMAL_PLAYLIST,
00030             ADD_TO_DYNAMIC_PLAYLIST,
00031             CREATE_NORMAL_PLAYLIST,
00032             CREATE_DYNAMIC_PLAYLIST
00033         };
00034 
00035         ListsModel(ListsPlugin *lists);
00036         ~ListsModel();
00037         void setupModelData();
00038         ListsItem *getRootItem() const;
00039         QStringList getDropTypesForItem(ListsItem *item) const;
00040         DropAction getDropActionsForItem(ListsItem *item, const QString &mimeType = "default") const;
00041 
00042         bool insertRows(int position, int rows, const QModelIndex &parent);
00043         bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);
00044         Qt::ItemFlags flags(const QModelIndex &index) const;
00045         QVariant data(const QModelIndex &index, int role) const;
00046         ListsItem *getItem(const QModelIndex &index) const;
00047 
00048         ListsItem *normalItem;
00049         ListsItem *dynamicItem;
00050         QModelIndex lastDropIndex;
00051 
00052     public slots:
00053         void dataHaveChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight);
00054         void dataDeleted();
00055 
00056     signals:
00057         void playlistContentChanged(int playlistId);
00058         void playlistNameChanged(int playlistId, QString newName);
00059         void playlistRemoved(int playlistId);
00060 
00061     private:
00062         ListsItem *insertCategoryItem(const QString &title, ListsItem::SubKind subKind, int position = 0);
00063         ListsItem *insertAddItem(const QString &title, ListsItem::SubKind subKind);
00064         ListsItem *insertDynamicList(const QMimeData *data, ListsItem *parentItem);
00065         ListsItem *insertNormalList(const QMimeData *data, ListsItem *parentItem);
00066 
00067         ListsItem *insertIntroItem(ListsItem *parentItem);
00068         ListsItem *insertSeparatorItem(ListsItem::SubKind subKind, ListsItem *parentItem);
00069         void insertParametersInDynamicList(const QMimeData *data, ListsItem *parentItem);
00070         void insertParametersInNormalList(const QMimeData *data, ListsItem *parentItem);
00071         void removeList(const QModelIndex &listIndex);
00072         void removeSeparatorFromList(const QModelIndex &separatorIndex);
00073         void removeParameterFromList(const QModelIndex &parameterIndex);
00074 
00075         void updateDBFromTree(ListsItem *list) const;
00076         void updateTreeFromDB();
00077         bool hasAction(ListsItem *item, const QStringList &formats, DropAction action);
00078 
00079         ListsPlugin *lists;
00080         QHash<ListsItem*, QStringList> dropTypesForItem;
00081         QHash<ListsItem*, QHash<QString, DropAction> > dropActionsForItem;
00082     };
00083 
00084 }
00085 
00086 #endif // LISTSMODEL_HPP