QXRD  0.11.16
Public Types | Public Slots | Signals | Public Member Functions | Private Member Functions | Private Attributes | List of all members
QxrdFileBrowserModel Class Reference

#include <qxrdfilebrowsermodel.h>

Inheritance diagram for QxrdFileBrowserModel:
Inheritance graph
[legend]
Collaboration diagram for QxrdFileBrowserModel:
Collaboration graph
[legend]

Public Types

typedef QAbstractTableModel inherited
 

Public Slots

void newDataAvailable (QVector< QFileInfo > dirs, QVector< QFileInfo > files, int limit=0, int trueSize=-1)
 
void updatedFile (QFileInfo file)
 

Signals

void rootChanged (const QString &path)
 
void fileUpdated (QFileInfo file)
 

Public Member Functions

 QxrdFileBrowserModel (QObject *parent)
 
 ~QxrdFileBrowserModel ()
 
void initialize ()
 
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
 
int rowCount (const QModelIndex &parent=QModelIndex()) const
 
int columnCount (const QModelIndex &parent=QModelIndex()) const
 
void setNameFilters (QStringList filters)
 
void setNameFilterDisables (bool disables)
 
QFileInfo fileInfo (const QModelIndex &index) const
 
QString fileName (const QModelIndex &index) const
 
QString filePath (const QModelIndex &index) const
 
void setRootPath (QString path)
 
QString rootPath () const
 
bool isDir (const QModelIndex &index) const
 
virtual void sort (int column, Qt::SortOrder order=Qt::AscendingOrder)
 
void refresh ()
 
QStringList nameFilters () const
 
int sortedColumn () const
 
Qt::SortOrder sortOrder () const
 
void generateFileUpdates (int doIt)
 

Private Member Functions

void updateModel ()
 

Private Attributes

QMutex m_Mutex
 
QxrdFileBrowserModelUpdaterThreadPtr m_UpdaterThread
 
QxrdFileBrowserModelUpdaterWPtr m_Updater
 
QString m_RootPath
 
QStringList m_NameFilters
 
QVector< QFileInfo > m_DirList
 
QVector< QFileInfo > m_FileList
 
int m_SortedColumn
 
Qt::SortOrder m_SortOrder
 
int m_Limit
 
int m_TrueSize
 
double m_HighlightOnTime
 
double m_HighlightFadeTime
 
int m_HighlightSaturation
 
int m_HighlightHue
 
QTimer * m_Timer
 

Detailed Description

Definition at line 17 of file qxrdfilebrowsermodel.h.

Member Typedef Documentation

typedef QAbstractTableModel QxrdFileBrowserModel::inherited

Definition at line 26 of file qxrdfilebrowsermodel.h.

Constructor & Destructor Documentation

QxrdFileBrowserModel::QxrdFileBrowserModel ( QObject *  parent)
explicit

Definition at line 14 of file qxrdfilebrowsermodel.cpp.

14  :
15  QAbstractTableModel(parent),
16  m_Mutex(QMutex::Recursive),
17  m_UpdaterThread(NULL),
18  m_Updater(),
19  m_SortedColumn(0),
20  m_SortOrder(Qt::AscendingOrder),
21  m_Limit(1000),
22  m_TrueSize(0),
23  m_HighlightOnTime(0.5),
26  m_HighlightHue(116)
27 {
28 }
QxrdFileBrowserModelUpdaterWPtr m_Updater
QxrdFileBrowserModelUpdaterThreadPtr m_UpdaterThread
QxrdFileBrowserModel::~QxrdFileBrowserModel ( )

Definition at line 30 of file qxrdfilebrowsermodel.cpp.

31 {
32 #ifndef QT_NO_DEBUG
33  printf("Deleting file browser model\n");
34 #endif
35 
36 // if (m_UpdaterThread) {
37 // m_UpdaterThread->shutdown();
38 // }
39 }

Member Function Documentation

int QxrdFileBrowserModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const

