Statically load the empty tile image so that we don't need to have over 9000 instances of it. Also display an error message if loading fails on startup.

This commit is contained in:
dfighter1985 2014-08-06 13:25:50 +02:00
parent 3fc31ee2ad
commit 2f56a5eee4
4 changed files with 45 additions and 8 deletions

View file

@ -37,6 +37,8 @@
#include "land_edit_dialog.h" #include "land_edit_dialog.h"
#include <QTimer>
TileEditorMainWindow::TileEditorMainWindow(QWidget *parent) TileEditorMainWindow::TileEditorMainWindow(QWidget *parent)
: QMainWindow(parent), : QMainWindow(parent),
m_ui(new Ui::TileEditorMainWindow) m_ui(new Ui::TileEditorMainWindow)
@ -44,6 +46,11 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent)
m_ui->setupUi(this); m_ui->setupUi(this);
m_undoStack = new QUndoStack(this); m_undoStack = new QUndoStack(this);
if( !TileItemNode::loadEmptyPixmap() )
{
QTimer::singleShot( 0, this, SLOT( onEmptyImageLoadFailed() ) );
}
// Retrieve the menu manager // Retrieve the menu manager
Core::ICore *core = Core::ICore::instance(); Core::ICore *core = Core::ICore::instance();
Core::MenuManager *menuManager = core->menuManager(); Core::MenuManager *menuManager = core->menuManager();
@ -341,6 +348,13 @@ void TileEditorMainWindow::onRotate( int id )
m_tileModel->setAlphaRot( id ); m_tileModel->setAlphaRot( id );
} }
void TileEditorMainWindow::onEmptyImageLoadFailed()
{
QMessageBox::critical( this,
tr( "Empty image load failed" ),
tr( "Couldn't load the image for empty tiles :(" ) );
}
void TileEditorMainWindow::onActionAddTile(bool triggered) void TileEditorMainWindow::onActionAddTile(bool triggered)
{ {
onActionAddTile(m_ui->tileViewTabWidget->currentIndex()); onActionAddTile(m_ui->tileViewTabWidget->currentIndex());

View file

@ -80,6 +80,8 @@ private Q_SLOTS:
void onZoomFactor(int level); void onZoomFactor(int level);
void onRotate(int id); void onRotate(int id);
void onEmptyImageLoadFailed();
private: private:
void onActionAddTile(int tabId); void onActionAddTile(int tabId);
void onActionDeleteTile(int tabId); void onActionDeleteTile(int tabId);

View file

@ -271,6 +271,12 @@ public:
bool loadImage( TileConstants::TTileChannel channel, const QString &fn ) bool loadImage( TileConstants::TTileChannel channel, const QString &fn )
{ {
if( fn.isEmpty() )
{
pixmaps[ channel ] = TileItemNodePvt::emptyPm();
return true;
}
QPixmap temp; QPixmap temp;
bool b = temp.load( fn ); bool b = temp.load( fn );
@ -284,6 +290,17 @@ public:
return true; return true;
} }
static bool loadEmptyImage()
{
bool b = empty.load( ":/placeHolder/images/empty_image.png" );
if( !b )
{
empty = QPixmap();
}
return b;
}
void clearImage( TileConstants::TTileChannel channel ) void clearImage( TileConstants::TTileChannel channel )
{ {
pixmaps[ channel ] = QPixmap(); pixmaps[ channel ] = QPixmap();
@ -293,10 +310,15 @@ public:
return pixmaps[ channel ]; return pixmaps[ channel ];
} }
static QPixmap& emptyPm(){ return empty; }
private: private:
QPixmap pixmaps[ TileConstants::TileChannelCount ]; QPixmap pixmaps[ TileConstants::TileChannelCount ];
static QPixmap empty;
}; };
QPixmap TileItemNodePvt::empty = QPixmap();
TileConstants::TTileChannel TileItemNode::s_displayChannel = TileConstants::TileDiffuse; TileConstants::TTileChannel TileItemNode::s_displayChannel = TileConstants::TileDiffuse;
TileItemNode::TileItemNode( TileConstants::TNodeTileType type, int tileId, Node *parent ) TileItemNode::TileItemNode( TileConstants::TNodeTileType type, int tileId, Node *parent )
@ -321,14 +343,7 @@ TileItemNode::~TileItemNode()
bool TileItemNode::setTileFilename(TileConstants::TTileChannel channel, QString filename) bool TileItemNode::setTileFilename(TileConstants::TTileChannel channel, QString filename)
{ {
QString fn = filename; bool b = pvt->loadImage( channel, filename );
if( filename.isEmpty() || ( filename == "empty" ) )
{
fn = ":/placeHolder/images/empty_image.png";
}
bool b = pvt->loadImage( channel, fn );
if( !b ) if( !b )
return false; return false;
@ -346,6 +361,11 @@ QString TileItemNode::getTileFilename(TileConstants::TTileChannel channel)
return itr.value(); return itr.value();
} }
bool TileItemNode::loadEmptyPixmap()
{
return TileItemNodePvt::loadEmptyImage();
}
QVariant TileItemNode::data(int column, int role) const QVariant TileItemNode::data(int column, int role) const
{ {
QString tileFilename = m_tileFilename[ TileItemNode::s_displayChannel ]; QString tileFilename = m_tileFilename[ TileItemNode::s_displayChannel ];

View file

@ -117,6 +117,7 @@ public:
static void setDisplayChannel( TileConstants::TTileChannel channel ){ s_displayChannel = channel; } static void setDisplayChannel( TileConstants::TTileChannel channel ){ s_displayChannel = channel; }
static TileConstants::TTileChannel displayChannel(){ return s_displayChannel; } static TileConstants::TTileChannel displayChannel(){ return s_displayChannel; }
static bool loadEmptyPixmap();
QVariant pixmap( TileConstants::TTileChannel channel ) const; QVariant pixmap( TileConstants::TTileChannel channel ) const;