Ignore:
Timestamp:
Dec 16, 2009, 2:47:25 AM (10 years ago)
Author:
sven
Message:

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

Location:
punch-card/punch-card-editor
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • punch-card/punch-card-editor

    • Property svn:ignore set to

  • punch-card/punch-card-editor/src/qpunchcard/card.h

    r49 r52  
    1414
    1515namespace QPunchCard {
    16         class Column; class Card; class Deck; class DeckIndex;
     16        class Column; class Deck; class DeckIndex;
    1717};
    18 
    19 #include "format.h"
    20 //#include "codec.h"
    2118
    2219namespace QPunchCard {
     
    2926        Column() : QBitArray(13) {}
    3027
     28        // TODO: int-Casting komplett entfernen. Das ist nicht Sinn
     29        //       der Sache bei der *Modellierung*, sondern eben eher
     30        //       beim Import/Export. Natuerlich *kann* man hier Methoden
     31        //       fuer sowas bereitstellen.
    3132        Column(int value) : QBitArray(13) {
    3233                // TODO: range check, throw exception if bad
     
    3637                }
    3738        }
    38 
    3939
    4040        operator int() const {
     
    4949 * This is a punch card.
    5050 **/
    51 class Card : public QObject {
    52         Q_OBJECT // must be qobject for signals/slots and QPointer usage
     51class Card {
    5352
    5453public:
     
    7877
    7978        ~Card() {};
    80 
    81 signals:
    82         // auf das level will echt keiner runter!
    83         void dataChanged(int left_index, int right_index);
    84         // wenn signal: klasse muss QObject sein =>
    85         //              kein copy constructor möglich =>
    86         //              File = QVector<Card*>
    8779};
    8880
    89 
    90 /**
    91  * File uses the strategy pattern to switch between different
    92  * I/O formats (using the FileFormat class).
    93  **/
    94 class Deck : public QObject, public QList< QPointer<Card> > {
    95         Q_OBJECT
    96 
    97         QSharedPointer<const FileFormat> created_format;
    98         void init();
    99 
    100 public:
    101         typedef QList< QPointer<Card> >::iterator iterator;
    102         QPointer<QUndoStack> undo;
    103 
    104         // Creation and I/O handling ===================
    105         /// Create empty
    106         Deck() : QList< QPointer<Card> >() { init(); }
    107         ~Deck() {};
    108         /// Create from file/stream/etc., that is, calls format->read()
    109         Deck(const FileFormat* format) : QList< QPointer<Card> >(), created_format(format) { init(); }
    110         /// Save with same device/format as created
    111         bool save(QFile& file) { return save(created_format.data(), file); }
    112         /// Save
    113         bool save(const FileFormat* format, QFile& file);
    114         bool read(QFile& file) { return read(created_format.data(), file); }
    115         bool read(const FileFormat* format, QFile& file);
    116 
    117         bool canSave() const { return created_format; }
    118         void setFormat(const FileFormat* format);
    119         //File* getFile() { if(created_format && created_format->file) return created_format->file; }
    120 
    121         bool isModified() const { return !undo->isClean(); }
    122 
    123         // index handling ======================
    124         inline bool isValid(int i);
    125         inline DeckIndex createIndex(int i);
    126 
    127         // Bearbeitungsfunktionen
    128         bool insert(DeckIndex after); // neue Karte hinzufuegen
    129         bool insertTimes(DeckIndex after, int times = 1);
    130         bool move(DeckIndex from, DeckIndex to);
    131         bool erase(DeckIndex from, DeckIndex to);
    132 
    133         // Quick & dirty
    134         inline void emitChanged(DeckIndex lower, DeckIndex upper);
    135 signals:
    136         void cardCountChanged(int newCardCount); // wer braucht das?
    137 
    138         // das hier ist das FAVORISIERTE FORMAT:
    139         void contentsChanged(DeckIndex lowerCard, DeckIndex upperCard);
    140 
    141 
    142         void modified(bool modified);
    143         //void redoAvailable(bool available);
    144         //void undoAvailable(bool available);
    145         //void undoCommandAdded();
    146 
    147 public slots:
    148         //void redo() {}
    149         //void undo() {}
    150         //void setModified(bool modified) {}
    151 };
    152 
    153 // Java-style iterator
    154 typedef QListIterator< QPointer<Card> > DeckIterator;
    155 
    156 
    157 /**
    158  * CardIndex feels like an int (normalized)
    159  **/
    160 class DeckIndex {
    161 private:
    162         QPointer<Deck> deck;
    163         int i;
    164 public:
    165         // behaves like int, copy constructor and operator= will be created automatically
    166         DeckIndex(int i = 0) : i(i) {}
    167         operator int() const { return normalized(); }
    168         int asInt() const { return normalized(); }
    169 
    170         DeckIndex(Deck* d, int i) : deck(d), i(i) { if(!deck) qDebug() << "NULL DECK!"; }
    171         bool isValid() const { return deck ? (i >= 0 && i < deck->count()) : false; }
    172 
    173         // "normalisierung" = in Deck Bounds
    174         int normalized() const { if(!deck) return i; if(i < 0) return 0; else if(i >= deck->count()) return deck->count()-1; else return i; }
    175         void normalize() { i = normalized(); }
    176         bool canNormalize() const { return deck; }
    177 
    178         // special positions
    179         bool isTop() const { return i < 0; }
    180         bool isEnd() const { return i >= deck->count(); }
    181         bool isFirst() const { return i == 0; }
    182         bool isLast() const { return i == deck->count(); }
    183 
    184         const QPointer<Deck> getDeck() const { return deck; }
    185         void setDeck(Deck* deck) { this->deck = deck; }
    186         bool assertDeck(Deck* fallback) { if(!deck) deck=fallback; return deck == fallback; }
    187         bool hasDeck() const { return deck; }
    188 
    189         // ein paar abkuerzungen
    190         /// @returns null wenn nicht normalisierbar (also letztlich kein Deck da ist)
    191         QPointer<Card> getCard() const { return canNormalize() ? deck->at(normalized()) : NULL; }
    192 
    193         DeckIndex& operator++() { i++; return *this; }
    194         DeckIndex& operator+=(int x) { i+= x; return *this; }
    195 };
    19681
    19782/****************************************************************************
     
    19984 ***************************************************************************/
    20085
    201  QDebug operator<<(QDebug dbg, const Column &c);
    202  QDebug operator<<(QDebug dbg, const Card &c);
    203  QDebug operator<<(QDebug dbg, const Deck &c);
    204  QDebug operator<<(QDebug dbg, const DeckIndex &c);
     86QDebug operator<<(QDebug dbg, const Column &c);
     87QDebug operator<<(QDebug dbg, const Card &c);
    20588
    206 
    207 /****************************************************************************
    208   inline functions
    209  ***************************************************************************/
    210 
    211 inline bool Deck::isValid(int i) { return createIndex(i).isValid(); }
    212 inline DeckIndex Deck::createIndex(int i) { return DeckIndex(this, i); }
    213 inline void Deck::emitChanged(DeckIndex lower, DeckIndex upper) {
    214         emit contentsChanged(lower, upper);
    215 }
    21689
    21790}; // Namespace
Note: See TracChangeset for help on using the changeset viewer.
© 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