Definition at line 158 of file qxrdfilebrowsermodel.cpp.

159 {
160  return 3;
161 }
QVariant QxrdFileBrowserModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const

Definition at line 78 of file qxrdfilebrowsermodel.cpp.

References fileInfo(), m_HighlightFadeTime, m_HighlightHue, m_HighlightOnTime, m_HighlightSaturation, and m_Mutex.

79 {
80  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
81 
82  QModelIndex index = idx;
83  QFileInfo info = fileInfo(index);
84 
85  if (role == Qt::DisplayRole) {
86  if (index.isValid()) {
87  if (index.column() == 0) {
88  return info.fileName();
89  } else if (index.column() == 1) {
90  if (info.isDir()) {
91  return "--";
92  } else if (!info.exists()) {
93  return "";
94  } else {
95  qint64 sz = info.size();
96 
97  if (sz < 1024) {
98  return tr("%1 B").arg(sz);
99  } else if (sz < 1024*1024) {
100  return tr("%1 KB").arg(sz/1024);
101  } else if (sz < 1024*1024*1024) {
102  return tr("%1 MB").arg(sz/(1024*1024));
103  } else {
104  return tr("%1 GB").arg(sz/(1024*1024*1024));
105  }
106  }
107  } else if (index.column() == 2) {
108  return info.lastModified();
109  }
110  }
111  } else if (role == Qt::DecorationRole) {
112  if (index.column() == 0) {
113  if (info.isDir()) {
114  return QPixmap(":/images/folder-16x16.png");
115  } else if (!info.exists()) {
116  return QVariant();
117  } else {
118  QString suffix = info.suffix();
119 
120  if (suffix == "metadata") {
121  return QPixmap(":/images/file-metadata-16x16.png");
122  } else if (suffix == "avg") {
123  return QPixmap(":/images/file-integration-16x16.png");
124  } else if (suffix == "tif") {
125  return QPixmap(":/images/file-image-16x16.png");
126  } else {
127  return QPixmap(":/images/file-generic-16x16.png");
128  }
129  }
130  }
131  // } else if (role == Qt::SizeHintRole) {
132  // return QSize(80,10);
133  } else if (role == Qt::BackgroundRole) {
134  double lastMod = info.lastModified().msecsTo(QDateTime::currentDateTime())/1000.0;
135 
136  if (lastMod > (m_HighlightOnTime+m_HighlightFadeTime)) {
137  return QColor(Qt::white);
138  } else if (info.exists()){
139  QxrdFileBrowserModel *model = const_cast<QxrdFileBrowserModel*>(this);
140  emit model->dataChanged(index, index);
141 // printf("Data %d changed after %g\n", index.row(), lastMod);
142 
143 // m_Updater -> needUpdate();
144 
145  if (lastMod > m_HighlightOnTime) {
146  double fade = lastMod - m_HighlightOnTime;
147 
148  return QColor::fromHsv(m_HighlightHue, int(m_HighlightSaturation*double(m_HighlightFadeTime-fade)/double(m_HighlightFadeTime)), 255, 255);
149  } else {
150  return QColor::fromHsv(m_HighlightHue, m_HighlightSaturation, 255, 255);
151  }
152  }
153  }
154 
155  return QVariant();
156 }
QFileInfo fileInfo(const QModelIndex &index) const

Here is the call graph for this function:

QFileInfo QxrdFileBrowserModel::fileInfo ( const QModelIndex &  index) const

Definition at line 187 of file qxrdfilebrowsermodel.cpp.

References m_DirList, m_FileList, m_Limit, m_Mutex, and m_TrueSize.

Referenced by data(), fileName(), filePath(), and isDir().

188 {
189  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
190 
191  int n = index.row();
192  QFileInfo info;
193 
194  if (n >= m_DirList.count()) {
195  int nf = n-m_DirList.count();
196 
197  if (nf >= m_FileList.count()) {
198  info = QFileInfo(tr("... %1 additional files not displayed...").arg(m_TrueSize-m_Limit));
199  } else {
200  info = m_FileList.at(nf);
201  }
202  } else {
203  info = m_DirList.at(n);
204  }
205 
206  return info;
207 }
QVector< QFileInfo > m_FileList
QVector< QFileInfo > m_DirList

