C:/Projets/hexamonkey/gui/tree/treemodel.h
Go to the documentation of this file.
00001 //This file is part of the HexaMonkey project, a multimedia analyser
00002 //Copyright (C) 2013  Sevan Drapeau-Martin, Nicolas Fleury
00003 
00004 //This program is free software; you can redistribute it and/or
00005 //modify it under the terms of the GNU General Public License
00006 //as published by the Free Software Foundation; either version 2
00007 //of the License, or (at your option) any later version.
00008 
00009 //This program is distributed in the hope that it will be useful,
00010 //but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //GNU General Public License for more details.
00013 
00014 //You should have received a copy of the GNU General Public License
00015 //along with this program; if not, write to the Free Software
00016 //Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00017 
00018 #ifndef DATATREEMODEL_H
00019 #define DATATREEMODEL_H
00020 
00021 #include <QAbstractItemModel>
00022 #include <QModelIndex>
00023 #include <QVariant>
00024 #include <QMap>
00025 
00026 #include "core/object.h"
00027 #include "core/modules/hmc/hmcmodule.h"
00028 #include "gui/tree/treefileitem.h"
00029 #include "gui/tree/treeview.h"
00030 
00031 class TreeItem;
00032 class ProgramLoader;
00033 
00047 class TreeModel : public QAbstractItemModel
00048 {
00049     Q_OBJECT
00050 public:
00051     TreeModel(const QString &data, const ProgramLoader& programLoader, TreeView* view, QObject *parent = 0);
00052 
00053     TreeItem& item(const QModelIndex &index) const;
00054     TreeItem* currentTreeFileItem();
00055     TreeView* view;
00056 
00057     virtual QVariant data(const QModelIndex &index, int role) const final;
00058     virtual Qt::ItemFlags flags(const QModelIndex &index) const final;
00059     virtual QVariant headerData(int section, Qt::Orientation orientation,
00060                                 int role = Qt::DisplayRole) const final;
00061     virtual QModelIndex index(int row, int column,
00062                               const QModelIndex &parent = QModelIndex()) const final;
00063     virtual QModelIndex parent(const QModelIndex &index) const final;
00064     virtual int realRowCount(const QModelIndex &parent = QModelIndex()) const final;
00065     virtual int rowCount(const QModelIndex &parent = QModelIndex()) const final;
00066     virtual int columnCount(const QModelIndex &parent = QModelIndex()) const final;
00067 
00068     QModelIndex addFile(File* file, const Module &module);
00069     virtual bool removeRows(int position, int rows, const QModelIndex &parent) override;
00070 
00071     void removeItem(QModelIndex index);
00072 
00073     int populate(const QModelIndex &index, unsigned int nominalCount, unsigned int minCount, unsigned int maxTries);
00074 
00075     QString rootPath();
00076     QString path(QModelIndex index) const;
00077     quint64 position(QModelIndex index) const;
00078     quint64 size    (QModelIndex index) const;
00079 
00080     void updateByFilePosition(quint64 pos);
00081 
00082 public slots:
00083     void requestExpansion(const QModelIndex &index);
00084     void updateCurrent(const QModelIndex &index);
00085     void deleteChildren(const QModelIndex &index);
00086     void updateFilter(QString expression);
00087     int updateChildren(const QModelIndex &index);
00088 
00089 signals:
00090     void filterChanged(QString);
00091     void invalidFilter();
00092     void work();
00093 
00094 
00095 private:
00096     QModelIndex findItemChildByFilePosition(const TreeItem& treeItem, qint64 position);
00097 
00098     static const int defaultPopulation   = 128;
00099     static const int minPopulationRatio  = 2;
00100     static const int populationTries     = 32;
00101     QModelIndex addObject(Object &object, const QModelIndex &parent);
00102 
00103     TreeItem *rootItem;
00104     QModelIndex current;
00105     const ProgramLoader& programLoader;
00106 };
00107 
00108 #endif // TREEMODEL_H