Skip to content

Commit

Permalink
Qt 5 API changes and missing includes
Browse files Browse the repository at this point in the history
  • Loading branch information
peterlama committed Feb 19, 2014
1 parent 40a4a50 commit a60446c
Show file tree
Hide file tree
Showing 158 changed files with 1,222 additions and 934 deletions.
9 changes: 9 additions & 0 deletions src/Base/Handle.cpp
Expand Up @@ -46,8 +46,13 @@ Handled::Handled()

Handled::~Handled()
{
#if QT_VERSION >= 0x050000
if (_lRefCount->load() != 0)
#else
if ((int)(*_lRefCount) != 0)
#endif
throw Exception("Reference counter of deleted object is not zero!!!!!\n");

delete _lRefCount;
}

Expand All @@ -66,7 +71,11 @@ void Handled::unref() const

int Handled::getRefCount(void) const
{
#if QT_VERSION >= 0x050000
return _lRefCount->load();
#else
return (int)(*_lRefCount);
#endif
}

const Handled& Handled::operator = (const Handled&)
Expand Down
2 changes: 1 addition & 1 deletion src/Base/UnitsApi.cpp
Expand Up @@ -135,7 +135,7 @@ QString UnitsApi::schemaTranslate(Base::Quantity quant,double &factor,QString &u
double UnitsApi::toDbl(PyObject *ArgObj,const Base::Unit &u)
{
if (PyString_Check(ArgObj))
QString str = QString::fromAscii(PyString_AsString(ArgObj));
QString str = QString::fromLatin1(PyString_AsString(ArgObj));
else if (PyFloat_Check(ArgObj))
double d = PyFloat_AsDouble(ArgObj);
else if (PyInt_Check(ArgObj))
Expand Down
6 changes: 3 additions & 3 deletions src/Base/Uuid.cpp
Expand Up @@ -68,21 +68,21 @@ std::string Uuid::createUuid(void)
QString uuid = QUuid::createUuid().toString();
uuid = uuid.mid(1);
uuid.chop(1);
Uuid = (const char*)uuid.toAscii();
Uuid = (const char*)uuid.toLatin1();
return Uuid;
}

void Uuid::setValue(const char* sString)
{
if (sString) {
QUuid uuid(QString::fromAscii(sString));
QUuid uuid(QString::fromLatin1(sString));
if (uuid.isNull())
throw std::runtime_error("invalid uuid");
// remove curly braces
QString id = uuid.toString();
id = id.mid(1);
id.chop(1);
_uuid = (const char*)id.toAscii();
_uuid = (const char*)id.toLatin1();
}
}

Expand Down
19 changes: 10 additions & 9 deletions src/Gui/Action.cpp
Expand Up @@ -34,6 +34,7 @@
# include <QTimer>
# include <QToolBar>
# include <QToolButton>
# include <QAbstractItemView>
#endif

#include "Action.h"
Expand All @@ -59,15 +60,15 @@ using namespace Gui::Dialog;
Action::Action (Command* pcCmd, QObject * parent)
: QObject(parent), _action(new QAction( this )), _pcCmd(pcCmd)
{
_action->setObjectName(QString::fromAscii(_pcCmd->getName()));
_action->setObjectName(QString::fromLatin1(_pcCmd->getName()));
connect(_action, SIGNAL(triggered(bool)), this, SLOT(onActivated()));
}

Action::Action (Command* pcCmd, QAction* action, QObject * parent)
: QObject(parent), _action(action), _pcCmd(pcCmd)
{
_action->setParent(this);
_action->setObjectName(QString::fromAscii(_pcCmd->getName()));
_action->setObjectName(QString::fromLatin1(_pcCmd->getName()));
connect(_action, SIGNAL(triggered(bool)), this, SLOT(onActivated()));
}

Expand Down Expand Up @@ -512,7 +513,7 @@ void WorkbenchGroup::addTo(QWidget *w)

void WorkbenchGroup::refreshWorkbenchList()
{
QString active = QString::fromAscii(WorkbenchManager::instance()->active()->name().c_str());
QString active = QString::fromLatin1(WorkbenchManager::instance()->active()->name().c_str());
QStringList items = Application::Instance->workbenches();

QList<QAction*> workbenches = _group->actions();
Expand Down Expand Up @@ -568,7 +569,7 @@ void WorkbenchGroup::slotAddWorkbench(const char* name)
QList<QAction*> workbenches = _group->actions();
for (QList<QAction*>::Iterator it = workbenches.begin(); it != workbenches.end(); ++it) {
if (!(*it)->isVisible()) {
QString wb = QString::fromAscii(name);
QString wb = QString::fromLatin1(name);
QPixmap px = Application::Instance->workbenchIcon(wb);
QString text = Application::Instance->workbenchMenuText(wb);
QString tip = Application::Instance->workbenchToolTip(wb);
Expand All @@ -585,7 +586,7 @@ void WorkbenchGroup::slotAddWorkbench(const char* name)

void WorkbenchGroup::slotRemoveWorkbench(const char* name)
{
QString workbench = QString::fromAscii(name);
QString workbench = QString::fromLatin1(name);
QList<QAction*> workbenches = _group->actions();
for (QList<QAction*>::Iterator it = workbenches.begin(); it != workbenches.end(); ++it) {
if ((*it)->objectName() == workbench) {
Expand Down Expand Up @@ -638,7 +639,7 @@ void RecentFilesAction::setFiles(const QStringList& files)
int numRecentFiles = std::min<int>(recentFiles.count(), files.count());
for (int index = 0; index < numRecentFiles; index++) {
QFileInfo fi(files[index]);
recentFiles[index]->setText(QString::fromAscii("&%1 %2").arg(index+1).arg(fi.fileName()));
recentFiles[index]->setText(QString::fromLatin1("&%1 %2").arg(index+1).arg(fi.fileName()));
recentFiles[index]->setStatusTip(tr("Open file %1").arg(files[index]));
recentFiles[index]->setToolTip(files[index]); // set the full name that we need later for saving
recentFiles[index]->setData(QVariant(index));
Expand Down Expand Up @@ -689,7 +690,7 @@ void RecentFilesAction::activateFile(int id)
// invokes appendFile()
SelectModule::Dict dict = SelectModule::importHandler(filename);
for (SelectModule::Dict::iterator it = dict.begin(); it != dict.end(); ++it) {
Application::Instance->open(it.key().toUtf8(), it.value().toAscii());
Application::Instance->open(it.key().toUtf8(), it.value().toLatin1());
break;
}
}
Expand Down Expand Up @@ -739,11 +740,11 @@ void RecentFilesAction::save()
QList<QAction*> recentFiles = _group->actions();
int num = std::min<int>(count, recentFiles.count());
for (int index = 0; index < num; index++) {
QString key = QString::fromAscii("MRU%1").arg(index);
QString key = QString::fromLatin1("MRU%1").arg(index);
QString value = recentFiles[index]->toolTip();
if (value.isEmpty())
break;
hGrp->SetASCII(key.toAscii(), value.toUtf8());
hGrp->SetASCII(key.toLatin1(), value.toUtf8());
}
}

Expand Down
50 changes: 31 additions & 19 deletions src/Gui/Application.cpp
Expand Up @@ -43,6 +43,7 @@
# include <QSessionManager>
# include <QTextStream>
#endif
# include <QStatusBar>

#include <boost/interprocess/sync/file_lock.hpp>

Expand Down Expand Up @@ -332,7 +333,7 @@ Application::Application(bool GUIenabled)
ParameterGrp::handle hPGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp");
hPGrp = hPGrp->GetGroup("Preferences")->GetGroup("General");
QString lang = QLocale::languageToString(QLocale::system().language());
Translator::instance()->activateLanguage(hPGrp->GetASCII("Language", (const char*)lang.toAscii()).c_str());
Translator::instance()->activateLanguage(hPGrp->GetASCII("Language", (const char*)lang.toLatin1()).c_str());
GetWidgetFactorySupplier();

ParameterGrp::handle hUnits = App::GetApplication().GetParameterGroupByPath
Expand Down Expand Up @@ -1005,7 +1006,7 @@ bool Application::activateWorkbench(const char* name)
ok = true; // already active
// now try to create and activate the matching workbench object
else if (WorkbenchManager::instance()->activate(name, type)) {
getMainWindow()->activateWorkbench(QString::fromAscii(name));
getMainWindow()->activateWorkbench(QString::fromLatin1(name));
this->signalActivateWorkbench(name);
ok = true;
}
Expand Down Expand Up @@ -1050,7 +1051,7 @@ bool Application::activateWorkbench(const char* name)
}
catch (Py::Exception&) {
Base::PyException e; // extract the Python error text
QString msg = QString::fromAscii(e.what());
QString msg = QString::fromLatin1(e.what());
QRegExp rx;
// ignore '<type 'exceptions.ImportError'>' prefixes
rx.setPattern(QLatin1String("^\\s*<type 'exceptions.ImportError'>:\\s*"));
Expand All @@ -1060,7 +1061,7 @@ bool Application::activateWorkbench(const char* name)
pos = rx.indexIn(msg);
}

Base::Console().Error("%s\n", (const char*)msg.toAscii());
Base::Console().Error("%s\n", (const char*)msg.toLatin1());
Base::Console().Log("%s\n", e.getStackTrace().c_str());
if (!d->startingUp) {
wc.restoreCursor();
Expand All @@ -1077,7 +1078,7 @@ QPixmap Application::workbenchIcon(const QString& wb) const
{
Base::PyGILStateLocker lock;
// get the python workbench object from the dictionary
PyObject* pcWorkbench = PyDict_GetItemString(_pcWorkbenchDictionary, wb.toAscii());
PyObject* pcWorkbench = PyDict_GetItemString(_pcWorkbenchDictionary, wb.toLatin1());
// test if the workbench exists
if (pcWorkbench) {
// make a unique icon name
Expand Down Expand Up @@ -1150,7 +1151,7 @@ QString Application::workbenchToolTip(const QString& wb) const
{
// get the python workbench object from the dictionary
Base::PyGILStateLocker lock;
PyObject* pcWorkbench = PyDict_GetItemString(_pcWorkbenchDictionary, wb.toAscii());
PyObject* pcWorkbench = PyDict_GetItemString(_pcWorkbenchDictionary, wb.toLatin1());
// test if the workbench exists
if (pcWorkbench) {
// get its ToolTip member if possible
Expand All @@ -1174,7 +1175,7 @@ QString Application::workbenchMenuText(const QString& wb) const
{
// get the python workbench object from the dictionary
Base::PyGILStateLocker lock;
PyObject* pcWorkbench = PyDict_GetItemString(_pcWorkbenchDictionary, wb.toAscii());
PyObject* pcWorkbench = PyDict_GetItemString(_pcWorkbenchDictionary, wb.toLatin1());
// test if the workbench exists
if (pcWorkbench) {
// get its ToolTip member if possible
Expand Down Expand Up @@ -1205,13 +1206,13 @@ QStringList Application::workbenches(void) const
const char* start = (st != config.end() ? st->second.c_str() : "<none>");
QStringList hidden, extra;
if (ht != config.end()) {
QString items = QString::fromAscii(ht->second.c_str());
QString items = QString::fromLatin1(ht->second.c_str());
hidden = items.split(QLatin1Char(';'), QString::SkipEmptyParts);
if (hidden.isEmpty())
hidden.push_back(QLatin1String(""));
}
if (et != config.end()) {
QString items = QString::fromAscii(et->second.c_str());
QString items = QString::fromLatin1(et->second.c_str());
extra = items.split(QLatin1Char(';'), QString::SkipEmptyParts);
if (extra.isEmpty())
extra.push_back(QLatin1String(""));
Expand All @@ -1227,18 +1228,18 @@ QStringList Application::workbenches(void) const
// add only allowed workbenches
bool ok = true;
if (!extra.isEmpty()&&ok) {
ok = (extra.indexOf(QString::fromAscii(wbName)) != -1);
ok = (extra.indexOf(QString::fromLatin1(wbName)) != -1);
}
if (!hidden.isEmpty()&&ok) {
ok = (hidden.indexOf(QString::fromAscii(wbName)) == -1);
ok = (hidden.indexOf(QString::fromLatin1(wbName)) == -1);
}

// okay the item is visible
if (ok)
wb.push_back(QString::fromAscii(wbName));
wb.push_back(QString::fromLatin1(wbName));
// also allow start workbench in case it is hidden
else if (strcmp(wbName, start) == 0)
wb.push_back(QString::fromAscii(wbName));
wb.push_back(QString::fromLatin1(wbName));
}

return wb;
Expand Down Expand Up @@ -1383,7 +1384,7 @@ void messageHandler(QtMsgType type, const char *msg)
Base::Console().Error("%s\n", msg);
abort(); // deliberately core dump
}
#ifdef FC_OS_WIN32
#if defined(FC_OS_WIN32) && QT_VERSION < 0x050000
if (old_qtmsg_handler)
(*old_qtmsg_handler)(type, msg);
#endif
Expand All @@ -1393,6 +1394,13 @@ void messageHandler(QtMsgType type, const char *msg)
#endif
}

#if QT_VERSION >= 0x050000
void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
messageHandler(type, msg.toLocal8Bit().constData());
}
#endif

#ifdef FC_DEBUG // redirect Coin messages to FreeCAD
void messageHandlerCoin(const SoError * error, void * userdata)
{
Expand All @@ -1411,7 +1419,7 @@ void messageHandlerCoin(const SoError * error, void * userdata)
Base::Console().Error("%s\n", msg);
break;
}
#ifdef FC_OS_WIN32
#if defined(FC_OS_WIN32) && QT_VERSION < 0x050000
if (old_qtmsg_handler)
(*old_qtmsg_handler)(QtDebugMsg, msg);
#endif
Expand Down Expand Up @@ -1442,7 +1450,11 @@ void Application::initApplication(void)
initTypes();
new Base::ScriptProducer( "FreeCADGuiInit", FreeCADGuiInit );
init_resources();
old_qtmsg_handler = qInstallMsgHandler(messageHandler);
#if QT_VERSION >= 0x050000
qInstallMessageHandler(messageHandler);
#else
old_qtmsg_handler = qInstallMsgHandler(messageHandler);
#endif
}
catch (...) {
// force to flush the log
Expand Down Expand Up @@ -1720,7 +1732,7 @@ void Application::runApplication(void)
// if the auto workbench is not visible then force to use the default workbech
// and replace the wrong entry in the parameters
QStringList wb = app.workbenches();
if (!wb.contains(QString::fromAscii(start.c_str()))) {
if (!wb.contains(QString::fromLatin1(start.c_str()))) {
start = App::Application::Config()["StartWorkbench"];
App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/General")->
SetASCII("AutoloadModule", start.c_str());
Expand Down Expand Up @@ -1816,11 +1828,11 @@ void Application::runApplication(void)
void Application::checkForPreviousCrashes()
{
QDir tmp = QDir::temp();
tmp.setNameFilters(QStringList() << QString::fromAscii("*.lock"));
tmp.setNameFilters(QStringList() << QString::fromLatin1("*.lock"));
tmp.setFilter(QDir::Files);

QList<QFileInfo> restoreDocFiles;
QString exeName = QString::fromAscii(App::GetApplication().getExecutableName());
QString exeName = QString::fromLatin1(App::GetApplication().getExecutableName());
QList<QFileInfo> locks = tmp.entryInfoList();
for (QList<QFileInfo>::iterator it = locks.begin(); it != locks.end(); ++it) {
QString bn = it->baseName();
Expand Down
23 changes: 13 additions & 10 deletions src/Gui/BitmapFactory.cpp
Expand Up @@ -85,8 +85,8 @@ BitmapFactoryInst& BitmapFactoryInst::instance(void)
}
_pcSingleton->addPath(path);
}
_pcSingleton->addPath(QString::fromAscii("%1/icons").arg(QString::fromUtf8(App::GetApplication().GetHomePath())));
_pcSingleton->addPath(QString::fromAscii("%1/icons").arg(QString::fromUtf8(App::GetApplication().Config()["UserAppData"].c_str())));
_pcSingleton->addPath(QString::fromLatin1("%1/icons").arg(QString::fromUtf8(App::GetApplication().GetHomePath())));
_pcSingleton->addPath(QString::fromLatin1("%1/icons").arg(QString::fromUtf8(App::GetApplication().Config()["UserAppData"].c_str())));
_pcSingleton->addPath(QLatin1String(":/icons/"));
_pcSingleton->addPath(QLatin1String(":/Icons/"));

Expand Down Expand Up @@ -150,7 +150,7 @@ QStringList BitmapFactoryInst::findIconFiles() const
QStringList files, filters;
QList<QByteArray> formats = QImageReader::supportedImageFormats();
for (QList<QByteArray>::iterator it = formats.begin(); it != formats.end(); ++it)
filters << QString::fromAscii("*.%1").arg(QString::fromAscii(*it).toLower());
filters << QString::fromLatin1("*.%1").arg(QString::fromLatin1(*it).toLower());

QStringList paths = d->paths;
#if QT_VERSION >= 0x040500
Expand Down Expand Up @@ -253,8 +253,8 @@ QPixmap BitmapFactoryInst::pixmap(const char* name) const
else {
// Go through supported file formats
for (QList<QByteArray>::iterator fm = formats.begin(); fm != formats.end(); ++fm) {
QString path = QString::fromAscii("%1.%2").arg(fileName).
arg(QString::fromAscii((*fm).toLower().constData()));
QString path = QString::fromLatin1("%1.%2").arg(fileName).
arg(QString::fromLatin1((*fm).toLower().constData()));
if (loadPixmap(path, icon)) {
found = true;
break;
Expand Down Expand Up @@ -318,8 +318,8 @@ QPixmap BitmapFactoryInst::pixmapFromSvg(const QByteArray& contents, const QSize
QPalette pal = webView.palette();
pal.setColor(QPalette::Background, Qt::transparent);
webView.setPalette(pal);
webView.setContent(contents, QString::fromAscii("image/svg+xml"));
QString node = QString::fromAscii("document.rootElement.nodeName");
webView.setContent(contents, QString::fromLatin1("image/svg+xml"));
QString node = QString::fromLatin1("document.rootElement.nodeName");
QWebFrame* frame = webView.page()->mainFrame();
if (!frame) {
return QPixmap();
Expand All @@ -330,8 +330,8 @@ QPixmap BitmapFactoryInst::pixmapFromSvg(const QByteArray& contents, const QSize
return QPixmap();
}

QString w = QString::fromAscii("document.rootElement.width.baseVal.value");
QString h = QString::fromAscii("document.rootElement.height.baseVal.value");
QString w = QString::fromLatin1("document.rootElement.width.baseVal.value");
QString h = QString::fromLatin1("document.rootElement.height.baseVal.value");
double ww = frame->evaluateJavaScript(w).toDouble();
double hh = frame->evaluateJavaScript(h).toDouble();
if (ww == 0.0 || hh == 0.0)
Expand Down Expand Up @@ -545,8 +545,11 @@ void BitmapFactoryInst::convert(const QImage& p, SoSFImage& img) const
SbVec2s size;
size[0] = p.width();
size[1] = p.height();

#if QT_VERSION >= 0x050000
int buffersize = p.byteCount();
#else
int buffersize = p.numBytes();
#endif
int numcomponents = buffersize / ( size[0] * size[1] );

// allocate image data
Expand Down

0 comments on commit a60446c

Please sign in to comment.