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:
parent
3fc31ee2ad
commit
2f56a5eee4
4 changed files with 45 additions and 8 deletions
|
@ -37,6 +37,8 @@
|
|||
|
||||
#include "land_edit_dialog.h"
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
TileEditorMainWindow::TileEditorMainWindow(QWidget *parent)
|
||||
: QMainWindow(parent),
|
||||
m_ui(new Ui::TileEditorMainWindow)
|
||||
|
@ -44,6 +46,11 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent)
|
|||
m_ui->setupUi(this);
|
||||
m_undoStack = new QUndoStack(this);
|
||||
|
||||
if( !TileItemNode::loadEmptyPixmap() )
|
||||
{
|
||||
QTimer::singleShot( 0, this, SLOT( onEmptyImageLoadFailed() ) );
|
||||
}
|
||||
|
||||
// Retrieve the menu manager
|
||||
Core::ICore *core = Core::ICore::instance();
|
||||
Core::MenuManager *menuManager = core->menuManager();
|
||||
|
@ -341,6 +348,13 @@ void TileEditorMainWindow::onRotate( int 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)
|
||||
{
|
||||
onActionAddTile(m_ui->tileViewTabWidget->currentIndex());
|
||||
|
|
|
@ -80,6 +80,8 @@ private Q_SLOTS:
|
|||
void onZoomFactor(int level);
|
||||
void onRotate(int id);
|
||||
|
||||
void onEmptyImageLoadFailed();
|
||||
|
||||
private:
|
||||
void onActionAddTile(int tabId);
|
||||
void onActionDeleteTile(int tabId);
|
||||
|
|
|
@ -271,6 +271,12 @@ public:
|
|||
|
||||
bool loadImage( TileConstants::TTileChannel channel, const QString &fn )
|
||||
{
|
||||
if( fn.isEmpty() )
|
||||
{
|
||||
pixmaps[ channel ] = TileItemNodePvt::emptyPm();
|
||||
return true;
|
||||
}
|
||||
|
||||
QPixmap temp;
|
||||
bool b = temp.load( fn );
|
||||
|
||||
|
@ -284,6 +290,17 @@ public:
|
|||
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 )
|
||||
{
|
||||
pixmaps[ channel ] = QPixmap();
|
||||
|
@ -293,10 +310,15 @@ public:
|
|||
return pixmaps[ channel ];
|
||||
}
|
||||
|
||||
static QPixmap& emptyPm(){ return empty; }
|
||||
|
||||
private:
|
||||
QPixmap pixmaps[ TileConstants::TileChannelCount ];
|
||||
static QPixmap empty;
|
||||
|
||||
};
|
||||
|
||||
QPixmap TileItemNodePvt::empty = QPixmap();
|
||||
TileConstants::TTileChannel TileItemNode::s_displayChannel = TileConstants::TileDiffuse;
|
||||
|
||||
TileItemNode::TileItemNode( TileConstants::TNodeTileType type, int tileId, Node *parent )
|
||||
|
@ -321,14 +343,7 @@ TileItemNode::~TileItemNode()
|
|||
|
||||
bool TileItemNode::setTileFilename(TileConstants::TTileChannel channel, QString filename)
|
||||
{
|
||||
QString fn = filename;
|
||||
|
||||
if( filename.isEmpty() || ( filename == "empty" ) )
|
||||
{
|
||||
fn = ":/placeHolder/images/empty_image.png";
|
||||
}
|
||||
|
||||
bool b = pvt->loadImage( channel, fn );
|
||||
bool b = pvt->loadImage( channel, filename );
|
||||
if( !b )
|
||||
return false;
|
||||
|
||||
|
@ -346,6 +361,11 @@ QString TileItemNode::getTileFilename(TileConstants::TTileChannel channel)
|
|||
return itr.value();
|
||||
}
|
||||
|
||||
bool TileItemNode::loadEmptyPixmap()
|
||||
{
|
||||
return TileItemNodePvt::loadEmptyImage();
|
||||
}
|
||||
|
||||
QVariant TileItemNode::data(int column, int role) const
|
||||
{
|
||||
QString tileFilename = m_tileFilename[ TileItemNode::s_displayChannel ];
|
||||
|
|
|
@ -117,6 +117,7 @@ public:
|
|||
|
||||
static void setDisplayChannel( TileConstants::TTileChannel channel ){ s_displayChannel = channel; }
|
||||
static TileConstants::TTileChannel displayChannel(){ return s_displayChannel; }
|
||||
static bool loadEmptyPixmap();
|
||||
|
||||
QVariant pixmap( TileConstants::TTileChannel channel ) const;
|
||||
|
||||
|
|
Loading…
Reference in a new issue