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