1 | #include "card.h" |
---|
2 | |
---|
3 | using namespace QPunchCard; |
---|
4 | |
---|
5 | //QPunchCard::Deck::Deck(FileFormat* format) { |
---|
6 | void Deck::init() { |
---|
7 | undo = new QUndoStack(this); |
---|
8 | |
---|
9 | |
---|
10 | } |
---|
11 | |
---|
12 | bool Deck::save(FileFormat* format, QFile& file) { |
---|
13 | if(!format) return false; |
---|
14 | return format->write(file); |
---|
15 | } |
---|
16 | |
---|
17 | bool Deck::insert(DeckIndex after) { |
---|
18 | // TODO: Undo Redo Framework |
---|
19 | if(!after.assertDeck(this)) |
---|
20 | return false; |
---|
21 | DeckIndex new_index = createIndex(after + 1); |
---|
22 | qDebug("Inserting card at %i", (int)new_index.normalized()); |
---|
23 | QList< QPointer<Card> >::insert( new_index.normalized(), new Card); |
---|
24 | qDebug() << "Deck is now:" << *this; |
---|
25 | emit contentsChanged(after, createIndex(count()) ); |
---|
26 | return true; |
---|
27 | } |
---|
28 | |
---|
29 | bool Deck::insertTimes(DeckIndex after, int times) { |
---|
30 | // ja, das ist bloed, aber reicht erst mal: |
---|
31 | for(;times>0;times--) insert(++after); |
---|
32 | return true; |
---|
33 | } |
---|
34 | |
---|
35 | |
---|
36 | bool Deck::move(DeckIndex /*before*/, DeckIndex /*after*/) { |
---|
37 | // asdasdas |
---|
38 | return true; |
---|
39 | // emit cardChanged |
---|
40 | } |
---|
41 | |
---|
42 | bool Deck::erase(DeckIndex from, DeckIndex to) { |
---|
43 | qDebug() << "Deck: Erasing from" << from << " to " << to; |
---|
44 | // main->deck->erase( main->deck->begin() += new_max_blocks+1, |
---|
45 | // main->deck->begin() += end_block_number+1 ); |
---|
46 | return true; |
---|
47 | // emit cardChanged |
---|
48 | } |
---|
49 | |
---|
50 | /* |
---|
51 | void QPunchCard::changeCard(int card, const Column& new_value) { |
---|
52 | if(!isValid(card)) |
---|
53 | return; |
---|
54 | // TODO: PROBLEM: Alte Karte wird einfach |
---|
55 | // weggeschmissen (tote referenz). |
---|
56 | this->at(card) = new_value; |
---|
57 | } |
---|
58 | */ |
---|
59 | |
---|
60 | QDebug QPunchCard::operator<<(QDebug dbg, const Column &c) { |
---|
61 | for(int x=0; x < 12; x++) { |
---|
62 | // seperate in 3 nibbles |
---|
63 | if(x && x%4==0) dbg.nospace() << " "; |
---|
64 | dbg.nospace() << (c.testBit(x)?"1":"0"); |
---|
65 | } |
---|
66 | //os << std::endl; |
---|
67 | return dbg.nospace(); |
---|
68 | } |
---|
69 | |
---|
70 | QDebug QPunchCard::operator<<(QDebug dbg, const Card &c) { |
---|
71 | dbg.nospace() << "/ 1234 5678 9012\n"; |
---|
72 | for(int x=0; x < 80; x++) { |
---|
73 | dbg.nospace() << QString("|%1 ").arg(QString::number(x), 2, ' ').toAscii().data(); |
---|
74 | dbg.nospace() << c.column[x] << "\n"; |
---|
75 | } |
---|
76 | return dbg.nospace(); |
---|
77 | } |
---|
78 | |
---|
79 | |
---|
80 | QDebug QPunchCard::operator<<(QDebug dbg, const Deck &c) { |
---|
81 | dbg.nospace() << "QPunchCard::File object with [" << c.size() << "] cards:\n\n"; |
---|
82 | for(int i = 0; i < c.size(); i++) { |
---|
83 | dbg.nospace() << "Card no. #" << i << " (" << c[i] << ")\n"; |
---|
84 | dbg.nospace() << *c.at(i); |
---|
85 | dbg.nospace() << '\n'; |
---|
86 | } |
---|
87 | return dbg.nospace(); |
---|
88 | } |
---|
89 | |
---|
90 | QDebug QPunchCard::operator<<(QDebug dbg, const DeckIndex &c) { |
---|
91 | dbg.nospace() << "[QPunchCard::DeckIndex: i=" << c.asInt() << ". Has deck: " << c.hasDeck() << "]"; |
---|
92 | return dbg.nospace(); |
---|
93 | } |
---|