Hi there once again, thank you for the info from those two sites on QMaps and QLists. I understand the differences and concepts much better now after reading that info together with stuff on google. I didn't want to come back and post without attempting any solution to original posted question because that would mean I did not learn anything from the stuff I read. below is some code I wrote, consisting of my understanding of what the header and source file should look like, please check it and correct me if I misunderstood or am doing this incorrectly.
below is my header file:
#ifndef FILM_H
#define FILM_H
#include <QObject>
#include <QString>
#include <QMap>
{
Q_OBJECT
public:
private:
};
//Managed collection of pointers
class FilmMap : public QMap<QString, Film*>
{
public:
void addFilm (Film* film);
};
#endif
#ifndef FILM_H
#define FILM_H
#include <QObject>
#include <QString>
#include <QMap>
class Film : public QObject
{
Q_OBJECT
public:
Film (QString id, QString title, QString dir, QString length, QDate relDate);
Film (QStringList propList);
QString virtual toString (bool labelled, QString sepChar);
private:
QString m_FilmId;
QString m_Title;
QString m_Director;
QString m_FilmLength;
QDate m_ReleaseDate;
};
//Managed collection of pointers
class FilmMap : public QMap<QString, Film*>
{
public:
QString toString() const;
Film* findFilm (QString id);
QString getId (QString title);
void addFilm (Film* film);
void removeFilm (QString filmId);
};
#endif
To copy to clipboard, switch view to plain text mode
Below is my implementation file:
#include <QMap>
#include <QMapIterator>
#include "film.h"
using namespace std;
QString FilmMap
:: toString () const {
ConstIterator itr = constBegin();
for (; itr != constEnd(); ++itr)
os << '[' <<itr.key() << ']' << ":"
<< itr.value() -> toString() << endl;
return retval;
}
Film
* FilmMap
:: findFilm (QString id
){
}
{
return Id;
}
void FilmMap :: addFilm(Film* film)
{
insert (film -> getId(), film);
}
void FilmMap
:: removeFilm (QString filmId
) {
}
#include <QMap>
#include <QMapIterator>
#include "film.h"
using namespace std;
QString FilmMap :: toString () const
{
QString retval;
QTextStream os(&retval);
ConstIterator itr = constBegin();
for (; itr != constEnd(); ++itr)
os << '[' <<itr.key() << ']' << ":"
<< itr.value() -> toString() << endl;
return retval;
}
Film* FilmMap :: findFilm (QString id)
{
}
QString FilmMap :: getId (QString title)
{
return Id;
}
void FilmMap :: addFilm(Film* film)
{
insert (film -> getId(), film);
}
void FilmMap :: removeFilm (QString filmId)
{
}
To copy to clipboard, switch view to plain text mode
I have coded what I understood of the question but I do not know how to implement the 'findFilm' and 'removeFilm' iterators, kindly advise me on this please and tell me if I have done the above correctly. I would also appreciate if you could tell me hoe I code the main function in order to test the functions in FilmMap. Thank you so much for all your assistance.
Bookmarks