DUE 2025; 100% correct solutions and explanations.
Design + implementation plan (complete,
ready-to-code)
Below I will give a concrete, practical solution you can implement straight away: class design,
GUI layout, CMake, key C++/Qt code snippets (container classes, factory, memento-style in-
memory backup/restore, pallet model, XML serialization on a worker thread, TCP client send,
and a simple TCP server). I focus on exactly the behaviours your brief requires and on good
Qt/C++ practice (pointers, parent-child ownership, initializer lists, forward declarations,
signals/slots, models for views). Use/extend these files to finish your project.
1 — High-level architecture & patterns
Container (abstract) — base class (code, weight, volume as int) — pure virtual
toXml(QXmlStreamWriter&) and type() etc. Concrete: Box, Cylinder.
o Factory pattern to create Box/Cylinder instances (prevents creating raw Container).
ContainerCodeGenerator — generates codes of the form YYYY/MM/[B|C]<serial>; keeps
a map of serial counters per YYYY/MM/B or per type; ensures serials 1..9999.
Unallocated list — QStandardItemModel (so it can be shown in QListView/QTreeView).
Items hold QVariant::fromValue(Container*) or store container info; but because we must
manage pointers, keep std::unique_ptr/raw pointers in an app-level container list and store
code string in the model. (The brief asks pointers used for all instances — so classes will
be created with new and parented where appropriate.)
Backup/Restore — Memento pattern in memory: store a deep-copy
std::vector<std::unique_ptr<Container>> snapshot (or store serializable state objects). On
restore, clear current unallocated list and recreate containers from the snapshot.
IMPORTANT: do not back up pointers only.
Pallet — class with number, QList<Container*> (pointers), weight() and volume() calculations.
Pallets are stored in an application-level QList<Pallet*> (or std::vector<Pallet*>).
Serialization worker — QObject moved to QThread (or use QRunnable + QThreadPool).
Worker builds XML using QXmlStreamWriter and emits a xmlReady(QString) signal; it will
also send the XML to 127.0.0.1:6164 via QTcpSocket (connect->write->flush->close).
Server — separate Qt console project using QTcpServer. On message received, parse
XML using QXmlStreamReader, validate container codes via QRegularExpression, replace
invalid codes with ****, and update a model (e.g., QStandardItemModel) for a view.
Design patterns used: Factory, Memento (for backup/restore), MVC (Qt model/view), Worker
Thread.