Root/
| 1 | /* |
| 2 | Copyright 2010 Christian Vetter veaac.fdirct@gmail.com |
| 3 | |
| 4 | This file is part of MoNav. |
| 5 | |
| 6 | MoNav is free software: you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation, either version 3 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | MoNav is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along 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 | |
| 29 | static inline QString fileInDirectory( QString directory, QString filename ) |
| 30 | { |
| 31 | QDir dir( directory ); |
| 32 | return dir.filePath( filename ); |
| 33 | } |
| 34 | |
| 35 | static 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 | |
| 44 | class FileStream : public QDataStream { |
| 45 | |
| 46 | public: |
| 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 | |
| 60 | protected: |
| 61 | |
| 62 | QFile m_file; |
| 63 | }; |
| 64 | |
| 65 | class Timer : public QTime { |
| 66 | |
| 67 | public: |
| 68 | |
| 69 | Timer() |
| 70 | { |
| 71 | start(); |
| 72 | } |
| 73 | }; |
| 74 | |
| 75 | #endif // QTHELPERS_H |
| 76 |
Branches:
master