Here is the caller graph for this function:

QString QxrdFileBrowserModel::fileName ( const QModelIndex &  index) const

Definition at line 209 of file qxrdfilebrowsermodel.cpp.

References fileInfo(), and m_Mutex.

210 {
211  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
212 
213  return fileInfo(index).fileName();
214 }
QFileInfo fileInfo(const QModelIndex &index) const

Here is the call graph for this function:

QString QxrdFileBrowserModel::filePath ( const QModelIndex &  index) const

Definition at line 216 of file qxrdfilebrowsermodel.cpp.

References fileInfo(), and m_Mutex.

217 {
218  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
219 
220  return fileInfo(index).filePath();
221 }
QFileInfo fileInfo(const QModelIndex &index) const

Here is the call graph for this function:

void QxrdFileBrowserModel::fileUpdated ( QFileInfo  file)
signal

Referenced by QxrdFileBrowser::QxrdFileBrowser(), and updatedFile().

Here is the caller graph for this function:

void QxrdFileBrowserModel::generateFileUpdates ( int  doIt)

Definition at line 330 of file qxrdfilebrowsermodel.cpp.

References m_Mutex, and m_Updater.

331 {
332  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
333 
335 
336  if (updater) {
337  updater -> generateFileUpdates(doIt);
338  }
339 }
QxrdFileBrowserModelUpdaterWPtr m_Updater
void generateFileUpdates(int doIt)
QSharedPointer< QxrdFileBrowserModelUpdater > QxrdFileBrowserModelUpdaterPtr
QVariant QxrdFileBrowserModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role = Qt::DisplayRole 
) const

Definition at line 53 of file qxrdfilebrowsermodel.cpp.

References m_Mutex.

54 {
55  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
56 
57  if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
58  switch (section) {
59  case 0:
60  return "File name";
61 
62  case 1:
63  return "Size";
64 
65  case 2:
66  return "Modified";
67 
68  default:
69  return "";
70  }
71  } else {
72  return inherited::headerData(section, orientation, role);
73  }
74 
75  return QVariant();
76 }
void QxrdFileBrowserModel::initialize ( )

Definition at line 41 of file qxrdfilebrowsermodel.cpp.

References m_Updater, and m_UpdaterThread.

42 {
46  m_UpdaterThread -> setModel(sharedFromThis());
47 // m_UpdaterThread -> setObjectName("browser");
48  m_UpdaterThread -> start();
49  m_Updater = m_UpdaterThread->updater();
50 }
QxrdFileBrowserModelUpdaterWPtr m_Updater
QxrdFileBrowserModelUpdaterThreadPtr m_UpdaterThread
QSharedPointer< QxrdFileBrowserModelUpdaterThread > QxrdFileBrowserModelUpdaterThreadPtr
bool QxrdFileBrowserModel::isDir ( const QModelIndex &  index) const

Definition at line 280 of file qxrdfilebrowsermodel.cpp.

References fileInfo(), and m_Mutex.

281 {
282  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
283 
284  return fileInfo(index).isDir();
285 }
QFileInfo fileInfo(const QModelIndex &index) const

Here is the call graph for this function:

QStringList QxrdFileBrowserModel::nameFilters ( ) const

Definition at line 241 of file qxrdfilebrowsermodel.cpp.

References m_Mutex, and m_NameFilters.

242 {
243  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
244 
245  return m_NameFilters;
246 }
void QxrdFileBrowserModel::newDataAvailable ( QVector< QFileInfo >  dirs,
QVector< QFileInfo >  files,
int  limit = 0,
int  trueSize = -1 
)
slot

Definition at line 303 of file qxrdfilebrowsermodel.cpp.

