You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
1.4 KiB
C++

/*!
\file common.cpp
*/
#include "common.h"
#include <QBuffer>
#include <QDir>
QImage blob2Image(const QByteArray& ba)
{
QImage image;
if(!ba.isEmpty())
{
if(!image.loadFromData(ba))
myDebug << "image load error.";
}
return(image);
}
QByteArray image2Blob(const QImage &image)
{
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
image.save(&buffer, "JPG");
buffer.close();
return(ba);
}
void insertPath(QString szPath, QStandardItem* lpRootItem)
{
if(!lpRootItem)
return;
QString szPath1 = szPath.replace("\\", "/");
QStringList szPathList = szPath1.split("/");
QStandardItem* lpCurRoot = lpRootItem;
int path;
bool bFound;
szPath1 = "";
for(path = 0;path < szPathList.count();path++)
{
bFound = false;
for(int x = 0;x < lpCurRoot->rowCount();x++)
{
QStandardItem* lpCurItem = lpCurRoot->child(x, 0);
if(!lpCurItem->text().compare(szPathList[path], Qt::CaseInsensitive))
{
lpCurRoot = lpCurItem;
bFound = true;
break;
}
}
if(!bFound)
break;
szPath1.append(szPathList[path]+QDir::separator());
}
for(;path < szPathList.count();path++)
{
szPath1.append(szPathList[path]);
QStandardItem* lpNewItem = new QStandardItem(szPathList[path]);
lpCurRoot->appendRow(lpNewItem);
lpNewItem->setData(QVariant::fromValue(szPath1), Qt::UserRole+2);
szPath1.append(QDir::separator());
lpCurRoot = lpNewItem;
}
}