Advertisement
Guest User

fileslistmodel.h

a guest
May 4th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.26 KB | None | 0 0
  1. #ifndef FILESLISTMODEL_H
  2. #define FILESLISTMODEL_H
  3.  
  4. #include <QtCore/QAbstractItemModel>
  5. #include <QtCore/QStringList>
  6. #include "core/config.h"
  7.  
  8. /**
  9.  * Represents a single line from «Files» config section
  10.  * for storing in a flat list (not a map), see FLNodeGroup.
  11.  *
  12.  * When initializing model, it converts ConfigArchsSet to list of groups of nodes,
  13.  * and then configArchsSet() can convert it back.
  14.  */
  15. struct FLNode {
  16.     QString target;
  17.     bool symlinking;
  18.     QString source;
  19.     FLNode(QString target, bool symlinking, QString source):
  20.         target(target), symlinking(symlinking), source(source) {}
  21. };
  22.  
  23. /**
  24.  * A group of nodes for a single architecture.
  25.  *
  26.  * Groups are the top level of the tree. Each group contains flat list of nodes.
  27.  */
  28. struct FLNodeGroup {
  29.     QString arch;
  30.     QList<FLNode> nodes;
  31.     FLNodeGroup(QString arch, QList<FLNode> nodes):
  32.         arch(arch), nodes(nodes) {}
  33. };
  34.  
  35. /**
  36.  * Internal pointer for assigning to QModelIndex.
  37.  *
  38.  * Stores index of architecture node group and index of node in it.
  39.  * To store pointer to the whole group, set \c fileIndex to \c -1.
  40.  */
  41. struct FLNodePointer {
  42.     int archIndex;
  43.     int fileIndex;
  44.     FLNodePointer(int archIndex, int fileIndex=-1):
  45.         archIndex(archIndex), fileIndex(fileIndex) {}
  46. };
  47.  
  48.  
  49. class FilesListModel : public QAbstractItemModel
  50. {
  51. public:
  52.     static const int COLUMN_TARGET = 0;
  53.     static const int COLUMN_SOURCE = 1;
  54.     static const int COLUMNS_COUNT = 2;
  55.    
  56. private:
  57.     QList<FLNodeGroup> _data;
  58.    
  59. public:
  60.     FilesListModel(ConfigArchsSet set);
  61.     ConfigArchsSet configArchsSet();
  62.    
  63.     virtual QModelIndex   index(int row, int column, const QModelIndex& parent=QModelIndex()) const;
  64.     virtual QModelIndex   parent(const QModelIndex &child) const;
  65.     virtual int           rowCount(const QModelIndex &parent = QModelIndex()) const;
  66.     virtual int           columnCount(const QModelIndex &parent = QModelIndex()) const;
  67.     virtual QVariant      data(const QModelIndex &index, int role = Qt::DisplayRole) const;
  68. //  virtual bool          setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
  69. //  virtual Qt::ItemFlags flags(const QModelIndex& index) const;
  70. //  virtual bool          removeRows(int row, int count, const QModelIndex& parent = QModelIndex());
  71. };
  72.  
  73. #endif // FILESLISTMODEL_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement