From 66c8b95e2d1e87476bd6f5c3d15577ddad9c7cd8 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Fri, 1 Aug 2014 02:34:57 +0200 Subject: [PATCH] Don't reload the pixmaps every time they are displayed... -.- --- .../src/plugins/tile_editor/tile_item.cpp | 64 +++++++++++++++---- .../src/plugins/tile_editor/tile_item.h | 6 +- .../src/plugins/tile_editor/tile_model.h | 1 + 3 files changed, 59 insertions(+), 12 deletions(-) diff --git a/code/studio/src/plugins/tile_editor/tile_item.cpp b/code/studio/src/plugins/tile_editor/tile_item.cpp index d2fa3793f..b9064996e 100644 --- a/code/studio/src/plugins/tile_editor/tile_item.cpp +++ b/code/studio/src/plugins/tile_editor/tile_item.cpp @@ -264,23 +264,71 @@ void TileTypeNode::reindex() /////////////////////////////////////////////////// + +class TileItemNodePvt +{ +public: + + bool loadImage( TileModel::TTileChannel channel, const QString &fn ) + { + QPixmap temp; + bool b = temp.load( fn ); + + if( !b ) + return false; + + pixmaps[ channel ] = temp; + + return true; + } + + void clearImage( TileModel::TTileChannel channel ) + { + pixmaps[ channel ] = QPixmap(); + } + + const QPixmap& pixMap( TileModel::TTileChannel channel ) const{ + return pixmaps[ channel ]; + } + +private: + QPixmap pixmaps[ TileModel::TileChannelCount ]; + +}; + TileModel::TTileChannel TileItemNode::s_displayChannel = TileModel::TileDiffuse; TileItemNode::TileItemNode(int tileId, TileModel::TTileChannel channel, QString filename, Node *parent) : m_tileId(tileId) { - m_tileFilename[channel] = filename; m_parentItem = parent; //nlinfo("dispalying tile %d - %s", m_tileId, m_tileFilename[TileModel::TileDiffuse].toAscii().data()); + + pvt = new TileItemNodePvt(); + + setTileFilename( channel, filename ); } TileItemNode::~TileItemNode() { + delete pvt; + pvt = NULL; + qDeleteAll(m_childItems); } -void TileItemNode::setTileFilename(TileModel::TTileChannel channel, QString filename) +bool TileItemNode::setTileFilename(TileModel::TTileChannel channel, QString filename) { + QString fn = filename; + + if( filename.isEmpty() || ( filename == "empty" ) ) + fn = ":/placeHolder/images/empty_image.png"; + + bool b = pvt->loadImage( channel, fn ); + if( !b ) + return false; + m_tileFilename[channel] = filename; + return true; } QString TileItemNode::getTileFilename(TileModel::TTileChannel channel) @@ -295,8 +343,7 @@ QString TileItemNode::getTileFilename(TileModel::TTileChannel channel) QVariant TileItemNode::data(int column, int role) const { - // find some way to know which file/bitmap to display - QString tileFilename = m_tileFilename[s_displayChannel]; + QString tileFilename = m_tileFilename[ TileItemNode::s_displayChannel ]; if(role == TileModel::TilePixmapRole || role == Qt::DecorationRole) { @@ -307,18 +354,13 @@ QVariant TileItemNode::data(int column, int role) const // Retrieve the target tile size. uint32 tileSize = TileModel::getTileTypeSize(parent->getTileType()); - if(tileFilename.isEmpty() || tileFilename == "empty") - tileFilename = ":/placeHolder/images/empty_image.png"; - - QPixmap pixmap;// = new QPixmap(); - if(!pixmap.load(tileFilename)) - nlinfo("failed to load %s", tileFilename.toAscii().data()); - if(TileModel::CurrentZoomFactor == TileModel::TileZoom200) tileSize *= 2; else if(TileModel::CurrentZoomFactor == TileModel::TileZoom50) tileSize /= 2; + QPixmap pixmap = pvt->pixMap( TileItemNode::s_displayChannel ); + pixmap.scaled(tileSize, tileSize); return pixmap; diff --git a/code/studio/src/plugins/tile_editor/tile_item.h b/code/studio/src/plugins/tile_editor/tile_item.h index 5c5f8017c..611059ffa 100644 --- a/code/studio/src/plugins/tile_editor/tile_item.h +++ b/code/studio/src/plugins/tile_editor/tile_item.h @@ -104,6 +104,8 @@ private: TileModel::TNodeTileType m_nodeTileType; }; +class TileItemNodePvt; + class TileItemNode : public Node { public: @@ -111,7 +113,7 @@ public: virtual ~TileItemNode(); QVariant data(int column, int role) const; int columnCount() const; - void setTileFilename(TileModel::TTileChannel channel, QString filename); + bool setTileFilename(TileModel::TTileChannel channel, QString filename); QString getTileFilename(TileModel::TTileChannel channel); void setId( int id ){ m_tileId = id; } int id() const{ return m_tileId; } @@ -125,6 +127,8 @@ private: QMap m_tileWidget; static TileModel::TTileChannel s_displayChannel; + + TileItemNodePvt *pvt; }; #endif // TILE_ITEM_H diff --git a/code/studio/src/plugins/tile_editor/tile_model.h b/code/studio/src/plugins/tile_editor/tile_model.h index f2efdb8d4..e855f8871 100644 --- a/code/studio/src/plugins/tile_editor/tile_model.h +++ b/code/studio/src/plugins/tile_editor/tile_model.h @@ -34,6 +34,7 @@ public: TileDiffuse = 0, TileAdditive = 1, TileAlpha = 2, + TileChannelCount = 3 }; enum TNodeTileType