References m_DirList, m_FileList, m_Limit, m_Mutex, and m_TrueSize.

304 {
305  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
306 
307  beginResetModel();
308 
309  m_Limit = limit;
310  m_TrueSize = trueSize;
311  m_DirList = dirs;
312  m_FileList = files;
313 
314  endResetModel();
315 }
QVector< QFileInfo > m_FileList
QVector< QFileInfo > m_DirList
void QxrdFileBrowserModel::refresh ( )

Definition at line 262 of file qxrdfilebrowsermodel.cpp.

References m_Mutex, and updateModel().

263 {
264  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
265 
266  updateModel();
267 }

Here is the call graph for this function:

void QxrdFileBrowserModel::rootChanged ( const QString &  path)
signal

Referenced by QxrdFileBrowserModelUpdater::QxrdFileBrowserModelUpdater(), and setRootPath().

Here is the caller graph for this function:

QString QxrdFileBrowserModel::rootPath ( ) const

Definition at line 234 of file qxrdfilebrowsermodel.cpp.

References m_Mutex, and m_RootPath.

235 {
236  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
237 
238  return m_RootPath;
239 }
int QxrdFileBrowserModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const

Definition at line 163 of file qxrdfilebrowsermodel.cpp.

References m_DirList, m_FileList, m_Limit, and m_Mutex.

164 {
165  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
166 
167  if (m_Limit > 0) {
168  return m_DirList.count() + m_Limit + 1;
169  } else {
170  return m_FileList.count() + m_DirList.count();
171  }
172 }
QVector< QFileInfo > m_FileList
QVector< QFileInfo > m_DirList
void QxrdFileBrowserModel::setNameFilterDisables ( bool  disables)

Definition at line 183 of file qxrdfilebrowsermodel.cpp.

184 {
185 }
void QxrdFileBrowserModel::setNameFilters ( QStringList  filters)

Definition at line 174 of file qxrdfilebrowsermodel.cpp.

References m_Mutex, m_NameFilters, and updateModel().

175 {
176  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
177 
178  m_NameFilters = filters;
179 
180  updateModel();
181 }

Here is the call graph for this function:

void QxrdFileBrowserModel::setRootPath ( QString  path)

Definition at line 223 of file qxrdfilebrowsermodel.cpp.

References m_Mutex, m_RootPath, rootChanged(), and updateModel().

224 {
225  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
226 
227  m_RootPath = path;
228 
229  updateModel();
230 
231  emit rootChanged(m_RootPath);
232 }
void rootChanged(const QString &path)

Here is the call graph for this function:

void QxrdFileBrowserModel::sort ( int  column,
Qt::SortOrder  order = Qt::AscendingOrder 
)
virtual

Definition at line 287 of file qxrdfilebrowsermodel.cpp.

References m_Mutex, m_SortedColumn, m_SortOrder, and m_Updater.

288 {
289  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
290 
291  if ((m_SortedColumn != column) || (m_SortOrder != order)) {
292  m_SortedColumn = column;
293  m_SortOrder = order;
294 
296 
297  if (updater) {
298  updater -> needUpdate();
299  }
300  }
301 }
QxrdFileBrowserModelUpdaterWPtr m_Updater
QSharedPointer< QxrdFileBrowserModelUpdater > QxrdFileBrowserModelUpdaterPtr
int QxrdFileBrowserModel::sortedColumn ( ) const

Definition at line 248 of file qxrdfilebrowsermodel.cpp.

References m_Mutex, and m_SortedColumn.

249 {
250  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
251 
252  return m_SortedColumn;
253 }
Qt::SortOrder QxrdFileBrowserModel::sortOrder ( ) const

Definition at line 255 of file qxrdfilebrowsermodel.cpp.

References m_Mutex, and m_SortOrder.

256 {
257  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
258 
259  return m_SortOrder;
260 }
void QxrdFileBrowserModel::updatedFile ( QFileInfo  file)
slot

Definition at line 317 of file qxrdfilebrowsermodel.cpp.

