DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
FileModel.cpp
Go to the documentation of this file.
1
4
5#include <QFileInfo>
6#include <QDir>
8#include "dbe/FileModel.hpp"
10#include "dbe/MainWindow.hpp"
11
12dbe::FileModel::FileModel ( QObject * parent )
13 : QAbstractTableModel ( parent ),
14 Headers
15{ tr ( "Name" ), tr ( "Folder" ), tr ( "Permission" ) }
16{
17 initpaths();
18 initconnections();
19 initmodel();
20}
21
22dbe::FileModel::FileModel ( QList<QStringList> const & FileList, QObject * parent )
23 : QAbstractTableModel ( parent ),
24 IncludedFiles ( FileList ),
25 Headers
26{ tr ( "Name" ), tr ( "Folder" ), tr ( "Permission" ) }
27{
28 initconnections();
29}
30
33
34int dbe::FileModel::rowCount ( const QModelIndex & parent ) const
35{
36 if ( !parent.isValid() )
37 {
38 return IncludedFiles.size();
39 }
40
41 return 0;
42}
43
44int dbe::FileModel::columnCount ( const QModelIndex & parent ) const
45{
46 Q_UNUSED ( parent )
47 return Headers.size();
48}
49
50QVariant dbe::FileModel::data ( const QModelIndex & index, int role ) const
51{
52 if ( index.isValid() )
53 {
54 if ( role == Qt::DisplayRole )
55 return QVariant (
56 IncludedFiles.at ( index.row() ).at ( index.column() ) );
57 }
58
59 return QVariant();
60}
61
62QVariant dbe::FileModel::headerData ( int section, Qt::Orientation orientation,
63 int role ) const
64{
65 if ( role == Qt::DisplayRole )
66 {
67 if ( orientation == Qt::Horizontal )
68 {
69 return Headers.at ( section );
70 }
71
72 if ( orientation == Qt::Vertical )
73 {
74 return section + 1;
75 }
76 }
77
78 return QVariant();
79}
80
81Qt::ItemFlags dbe::FileModel::flags ( const QModelIndex & index ) const
82{
83 if ( IncludedFiles.at ( index.row() ).at ( static_cast<int>
84 ( tablepositions::filepermission ) ) == "RW" )
85 {
86 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
87 }
88
89 return Qt::ItemIsSelectable;
90}
91
93{
94 QString TDAQ_DB_REPOSITORY = getenv ( "TDAQ_DB_REPOSITORY" );
95 if(TDAQ_DB_REPOSITORY.isEmpty() == false) {
96 QString TDAQ_DB_USER_REPOSITORY = getenv ( "TDAQ_DB_USER_REPOSITORY" );
97 FolderPathList = TDAQ_DB_USER_REPOSITORY.split ( ":", QString::SkipEmptyParts );
98
100 } else {
101 QString DUNEDAQ_DB_PATH = getenv ( "DUNEDAQ_DB_PATH" );
102 FolderPathList = DUNEDAQ_DB_PATH.split ( ":", QString::SkipEmptyParts );
103 }
104
105 for ( QString & PathName : FolderPathList )
106 {
107 if ( !PathName.endsWith ( "/" ) )
108 {
109 PathName.append ( "/" );
110 }
111 }
112}
113
115{
116 connect ( this, SIGNAL ( FileCacheReady ( QList<QStringList> & ) ), &confaccessor::ref(),
117 SLOT ( GetFileCache ( QList<QStringList> & ) ) );
118}
119
120QString dbe::FileModel::GetFullFileName ( QString & FileName )
121{
122 QFileInfo FileInfo ( FileName );
123
124 if ( FileInfo.isRelative() )
125 {
126
127 for ( const QString & Folder : FolderPathList )
128 {
129 QDir TdaqFolder ( Folder );
130
131 if ( TdaqFolder.exists ( FileName ) )
132 {
133 FileName = TdaqFolder.path() + "/" + FileName;
134 break;
135 }
136 }
137 }
138
139 return FileName;
140}
141
142QList<QStringList> dbe::FileModel::GetFilesInfo() const
143{
144 return IncludedFiles;
145}
146
148{
149 QStringList sources = dbe::config::api::get::file::inclusions (
151
152 for ( QString const & source : sources )
153 {
154
155 QFileInfo srcinfo ( source );
156 QString fn = srcinfo.filePath();
157
158 for ( QString const & path : FolderPathList )
159 {
160 if ( fn.startsWith ( path ) )
161 {
162 fn = fn.replace ( 0, path.size(), "" );
163 break;
164 }
165 }
166
167 IncludedFiles.append ( QStringList{ srcinfo.fileName(), fn, confaccessor::check_file_rw ( source ) ? "RW" : "RO" } );
168 }
169
170 if ( IncludedFiles.size() )
171 {
172 emit FileCacheReady ( IncludedFiles );
173 }
174}
int columnCount(const QModelIndex &parent) const
Definition FileModel.cpp:44
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Definition FileModel.cpp:62
void initconnections()
Qt::ItemFlags flags(const QModelIndex &index) const
Definition FileModel.cpp:81
FileModel(QObject *parent=nullptr)
Including QT Headers.
Definition FileModel.cpp:12
int rowCount(const QModelIndex &parent) const
Definition FileModel.cpp:34
QList< QStringList > GetFilesInfo() const
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition FileModel.cpp:50
QString GetFullFileName(QString &FileName)
QString find_db_repository_dir()
static MainWindow * findthis()
static bool check_file_rw(const QString &FileName)
static QString dbfullname()
static confaccessor & ref()
static QStringList inclusions(QStringList const &candidates, QStringList files={ })