- Timestamp:
- 01/22/10 19:44:34 (2 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
punch-card-project/trunk/punch-card-editor/src/qpunchcard/deck.cc
r53 r59 7 7 } 8 8 9 Deck::Deck( const FileFormat* format, QObject* parent) :10 QObject(parent), undo_stack(this), format(format) {9 Deck::Deck(FileFormat format, const QString& filename, QObject* parent) : 10 QObject(parent), undo_stack(this), format(format), filename(filename) { 11 11 init(); 12 read(); 12 13 } 13 14 … … 18 19 19 20 bool Deck::save() { 20 return file ? save(*file) : false;21 return hasFile() ? save(filename) : false; 21 22 } 22 23 23 bool Deck::save( QFile& file) {24 return save(format.data(), file);24 bool Deck::save(const QString& filename) { 25 return hasFormat() ? save(format, filename) : false; 25 26 } 26 27 27 bool Deck::save(const FileFormat* format, QFile& file) { 28 return format ? format->write(file, *this) : false; 28 bool Deck::save(FileFormat format, const QString& filename) { 29 QFile file(filename); 30 return save(format, file); 31 } 32 33 bool Deck::save(FileFormat format, QFile& file) { 34 if( format.write(file, this) ) { 35 // save filename and format 36 this->format = format; 37 this->filename = file.fileName(); 38 return true; 39 } else { 40 qDebug() << "Deck saving failed. Format: " << format.getName(); 41 return false; 42 } 29 43 } 30 44 31 45 bool Deck::read() { 32 return file ? read(*file) : false;46 return hasFile() ? read(filename) : false; 33 47 } 34 48 35 bool Deck::read( QFile& file) {36 return read(format.data(), file);49 bool Deck::read(const QString& filename) { 50 return hasFormat() ? save(format, filename) : false; 37 51 } 38 52 39 bool Deck::read(const FileFormat* format, QFile& file) { 40 return format ? format->read(file, *this) : false; 53 bool Deck::read(FileFormat format, const QString &filename) { 54 QFile file(filename); 55 return read(format, file); 41 56 } 42 57 43 void Deck::setFormat(const FileFormat* new_format) { 44 format = QSharedPointer<const FileFormat>(new_format); 45 } 46 47 void Deck::setFile(QFile* file) { 48 this->file = QSharedPointer<QFile>(file); 58 bool Deck::read(FileFormat format, QFile& file) { 59 if( format.read(file, this) ) { 60 this->format = format; 61 this->filename = file.fileName(); 62 return true; 63 } else { 64 return false; 65 } 49 66 } 50 67
Powered by
Expect where otherwise noted, content on this site is licensed under a