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

Last change on this file since 53 was 53, checked in by sven, 10 years ago

Punch Card Editor, ongoing development

  • Extended new Deck interface, expanding the undo framework
  • Implemented editor changes via undo framework
  • revised the menu and toolbar actions and structure (now dynamic construction at deck load time), implemented undo viewer
  • Started implementation of device driver framework in menu
  • Embedded the Qextserialport library (http://qextserialport.sourceforge.net/)
  • Started the Documation M200 Client device driver (well, just created the directory structure and qmake project file infrastructure)
  • At the current state, the complete project compiles :-)

Statistics: About 3500 Lines of code (without libqextserialport)

-- sven @ workstation

File size: 2.8 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
51void Deck::run(DeckUndoCommand* command, bool call_redo) {
52        this->undo_stack.push(command);
53        if(call_redo)
54                command->redo();
55}
56
57bool Deck::isValid(int i) {
58        return createIndex(i).isValid();
59}
60
61DeckIndex Deck::createIndex(int i) {
62        return DeckIndex(this, i);
63}
64
65void Deck::emitChanged(DeckIndex lower, DeckIndex upper) {
66        emit contentsChanged(lower, upper);
67}
68
69bool Deck::insert(DeckIndex after) {
70        // TODO: Undo Redo Framework
71        if(!after.assertDeck(this))
72                return false;
73        DeckIndex new_index = createIndex(after + 1);
74        qDebug("Inserting card at %i", (int)new_index.normalized());
75        cards.insert( new_index.normalized(), Card() );
76        qDebug() << "Deck is now:" << *this;
77        emit contentsChanged(after, createIndex(count()) );
78        return true;
79}
80
81bool Deck::insertTimes(DeckIndex after, int times) {
82        // ja, das ist bloed, aber reicht erst mal:
83        for(;times>0;times--) insert(++after);
84        return true;
85}
86
87void Deck::append(Card card) {
88        // man ist das bloed:
89        cards.push_back(card);
90}
91
92
93bool Deck::move(DeckIndex /*before*/, DeckIndex /*after*/) {
94        // asdasdas
95        return true;
96        // emit cardChanged
97}
98
99bool Deck::erase(DeckIndex from, DeckIndex to) {
100        qDebug() << "Deck: Erasing from" << from << " to " << to;
101//      main->deck->erase( main->deck->begin() += new_max_blocks+1,
102//         main->deck->begin() += end_block_number+1 );
103        return true;
104        // emit cardChanged
105}
106
107
108
109
110QDebug QPunchCard::operator<<(QDebug dbg, const Deck &c) {
111        dbg.nospace() << "QPunchCard::File object with [" << c.count() << "] cards:\n\n";
112        for(int i = 0; i < c.size(); i++) {
113                dbg.nospace() << "Card no. #" << i << " (" << c.at(i) << ")\n";
114                dbg.nospace() << c.at(i);
115                dbg.nospace() << '\n';
116        }
117        return dbg.nospace();
118}
119
120QDebug QPunchCard::operator<<(QDebug dbg, const DeckIndex &c) {
121        dbg.nospace() << "[QPunchCard::DeckIndex: i=" << c.asInt() << ". Has deck: " << c.hasDeck() << "]";
122        return dbg.nospace();
123}
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