Root/monav/utils/qthelpers.h

1/*
2Copyright 2010 Christian Vetter veaac.fdirct@gmail.com
3
4This file is part of MoNav.
5
6MoNav is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
10
11MoNav is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with MoNav. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef QTHELPERS_H
21#define QTHELPERS_H
22
23#include <QFile>
24#include <QtDebug>
25#include <QDataStream>
26#include <QTime>
27#include <QDir>
28
29static inline QString fileInDirectory( QString directory, QString filename )
30{
31    QDir dir( directory );
32    return dir.filePath( filename );
33}
34
35static inline bool openQFile( QFile* file, QIODevice::OpenMode mode )
36{
37    if ( !file->open( mode ) ) {
38        qCritical() << "could not open file:" << file->fileName() << "," << mode;
39        return false;
40    }
41    return true;
42}
43
44class FileStream : public QDataStream {
45
46public:
47
48    FileStream( QString filename ) : m_file( filename )
49    {
50    }
51
52    bool open( QIODevice::OpenMode mode )
53    {
54        if ( !openQFile( &m_file, mode ) )
55            return false;
56        setDevice( &m_file );
57        return true;
58    }
59
60protected:
61
62    QFile m_file;
63};
64
65class Timer : public QTime {
66
67public:
68
69    Timer()
70    {
71        start();
72    }
73};
74
75#endif // QTHELPERS_H
76

Archive Download this file

Branches:
master



interactive