void MainWindow::displayMap(const QModelIndex &aIndex)
{
Event *event = static_cast<Event*>(aIndex.internalPointer());
- QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room());
+
+ // room names are stored in lower-case format
+ // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png"
+ QString mapPath = QString(":/maps/rooms/%1.png").arg(event->room().toLower().remove("."));
if(!QFile::exists(mapPath))
mapPath = QString(":/maps/rooms/not-available.png");
+
+ QString roomName;
+ if(mapPath.contains("not-available", Qt::CaseInsensitive))
+ roomName = QString("Map is not available: %1").arg(event->room());
+ else
+ roomName = event->room();
+
QPixmap map(mapPath);
- MapWindow window(map,this);
+ MapWindow window(map,roomName,this);
window.exec();
}
#include "mapwindow.h"
-MapWindow::MapWindow(const QPixmap &aImage, QWidget *aParent)
+MapWindow::MapWindow(const QPixmap &aImage, const QString &aName, QWidget *aParent)
: QDialog(aParent)
{
setupUi(this);
setMouseTracking(true); // to receive mouse events
+ setWindowTitle(aName);
map->setPixmap(aImage);
}
class MapWindow : public QDialog, Ui::MapWindow
{
public:
- MapWindow(const QPixmap &aImage, QWidget *aParent = NULL);
+ MapWindow(const QPixmap &aImage, const QString &aName, QWidget *aParent = NULL);
~MapWindow() {}
protected:
virtual void mouseDoubleClickEvent(QMouseEvent *event);
// TODO: handle qeury error
//qDebug() << query.lastError();
if(query.next())
- {
- QString map = query.record().value("name").toString();
- map=map.toLower(); // room names are stored in lower-case format
- map=map.remove("."); // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png"
- return map;
- }
+ return query.record().value("name").toString();
else
return QString("not-available");
}