Qt: Fix Qt5 deprecation warnings

Mostly the warnings were about QString::sprintf and QFontMetrics::width.
sprintf replacement is asprintf, which annoyingly behaves differently
from sprintf - it seems to append to the string.

Not thoroughly tested, but seems to work.
This commit is contained in:
Pasi Kallinen
2021-08-14 21:03:13 +03:00
parent 1b3b7b0b29
commit 6554500593
13 changed files with 42 additions and 47 deletions

View File

@@ -196,7 +196,7 @@ NetHackQtMenuWindow::NetHackQtMenuWindow(QWidget *parent) :
QPoint pos(0,ok->height());
move(pos);
prompt.setParent(this,0);
prompt.setParent(this);
prompt.move(pos);
grid->addWidget(ok, 0, 0);
@@ -378,8 +378,8 @@ void NetHackQtMenuWindow::PadMenuColumns(bool split_descr)
QFontMetrics fm(table->font());
QString col0width_str = "";
if (biggestcount > 0L)
col0width_str.sprintf("%*ld", std::max(countdigits, 1), biggestcount);
int col0width_int = (int) fm.width(col0width_str) + MENU_WIDTH_SLOP;
col0width_str = QString::asprintf("%*ld", std::max(countdigits, 1), biggestcount);
int col0width_int = (int) fm.horizontalAdvance(col0width_str) + MENU_WIDTH_SLOP;
if (col0width_int > table->columnWidth(0))
WidenColumn(0, col0width_int);
@@ -401,7 +401,7 @@ void NetHackQtMenuWindow::PadMenuColumns(bool split_descr)
QStringList columns = itemlist[row].str.split("\t");
for (int fld = 0; fld < (int) columns.size(); ++fld) {
bool lastcol = (fld == (int) columns.size() - 1);
int w = fm.width(columns[fld] + (lastcol ? "" : " "));
int w = fm.horizontalAdvance(columns[fld] + (lastcol ? "" : " "));
if (fld >= (int) col_widths.size()) {
col_widths.push_back(w); // add another element
} else if (col_widths[fld] < w) {
@@ -421,7 +421,7 @@ void NetHackQtMenuWindow::PadMenuColumns(bool split_descr)
QString Amt = "";
long amt = count(row); // fetch item(row,0) as a number
if (amt > 0L)
Amt.sprintf("%*ld", countdigits, amt);
Amt = QString::asprintf("%*ld", countdigits, amt);
cnt->setText(Amt);
}
@@ -435,14 +435,14 @@ void NetHackQtMenuWindow::PadMenuColumns(bool split_descr)
for (int fld = 0; fld < (int) columns.size() - 1; ++fld) {
//columns[fld] += "\t"; /* (used to pad with tabs) */
int width = col_widths[fld];
while (fm.width(columns[fld]) < width)
while (fm.horizontalAdvance(columns[fld]) < width)
columns[fld] += " "; //"\t";
}
text = columns.join("");
twi->setText(text);
}
// TODO? if description needs to wrap, increase the height of this row
int wid = fm.width(text) + MENU_WIDTH_SLOP;
int wid = fm.horizontalAdvance(text) + MENU_WIDTH_SLOP;
if (wid > widest4)
widest4 = wid;
}
@@ -464,7 +464,7 @@ void NetHackQtMenuWindow::UpdateCountColumn(long newcount)
} else {
biggestcount = std::max(biggestcount, newcount);
QString num;
num.sprintf("%*ld", std::max(countdigits, 1), biggestcount);
num = QString::asprintf("%*ld", std::max(countdigits, 1), biggestcount);
int numlen = (int) num.length();
if (numlen % 2)
++numlen;
@@ -552,7 +552,7 @@ void NetHackQtMenuWindow::AddRow(int row, const MenuItem& mi)
table->setItem(row, 0, twi);
twi->setFlags(Qt::ItemIsEnabled);
#if 0 // active count field now widened as needed rather than preset
WidenColumn(0, fm.width("999999") + MENU_WIDTH_SLOP);
WidenColumn(0, fm.horizontalAdvance("999999") + MENU_WIDTH_SLOP);
#else
WidenColumn(0, MENU_WIDTH_SLOP);
#endif
@@ -600,7 +600,7 @@ void NetHackQtMenuWindow::AddRow(int row, const MenuItem& mi)
// for the normal case of "a - ", the trailing space hid the fact that
// the column wasn't wide enough for four characters; for the " #"
// and " *" cases, the last character was replaced by very tiny "..."
int w = (int) fm.width(letter);
int w = (int) fm.horizontalAdvance(letter);
if (w)
w += MENU_WIDTH_SLOP / 2;
WidenColumn(3, w);
@@ -608,7 +608,7 @@ void NetHackQtMenuWindow::AddRow(int row, const MenuItem& mi)
twi = new QTableWidgetItem(text);
table->setItem(row, 4, twi);
table->item(row, 4)->setFlags(Qt::ItemIsEnabled);
WidenColumn(4, fm.width(text));
WidenColumn(4, fm.horizontalAdvance(text));
if ((int) mi.color != -1) {
twi->setForeground(colors[mi.color].q);
@@ -875,7 +875,7 @@ void NetHackQtMenuWindow::ToggleSelect(int row, bool already_toggled)
amt = count(row); // fetch item(row,0) as a number
QString Amt = "";
if (amt > 0L)
Amt.sprintf("%*ld", countdigits, amt);
Amt = QString::asprintf("%*ld", countdigits, amt);
countfield->setText(Amt); // store right-justified value
}
ClearCount(); // blank out 'countstr' and reset 'counting'