source: projects/punch-card/punch-card-editor/src/qpunchcard/deck.cc @ 52

Last change on this file since 52 was 52, checked in by sven, 14 years ago

Punch Card Editor: Code reordering and class renaming, rewriting.
Now using the namespace QPunchCard everywhere.

Parted the whole application into 5 parts/directories:

  • app: The application core with MainWindow and main() function
  • qpunchcard: Everything directly binary card related (no interpretation): modeling, input/output, view. Most important classes are Card, Deck, FileFormat, Widget
  • text: Everything related to text interpretation of Cards/Card Decks. Having the abstract Codec classes and the Text::Editor, Text::EditorDock
  • deckviewer: Application components like binary card editing central widget (CardEditor) and Navigator (Model View Controller classes)
  • driver: Basis for the driver framework, must be written soon.

Deck now hides the complete Storage to implement frontend methods that
implement versioning (Undo framework). All code was cleaned up, but doesn't
compile right now (still quite some non heavy errors).

-- Sven @ workstation

File size: 2.7 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(const FileFormat* format, QObject* parent) :
10                QObject(parent), undo_stack(this), format(format) {
11        init();
12}
13
14void Deck::init() {
15        // undo ist jetzt direktes member, nicht mher noetig
16        //undo = new QUndoStack(this);
17}
18
19bool Deck::save() {
20        return file ? save(*file) : false;
21}
22
23bool Deck::save(QFile& file) {
24        return save(format.data(), file);
25}
26
27bool Deck::save(const FileFormat* format, QFile& file) {
28        return format ? format->write(file, *this) : false;
29}
30
31bool Deck::read() {
32        return file ? read(*file) : false;
33}
34
35bool Deck::read(QFile& file) {
36        return read(format.data(), file);
37}
38
39bool Deck::read(const FileFormat* format, QFile& file) {
40        return format ? format->read(file, *this) : false;
41}
42
43void Deck::setFormat(const FileFormat* new_format) {
44        format = QSharedPointer<const FileFormat>(new_format);
45}
46
47void Deck::setFile(QFile* file) {
48        this->file = QSharedPointer<QFile>(file);
49}
50
51
52bool Deck::isValid(int i) {
53        return createIndex(i).isValid();
54}
55
56DeckIndex Deck::createIndex(int i) {
57        return DeckIndex(this, i);
58}
59
60void Deck::emitChanged(DeckIndex lower, DeckIndex upper) {
61        emit contentsChanged(lower, upper);
62}
63
64bool Deck::insert(DeckIndex after) {
65        // TODO: Undo Redo Framework
66        if(!after.assertDeck(this))
67                return false;
68        DeckIndex new_index = createIndex(after + 1);
69        qDebug("Inserting card at %i", (int)new_index.normalized());
70        cards.insert( new_index.normalized(), Card() );
71        qDebug() << "Deck is now:" << *this;
72        emit contentsChanged(after, createIndex(count()) );
73        return true;
74}
75
76bool Deck::insertTimes(DeckIndex after, int times) {
77        // ja, das ist bloed, aber reicht erst mal:
78        for(;times>0;times--) insert(++after);
79        return true;
80}
81
82void Deck::append(Card card) {
83        // man ist das bloed:
84        cards.push_back(card);
85}
86
87
88bool Deck::move(DeckIndex /*before*/, DeckIndex /*after*/) {
89        // asdasdas
90        return true;
91        // emit cardChanged
92}
93
94bool Deck::erase(DeckIndex from, DeckIndex to) {
95        qDebug() << "Deck: Erasing from" << from << " to " << to;
96//      main->deck->erase( main->deck->begin() += new_max_blocks+1,
97//         main->deck->begin() += end_block_number+1 );
98        return true;
99        // emit cardChanged
100}
101
102
103
104
105QDebug QPunchCard::operator<<(QDebug dbg, const Deck &c) {
106        dbg.nospace() << "QPunchCard::File object with [" << c.count() << "] cards:\n\n";
107        for(int i = 0; i < c.size(); i++) {
108                dbg.nospace() << "Card no. #" << i << " (" << c.at(i) << ")\n";
109                dbg.nospace() << c.at(i);
110                dbg.nospace() << '\n';
111        }
112        return dbg.nospace();
113}
114
115QDebug QPunchCard::operator<<(QDebug dbg, const DeckIndex &c) {
116        dbg.nospace() << "[QPunchCard::DeckIndex: i=" << c.asInt() << ". Has deck: " << c.hasDeck() << "]";
117        return dbg.nospace();
118}
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