Here is my getPixmap function
//=============================================================================
//=============================================================================
int width,
int height)
{
ZeLog::get()->Print("ZePixmapManager - getPixmap 2 %s %d %d\n",
pixmapName.toStdString().c_str(), width, height);
if (tempPixmap.isNull())
{
tempPixmap
= QPixmap(PICTURE_DEFAULT
);
pixmapName = PICTURE_DEFAULT;
}
for (unsigned int i = 0; i < mPixmapItem.size(); i++)
{
if (mPixmapItem[i]->getPixmapName() == pixmapName
&&
mPixmapItem[i]->width() == width
&&
mPixmapItem[i]->height() == height)
{
ZeLog::get()->Print("ZePixmapManager - Pixmap already exists\n");
mPixmapItem[i]->addInstance();
return mPixmapItem[i]->getPixmap();
}
}
ZePixmapItem * pixmapItem = new ZePixmapItem(pixmapName,
tempPixmap.
scaled(width, height,
Qt::IgnoreAspectRatio,
Qt::SmoothTransformation));
mPixmapItem.push_back(pixmapItem);
ZeLog::get()->Print("ZePixmapManager - getPixmap %d %d\n",
pixmapItem->getPixmap().width(),
pixmapItem->getPixmap().height());
return pixmapItem->getPixmap();
//=============================================================================
//=============================================================================
QPixmap & ZePixmapManager::getPixmap(QString & pixmapName,
const QPixmap & pixmap,
int width,
int height)
{
ZeLog::get()->Print("ZePixmapManager - getPixmap 2 %s %d %d\n",
pixmapName.toStdString().c_str(), width, height);
QPixmap tempPixmap(pixmap);
if (tempPixmap.isNull())
{
tempPixmap = QPixmap(PICTURE_DEFAULT);
pixmapName = PICTURE_DEFAULT;
}
for (unsigned int i = 0; i < mPixmapItem.size(); i++)
{
if (mPixmapItem[i]->getPixmapName() == pixmapName
&&
mPixmapItem[i]->width() == width
&&
mPixmapItem[i]->height() == height)
{
ZeLog::get()->Print("ZePixmapManager - Pixmap already exists\n");
mPixmapItem[i]->addInstance();
return mPixmapItem[i]->getPixmap();
}
}
ZePixmapItem * pixmapItem = new ZePixmapItem(pixmapName,
tempPixmap.
scaled(width, height,
Qt::IgnoreAspectRatio,
Qt::SmoothTransformation));
mPixmapItem.push_back(pixmapItem);
ZeLog::get()->Print("ZePixmapManager - getPixmap %d %d\n",
pixmapItem->getPixmap().width(),
pixmapItem->getPixmap().height());
return pixmapItem->getPixmap();
To copy to clipboard, switch view to plain text mode
}
and my delete pixmap :
//=============================================================================
//=============================================================================
bool ZePixmapManager
::DeletePixmap(const QString & pixmapName,
{
ZeLog::get()->Print("ZePixmapManager - DeletePixmap %d %s %d %d\n",
mPixmapItem.size(),
pixmapName.toStdString().c_str(),
pixmap.width(),
pixmap.height());
for (unsigned int i = 0; i < mPixmapItem.size(); i++)
{
if (mPixmapItem[i]->getPixmapName() == pixmapName
&&
mPixmapItem[i]->width() == pixmap.width()
&&
mPixmapItem[i]->height() == pixmap.height())
{
ZeLog::get()->Print("ZePixmapManager - DeletePixmap instance %d\n",
mPixmapItem[i]->getInstance());
mPixmapItem[i]->deleteInstance();
if (mPixmapItem[i]->getInstance() == 0)
{
ZeLog::get()->Print("ZePixmapManager - DeletePixmap complete\n");
delete mPixmapItem[i];
mPixmapItem.remove(i);
}
return true;
}
}
return false;
}
//=============================================================================
//=============================================================================
bool ZePixmapManager::DeletePixmap(const QString & pixmapName,
const QPixmap & pixmap)
{
ZeLog::get()->Print("ZePixmapManager - DeletePixmap %d %s %d %d\n",
mPixmapItem.size(),
pixmapName.toStdString().c_str(),
pixmap.width(),
pixmap.height());
for (unsigned int i = 0; i < mPixmapItem.size(); i++)
{
if (mPixmapItem[i]->getPixmapName() == pixmapName
&&
mPixmapItem[i]->width() == pixmap.width()
&&
mPixmapItem[i]->height() == pixmap.height())
{
ZeLog::get()->Print("ZePixmapManager - DeletePixmap instance %d\n",
mPixmapItem[i]->getInstance());
mPixmapItem[i]->deleteInstance();
if (mPixmapItem[i]->getInstance() == 0)
{
ZeLog::get()->Print("ZePixmapManager - DeletePixmap complete\n");
delete mPixmapItem[i];
mPixmapItem.remove(i);
}
return true;
}
}
return false;
}
To copy to clipboard, switch view to plain text mode
And here is my pixmap item :
//=============================================================================
//=============================================================================
// ZePixmapItem
//=============================================================================
//=============================================================================
ZePixmapItem
::ZePixmapItem(const QString & pixmapName,
mPixmapName(pixmapName),
mPixmap(pixmap)
{
mWidth = mPixmap.width();
mHeight = mPixmap.height();
mInstance = 0;
addInstance();
}
//=============================================================================
//=============================================================================
ZePixmapItem::~ZePixmapItem()
{
}
//=============================================================================
//=============================================================================
void ZePixmapItem::addInstance()
{
mInstance++;
}
//=============================================================================
//=============================================================================
void ZePixmapItem::deleteInstance()
{
mInstance--;
}
//=============================================================================
//=============================================================================
// ZePixmapItem
//=============================================================================
//=============================================================================
ZePixmapItem::ZePixmapItem(const QString & pixmapName,
const QPixmap & pixmap) :
mPixmapName(pixmapName),
mPixmap(pixmap)
{
mWidth = mPixmap.width();
mHeight = mPixmap.height();
mInstance = 0;
addInstance();
}
//=============================================================================
//=============================================================================
ZePixmapItem::~ZePixmapItem()
{
}
//=============================================================================
//=============================================================================
void ZePixmapItem::addInstance()
{
mInstance++;
}
//=============================================================================
//=============================================================================
void ZePixmapItem::deleteInstance()
{
mInstance--;
}
To copy to clipboard, switch view to plain text mode
Bookmarks