Skip to content

Commit

Permalink
deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
julianschick committed Feb 23, 2020
1 parent a80f790 commit 875ac0d
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 40 deletions.
31 changes: 18 additions & 13 deletions src/db/interface/DefaultInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ DefaultInterface::DefaultInterface (const DatabaseInfo &dbInfo, int readTimeout)
connect (proxy, SIGNAL (readResumed ()), this, SIGNAL (readResumed ()), Qt::DirectConnection);

QString name=qnotr ("startkladde_defaultInterface_%1").arg (getFreeNumber ());
//std::cout << "Create db " << name << std::endl;

db=QSqlDatabase::addDatabase (notr ("QMYSQL"), name);
threadId=QThread::currentThreadId ();
Expand All @@ -101,8 +100,6 @@ DefaultInterface::~DefaultInterface ()

// Make sure the QSqlDatabase instance is destroyed before removing it
db=QSqlDatabase ();

//std::cout << "remove db " << name << std::endl;
QSqlDatabase::removeDatabase (name);

delete proxy;
Expand Down Expand Up @@ -177,9 +174,12 @@ void DefaultInterface::openImpl ()
// Failed due to error
QSqlError error=db.lastError ();
std::cout << error.databaseText () << std::endl;
emit databaseError (error.number (), error.databaseText ());

switch (error.number ())
int number = extractNativeErrorNumber(error);

emit databaseError (number, error.databaseText ());

switch (number)
{
case CR_CONN_HOST_ERROR: break; // Retry
case CR_UNKNOWN_HOST: break; // Retry
Expand Down Expand Up @@ -301,9 +301,10 @@ bool DefaultInterface::doTransactionStatement (TransactionStatement statement)
// Failed due to error
QSqlError error=db.lastError ();
if (displayQueries) std::cout << error.databaseText () << std::endl;
emit databaseError (error.number (), error.databaseText ());
int number = extractNativeErrorNumber(error);
emit databaseError (number, error.databaseText ());

if (!retryOnQueryError (error.number ()))
if (!retryOnQueryError (number))
throw TransactionFailedException (error, statement);

return false;
Expand Down Expand Up @@ -377,9 +378,10 @@ QSqlQuery DefaultInterface::executeQueryImpl (const Query &query, bool forwardOn
}
catch (QueryFailedException &ex)
{
if (!retryOnQueryError (ex.error.number ()))
int number = extractNativeErrorNumber(ex.error);
if (!retryOnQueryError (number))
{
switch (ex.error.number ())
switch (number)
{
case ER_ACCESS_DENIED_ERROR: throw AccessDeniedException (ex.error);
case ER_DBACCESS_DENIED_ERROR: throw AccessDeniedException (ex.error);
Expand Down Expand Up @@ -441,9 +443,10 @@ QSqlQuery DefaultInterface::doExecuteQuery (const Query &query, bool forwardOnly
else
{
QSqlError error=sqlQuery.lastError ();
int number = extractNativeErrorNumber(error);
if (displayQueries)
std::cout << error.databaseText () << std::endl;
emit databaseError (error.number (), error.databaseText ());
emit databaseError (number, error.databaseText ());

throw QueryFailedException::prepare (error, query);
}
Expand All @@ -465,9 +468,10 @@ QSqlQuery DefaultInterface::doExecuteQuery (const Query &query, bool forwardOnly
else
{
QSqlError error=sqlQuery.lastError ();
int number = extractNativeErrorNumber(error);
if (displayQueries)
std::cout << error.databaseText () << std::endl;
emit databaseError (error.number (), error.databaseText ());
emit databaseError (number, error.databaseText ());

throw QueryFailedException::execute (error, query);
}
Expand Down Expand Up @@ -530,10 +534,11 @@ void DefaultInterface::ping ()
{
// Failed due to error
QSqlError error=sqlQuery.lastError ();
int number = extractNativeErrorNumber(error);
if (display) std::cout << error.databaseText () << std::endl;
emit databaseError (error.number (), error.databaseText ());
emit databaseError (number, error.databaseText ());

if (!retryOnQueryError (error.number ()))
if (!retryOnQueryError (number))
throw PingFailedException (error);
}

Expand Down
2 changes: 1 addition & 1 deletion src/db/interface/DefaultInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class DefaultInterface: public QObject, public Interface

signals:
void executingQuery (Query query);
void databaseError (int number, QString message);
void databaseError (int number, QString message);

void readTimeout ();
void readResumed ();
Expand Down
15 changes: 13 additions & 2 deletions src/db/interface/Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ void Interface::createIndex (const IndexSpec &index, bool skipIfExists)
// TODO: better check if the index exists before creating, don't
// execute the query at all in this case (also, this currently emits
// an error message)
if (skipIfExists && ex.error.number ()==ER_DUP_KEYNAME)
int number = extractNativeErrorNumber(ex.error);
if (skipIfExists && number == ER_DUP_KEYNAME)
std::cout << qnotr ("Skipping existing index %1.%2").arg (index.getTable (), index.getName ()) << std::endl;
else
throw;
Expand All @@ -346,7 +347,8 @@ void Interface::dropIndex (const QString &table, const QString &name, bool skipI
}
catch (QueryFailedException &ex)
{
if (skipIfNotExists && ex.error.number ()==ER_CANT_DROP_FIELD_OR_KEY)
int number = extractNativeErrorNumber(ex.error);
if (skipIfNotExists && number == ER_CANT_DROP_FIELD_OR_KEY)
std::cout << qnotr ("Skipping non-existing index %1.%2").arg (table, name) << std::endl;
else
throw;
Expand Down Expand Up @@ -405,3 +407,12 @@ QString Interface::mysqlPasswordHash (const QString &password)

return qnotr ("*%1").arg (QString (data.toHex ()).toUpper ());
}

int Interface::extractNativeErrorNumber(QSqlError& error) {
bool ok = false;
int number = error.nativeErrorCode().toInt(&ok);
if (!ok) {
number = -1;
}
return number;
}
1 change: 1 addition & 0 deletions src/db/interface/Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class Interface: public AbstractInterface

// *** Misc
QString mysqlPasswordHash (const QString &password);
static int extractNativeErrorNumber(QSqlError& error);
};

#endif
4 changes: 2 additions & 2 deletions src/db/interface/exceptions/SqlException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ QString SqlException::makeString (const QString &message) const
" Database error: %4\n"
" Driver error : %5")
.arg (message)
.arg (error.number ()).arg (error.type ())
.arg (error.nativeErrorCode ()).arg (error.type ())
.arg (error.databaseText ())
.arg (error.driverText ());
}
Expand All @@ -36,7 +36,7 @@ QString SqlException::makeColorizedString (const QString &message) const
" Driver error : %7")
.arg (c.red ()).arg (c.reset ())
.arg (message)
.arg (error.number ()).arg (error.type ())
.arg (error.nativeErrorCode ()).arg (error.type ())
.arg (error.databaseText ())
.arg (error.driverText ());
}
6 changes: 3 additions & 3 deletions src/flarm/flarmMap/FlarmMapWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ void FlarmMapWidget::paintLatLonGrid (QPainter &painter)

QString text=longitude.formatDmSuffix ("E", "W");
QPointF intersection;
if (line.intersect (intersectionLine, &intersection)==QLineF::BoundedIntersection)
if (line.intersects (intersectionLine, &intersection)==QLineF::BoundedIntersection)
drawText (painter, intersection, textAlignment, text);
}

Expand All @@ -852,8 +852,8 @@ void FlarmMapWidget::paintLatLonGrid (QPainter &painter)

QString text=latitude.formatDmSuffix ("N", "S");
QPointF intersection;
if (line.intersect (intersectionLine, &intersection)==QLineF::BoundedIntersection)
drawText (painter, intersection, textAlignment, text);
if (line.intersects (intersectionLine, &intersection)==QLineF::BoundedIntersection)
drawText (painter, intersection, textAlignment, text);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/views/SkItemDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void SkItemDelegate::paint (QPainter *painter, const QStyleOptionViewItem &optio
{
if (coloredSelectionEnabled && (option.state & QStyle::State_Selected))
{
QStyleOptionViewItemV4 o (option);
QStyleOptionViewItem o (option);

o.palette.setBrush (QPalette::HighlightedText, index.data (Qt::BackgroundRole).value<QBrush> ());
o.palette.setColor (QPalette::Highlight, QColor (63, 63, 63));
Expand Down
4 changes: 2 additions & 2 deletions src/gui/widgets/PlotWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ void PlotWidget::mouseMoveEvent (QMouseEvent *event)

void PlotWidget::wheelEvent (QWheelEvent *event)
{
Angle angle=Angle::fromDegrees (event->delta ()/(double)8);
Angle angle=Angle::fromDegrees (event->angleDelta().y()/(double)8);

if (event->modifiers ()==Qt::AltModifier)
{
Expand All @@ -379,7 +379,7 @@ void PlotWidget::wheelEvent (QWheelEvent *event)
else
{
// Store the previous position so we can zoom around the mouse position
QPointF position_w=QPointF (event->pos ());
QPointF position_w=QPointF (event->position ());
QPointF position_p=toPlot (position_w);

zoomInBy (pow (2, angle/_mouseWheelZoomDoubleAngle));
Expand Down
10 changes: 5 additions & 5 deletions src/gui/widgets/SkLabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,28 +121,28 @@ void SkLabel::updateColors ()
// Concealed => foreground and background like parent background
setAutoFillBackground (true);

p.setColor (QPalette::WindowText, parentWidget ()->palette ().background ().color ());
p.setColor (QPalette::Window , parentWidget ()->palette ().background ().color ());
p.setColor (QPalette::WindowText, parentWidget ()->palette ().window ().color ());
p.setColor (QPalette::Window , parentWidget ()->palette ().window ().color ());
}
else if (error)
{
// Error => given error background, same foreground as parent
setAutoFillBackground (true);

p.setColor (QPalette::WindowText, parentWidget ()->palette ().foreground ().color ());
p.setColor (QPalette::WindowText, parentWidget ()->palette ().windowText ().color ());
p.setColor (QPalette::Window , errorColor);
}
else
{
if (defaultForegroundColor.isValid ())
p.setColor (QPalette::WindowText, defaultForegroundColor);
else
p.setColor (QPalette::WindowText, parentWidget ()->palette ().foreground ().color ());
p.setColor (QPalette::WindowText, parentWidget ()->palette ().windowText ().color ());

if (useDefaultBackgroundColor)
p.setColor (QPalette::Window , defaultBackgroundColor);
else
p.setColor (QPalette::Window , parentWidget ()->palette ().background ().color ());
p.setColor (QPalette::Window , parentWidget ()->palette ().window ().color ());

setAutoFillBackground (useDefaultBackgroundColor);
}
Expand Down
13 changes: 7 additions & 6 deletions src/gui/windows/SettingsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ SettingsWindow::~SettingsWindow()
void SettingsWindow::prepareText ()
{
weatherPlugins=PluginFactory::getInstance ().getDescriptors<WeatherPlugin> ();
qSort (weatherPlugins.begin (), weatherPlugins.end (), WeatherPlugin::Descriptor::nameLessThanP);
std::sort (weatherPlugins.begin (), weatherPlugins.end (), WeatherPlugin::Descriptor::nameLessThanP);

// Weather plugin lists
ui.weatherPluginInput ->addItem (notr ("-"), QString ());
Expand Down Expand Up @@ -146,13 +146,13 @@ void SettingsWindow::setupText ()
* - ttyUSB1 < ttyUSB10 (entries containing "USB": use stringNumericLessThan)
* - ttyS1 < ttyS10 (entries not containing "USB": use stringNumericLessThan)
*/
bool serialPortLessThan (const QString &s1, const QString &s2)
bool serialPortLessThan (const QSerialPortInfo &s1, const QSerialPortInfo &s2)
{
bool usb1=s1.contains ("USB", Qt::CaseInsensitive);
bool usb2=s2.contains ("USB", Qt::CaseInsensitive);
bool usb1=s1.portName().contains ("USB", Qt::CaseInsensitive);
bool usb2=s2.portName().contains ("USB", Qt::CaseInsensitive);

if (usb1 == usb2)
return stringNumericLessThan (s1, s2);
return stringNumericLessThan (s1.portName(), s2.portName());
else
return usb1;
}
Expand All @@ -170,7 +170,8 @@ void SettingsWindow::populateSerialPortList ()
ui.flarmSerialPortInput->clear ();

QList<QSerialPortInfo> serialPortList = QSerialPortInfo::availablePorts();
//qSort (ports.begin (), ports.end (), serialPortLessThan);
std::sort (serialPortList.begin (), serialPortList.end (), serialPortLessThan);

foreach (const QSerialPortInfo &portInfo, serialPortList)
{
QString deviceDescription= portInfo.description();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/windows/objectList/FlightListWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ bool FlightListWindow::fetchFlights (const QDate &first, const QDate &last)
// Sort the flights (by effective date)
// TODO: hide the sort indicator. The functionality is already in
// MainWindow, should probably be in SkTableView.
qSort (flights);
std::sort (flights.begin(), flights.end());

// Store the date range
currentFirst=first;
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/info/InfoPluginSelectionDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const InfoPlugin::Descriptor *InfoPluginSelectionDialog::getCurrentPluginDescrip
const InfoPlugin::Descriptor *InfoPluginSelectionDialog::select (const QList<const InfoPlugin::Descriptor *> &plugins, QWidget *parent)
{
QList<const InfoPlugin::Descriptor *> sortedPlugins (plugins);
qSort (sortedPlugins.begin (), sortedPlugins.end (), InfoPlugin::Descriptor::nameLessThanP);
std::sort (sortedPlugins.begin (), sortedPlugins.end (), InfoPlugin::Descriptor::nameLessThanP);
InfoPluginSelectionDialog *dialog=new InfoPluginSelectionDialog (sortedPlugins, parent);
dialog->setModal (true);

Expand Down
2 changes: 1 addition & 1 deletion src/startkladde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ int test_database ()
// QSqlError error=interface.lastError ();
// std::cout << "Database could not be opened" << std::endl;
// std::cout << qnotr ("Type: %1, number: %2")
// .arg (error.type ()).arg (error.number ()) << std::endl;
// .arg (error.type ()).arg (error.nativeErrorCode ()) << std::endl;
// std::cout << qnotr ("Database text: %1").arg (error.databaseText ()) << std::endl;
// std::cout << qnotr ("Driver text: %1").arg (error.driverText ()) << std::endl;
//
Expand Down
4 changes: 2 additions & 2 deletions src/statistics/PlaneLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ PlaneLog *PlaneLog::createNew (dbId planeId, const QList<Flight> &flights, Cache
if (flight.getPlaneId ()==planeId)
interestingFlights.append (flight);

qSort (interestingFlights);
std::sort (interestingFlights.begin(), interestingFlights.end());

// Iterate over all interesting flights, generating logbook entries.
// Sometimes, we can generate one entry from several flights. These
Expand Down Expand Up @@ -283,7 +283,7 @@ PlaneLog *PlaneLog::createNew (const QList<Flight> &flights, Cache &cache)
// TODO log error
}
}
qSort (planes.begin (), planes.end (), Plane::clubAwareLessThan);
std::sort (planes.begin (), planes.end (), Plane::clubAwareLessThan);

PlaneLog *result=new PlaneLog ();
foreach (const Plane &plane, planes)
Expand Down

0 comments on commit 875ac0d

Please sign in to comment.