source: projects/punch-card-project/trunk/punch-card-editor/src/qpunchcard/deck.cc @ 59

Last change on this file since 59 was 59, checked in by sven-win, 14 years ago

Umfangreiche Weiterentwicklung (letzte Entwicklung am Netbook). Driver fuer M200 erstmals testweise implementiert; funktioniert(e mit Netbook).

-- Sven @ netboo

File size: 3.2 KB
Line 
1#include "deck.h"
2
3using namespace QPunchCard;
4
5Deck::Deck(QObject* parent) : QObject(parent), undo_stack(this) {
6        init();
7}
8
9Deck::Deck(FileFormat format, const QString& filename, QObject* parent) :
10                QObject(parent), undo_stack(this), format(format), filename(filename) {
11        init();
12        read();
13}
14
15void Deck::init() {
16        // undo ist jetzt direktes member, nicht mher noetig
17        //undo = new QUndoStack(this);
18}
19
20bool Deck::save() {
21        return hasFile() ? save(filename) : false;
22}
23
24bool Deck::save(const QString& filename) {
25        return hasFormat() ? save(format, filename) : false;
26}
27
28bool Deck::save(FileFormat format, const QString& filename) {
29        QFile file(filename);
30        return save(format, file);
31}
32
33bool 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        }
43}
44
45bool Deck::read() {
46        return hasFile() ? read(filename) : false;
47}
48
49bool Deck::read(const QString& filename) {
50        return hasFormat() ? save(format, filename) : false;
51}
52
53bool Deck::read(FileFormat format, const QString &filename) {
54        QFile file(filename);
55        return read(format, file);
56}
57
58bool 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        }
66}
67
68void Deck::run(DeckUndoCommand* command, bool call_redo) {
69        this->undo_stack.push(command);
70        if(call_redo)
71                command->redo();
72}
73
74bool Deck::isValid(int i) {
75        return createIndex(i).isValid();
76}
77
78DeckIndex Deck::createIndex(int i) {
79        return DeckIndex(this, i);
80}
81
82void Deck::emitChanged(DeckIndex lower, DeckIndex upper) {
83        emit contentsChanged(lower, upper);
84}
85
86bool Deck::insert(DeckIndex after) {
87        // TODO: Undo Redo Framework
88        if(!after.assertDeck(this))
89                return false;
90        DeckIndex new_index = createIndex(after + 1);
91        qDebug("Inserting card at %i", (int)new_index.normalized());
92        cards.insert( new_index.normalized(), Card() );
93        qDebug() << "Deck is now:" << *this;
94        emit contentsChanged(after, createIndex(count()) );
95        return true;
96}
97
98bool Deck::insertTimes(DeckIndex after, int times) {
99        // ja, das ist bloed, aber reicht erst mal:
100        for(;times>0;times--) insert(++after);
101        return true;
102}
103
104void Deck::append(Card card) {
105        // man ist das bloed:
106        cards.push_back(card);
107}
108
109
110bool Deck::move(DeckIndex /*before*/, DeckIndex /*after*/) {
111        // asdasdas
112        return true;
113        // emit cardChanged
114}
115
116bool Deck::erase(DeckIndex from, DeckIndex to) {
117        qDebug() << "Deck: Erasing from" << from << " to " << to;
118//      main->deck->erase( main->deck->begin() += new_max_blocks+1,
119//         main->deck->begin() += end_block_number+1 );
120        return true;
121        // emit cardChanged
122}
123
124
125
126
127QDebug QPunchCard::operator<<(QDebug dbg, const Deck &c) {
128        dbg.nospace() << "QPunchCard::File object with [" << c.count() << "] cards:\n\n";
129        for(int i = 0; i < c.size(); i++) {
130                dbg.nospace() << "Card no. #" << i << " (" << c.at(i) << ")\n";
131                dbg.nospace() << c.at(i);
132                dbg.nospace() << '\n';
133        }
134        return dbg.nospace();
135}
136
137QDebug QPunchCard::operator<<(QDebug dbg, const DeckIndex &c) {
138        dbg.nospace() << "[QPunchCard::DeckIndex: i=" << c.asInt() << ". Has deck: " << c.hasDeck() << "]";
139        return dbg.nospace();
140}
Note: See TracBrowser for help on using the repository browser.
© 2008 - 2013 technikum29 • Sven Köppel • Some rights reserved
Powered by Trac
Expect where otherwise noted, content on this site is licensed under a Creative Commons 3.0 License