References fileUpdated().

318 {
319 // QxrdExperimentPtr expt(m_Experiment);
320 
321 // if (expt && qcepDebug(DEBUG_BROWSER)) {
322 // expt->printMessage(tr("file %1 updated at %2")
323 // .arg(path)
324 // .arg(atTime.toString(Qt::ISODate)));
325 // }
326 
327  emit fileUpdated(file);
328 }
void fileUpdated(QFileInfo file)
void QxrdFileBrowserModel::updateModel ( )
private

Definition at line 269 of file qxrdfilebrowsermodel.cpp.

References m_Mutex, and m_Updater.

Referenced by refresh(), setNameFilters(), and setRootPath().

270 {
271  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
272 
274 
275  if (updater) {
276  updater -> needUpdate();
277  }
278 }
QxrdFileBrowserModelUpdaterWPtr m_Updater
QSharedPointer< QxrdFileBrowserModelUpdater > QxrdFileBrowserModelUpdaterPtr

Here is the caller graph for this function:

Member Data Documentation

QVector<QFileInfo> QxrdFileBrowserModel::m_DirList
private

Definition at line 70 of file qxrdfilebrowsermodel.h.

Referenced by fileInfo(), newDataAvailable(), and rowCount().

QVector<QFileInfo> QxrdFileBrowserModel::m_FileList
private

Definition at line 71 of file qxrdfilebrowsermodel.h.

Referenced by fileInfo(), newDataAvailable(), and rowCount().

double QxrdFileBrowserModel::m_HighlightFadeTime
private

Definition at line 77 of file qxrdfilebrowsermodel.h.

Referenced by data().

int QxrdFileBrowserModel::m_HighlightHue
private

Definition at line 79 of file qxrdfilebrowsermodel.h.

Referenced by data().

double QxrdFileBrowserModel::m_HighlightOnTime
private

Definition at line 76 of file qxrdfilebrowsermodel.h.

Referenced by data().

int QxrdFileBrowserModel::m_HighlightSaturation
private

Definition at line 78 of file qxrdfilebrowsermodel.h.

Referenced by data().

int QxrdFileBrowserModel::m_Limit
private

Definition at line 74 of file qxrdfilebrowsermodel.h.

Referenced by fileInfo(), newDataAvailable(), and rowCount().

QMutex QxrdFileBrowserModel::m_Mutex
mutableprivate
QStringList QxrdFileBrowserModel::m_NameFilters
private

Definition at line 69 of file qxrdfilebrowsermodel.h.

Referenced by nameFilters(), and setNameFilters().

QString QxrdFileBrowserModel::m_RootPath
private

Definition at line 68 of file qxrdfilebrowsermodel.h.

Referenced by rootPath(), and setRootPath().

int QxrdFileBrowserModel::m_SortedColumn
private

Definition at line 72 of file qxrdfilebrowsermodel.h.

Referenced by sort(), and sortedColumn().

Qt::SortOrder QxrdFileBrowserModel::m_SortOrder
private

Definition at line 73 of file qxrdfilebrowsermodel.h.

Referenced by sort(), and sortOrder().

QTimer* QxrdFileBrowserModel::m_Timer
private

Definition at line 80 of file qxrdfilebrowsermodel.h.

int QxrdFileBrowserModel::m_TrueSize
private

Definition at line 75 of file qxrdfilebrowsermodel.h.

Referenced by fileInfo(), and newDataAvailable().

QxrdFileBrowserModelUpdaterWPtr QxrdFileBrowserModel::m_Updater
private

Definition at line 67 of file qxrdfilebrowsermodel.h.

Referenced by generateFileUpdates(), initialize(), sort(), and updateModel().

QxrdFileBrowserModelUpdaterThreadPtr QxrdFileBrowserModel::m_UpdaterThread
private

Definition at line 66 of file qxrdfilebrowsermodel.h.

Referenced by initialize().


The documentation for this class was generated from the following files: