Skip to content

Commit

Permalink
COMP: Fix various deprecation warning C4996
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesobutler committed May 30, 2020
1 parent f48c4a6 commit b9eb388
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 93 deletions.
13 changes: 12 additions & 1 deletion Libs/Widgets/ctkActionsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,17 @@ void ctkActionsWidget::addAction(QAction* action, const QString& group)
for (int i = 0; i < 4; ++i)
{
QStandardItem* item = new QStandardItem;
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
item->setData(QVariant::fromValue(qobject_cast<QObject*>(action)));
#else
item->setData(qVariantFromValue(qobject_cast<QObject*>(action)));
#endif
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
actionItems << item;
}

d->updateItems(actionItems, action);

bool expandGroupItem = (actionGroupItem->rowCount() == 0);
actionGroupItem->appendRow(actionItems);
// if the group didn't exist yet or was empty, then open/expand it
Expand Down Expand Up @@ -273,10 +277,17 @@ void ctkActionsWidget::updateAction()
Q_D(ctkActionsWidget);
QAction* action = qobject_cast<QAction*>(this->sender());
Q_ASSERT(action);
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
QModelIndexList foundActions =
d->ActionsModel->match(d->ActionsModel->index(0,0),
Qt::UserRole + 1, QVariant::fromValue(qobject_cast<QObject*>(action)),
-1, Qt::MatchExactly | Qt::MatchRecursive);
#else
QModelIndexList foundActions =
d->ActionsModel->match(d->ActionsModel->index(0,0),
Qt::UserRole + 1, qVariantFromValue(qobject_cast<QObject*>(action)),
-1, Qt::MatchExactly | Qt::MatchRecursive);
#endif
Q_ASSERT(foundActions.size());
foreach (QModelIndex actionIndex, foundActions)
{
Expand Down
12 changes: 11 additions & 1 deletion Libs/Widgets/ctkAddRemoveComboBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,16 @@ ctkAddRemoveComboBox::~ctkAddRemoveComboBox()
// --------------------------------------------------------------------------
void ctkAddRemoveComboBox::printAdditionalInfo()
{
Q_D(ctkAddRemoveComboBox);
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
qDebug() << "ctkAddRemoveComboBox:" << this << Qt::endl
<< " EmptyText:" << d->EmptyText << Qt::endl
<< " AddingEmptyItem:" << d->AddingEmptyItem << Qt::endl
<< " RemovingEmptyItem:" << d->RemovingEmptyItem << Qt::endl
<< " AddEnabled:" << d->AddEnabled << Qt::endl
<< " RemoveEnabled:" << d->RemoveEnabled << Qt::endl
<< " EditEnabled:" << d->EditEnabled << Qt::endl
<< " HasEmptyItem:" << d->HasEmptyItem;
#else
qDebug() << "ctkAddRemoveComboBox:" << this << endl
<< " EmptyText:" << d->EmptyText << endl
<< " AddingEmptyItem:" << d->AddingEmptyItem << endl
Expand All @@ -158,6 +167,7 @@ void ctkAddRemoveComboBox::printAdditionalInfo()
<< " RemoveEnabled:" << d->RemoveEnabled << endl
<< " EditEnabled:" << d->EditEnabled << endl
<< " HasEmptyItem:" << d->HasEmptyItem;
#endif
}

// --------------------------------------------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion Libs/Widgets/ctkButtonGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ void ctkButtonGroup::onButtonClicked(int buttonId)
clickedButton->setChecked(false);
this->addButton(clickedButton, oldId);
d->IsLastButtonPressedChecked = false;
#if QT_VERSION >= 0x050200
#if (QT_VERSION >= QT_VERSION_CHECK(5,15,0))
emit idToggled(oldId, false);
#elif (QT_VERSION >= QT_VERSION_CHECK(5,2,0))
emit buttonToggled(oldId, false);
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(5,2,0))
emit buttonToggled(clickedButton, false);
#endif
}
Expand Down
1 change: 0 additions & 1 deletion Libs/Widgets/ctkColorPickerButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ ctkColorPickerButtonPrivate::ctkColorPickerButtonPrivate(ctkColorPickerButton& o
this->Color = Qt::black;
this->ColorName = QString();
this->DisplayColorName = true;
this->DialogOptions = 0;
}

//-----------------------------------------------------------------------------
Expand Down
24 changes: 12 additions & 12 deletions Libs/Widgets/ctkComboBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,13 @@ QSize ctkComboBoxPrivate::recomputeSizeHint(QSize &sh) const
case QComboBox::AdjustToContentsOnFirstShow:
if (count == 0 || this->ForceDefault)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,11,0))
int character_pixel_width = fm.horizontalAdvance(QLatin1Char('x'));
#else
int character_pixel_width = fm.width(QLatin1Char('x'));
#endif
sh.rwidth() = this->DefaultText.isEmpty() ?
7 * fm.width(QLatin1Char('x')) :
7 * character_pixel_width :
fm.boundingRect(this->DefaultText).width();
if (!this->DefaultIcon.isNull())
{
Expand All @@ -104,16 +109,6 @@ QSize ctkComboBoxPrivate::recomputeSizeHint(QSize &sh) const
}
}
break;
case QComboBox::AdjustToMinimumContentsLength:
if ((count == 0 || this->ForceDefault) && !this->DefaultIcon.isNull())
{
hasIcon = true;
}
for (int i = 0; i < count && !hasIcon; ++i)
{
hasIcon = !q->itemIcon(i).isNull();
}
break;
case QComboBox::AdjustToMinimumContentsLengthWithIcon:
hasIcon = true;
break;
Expand All @@ -135,8 +130,13 @@ QSize ctkComboBoxPrivate::recomputeSizeHint(QSize &sh) const
}
if (q->minimumContentsLength() > 0)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,11,0))
int character_pixel_width = fm.horizontalAdvance(QLatin1Char('x'));
#else
int character_pixel_width = fm.width(QLatin1Char('x'));
#endif
sh.setWidth(qMax(sh.width(),
q->minimumContentsLength() * fm.width(QLatin1Char('X'))
q->minimumContentsLength() * character_pixel_width
+ (hasIcon ? iconSize.width() + 4 : 0)));
}

Expand Down
7 changes: 7 additions & 0 deletions Libs/Widgets/ctkCoordinatesWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,14 @@ void ctkCoordinatesWidget::updateCoordinate(double coordinate)
{
if (d->LastUserEditedCoordinates[i] == element)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,13,0))
if (i >= 0 && i-1 >= 0 && d->LastUserEditedCoordinates.size() > i && d->LastUserEditedCoordinates.size() > i-1)
{
d->LastUserEditedCoordinates.swapItemsAt(i,i-1);
}
#else
d->LastUserEditedCoordinates.swap(i,i-1);
#endif
}
}
// What is the oldest coordinate to be edited
Expand Down
23 changes: 17 additions & 6 deletions Libs/Widgets/ctkDateRangeWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ void ctkDateRangeWidgetPrivate::autoselectRadioButton()
Q_Q(ctkDateRangeWidget);
QDate startDate = q->startDateTime().date();
QDate endDate = q->endDateTime().date();
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
QDateTime startOfDay = q->startDateTime().date().startOfDay();
QDateTime endOfDay = q->startDateTime().date().endOfDay();
#else
QDateTime startOfDay = QDateTime(q->startDateTime().date());
QDateTime endOfDay = QDateTime(q->endDateTime().date());
#endif
if (this->ForceSelectRange)
{
this->SelectRangeRadioButton->setChecked(true);
Expand All @@ -73,8 +80,8 @@ void ctkDateRangeWidgetPrivate::autoselectRadioButton()
{
this->AnyDateRadioButton->setChecked(true);
}
else if (q->startDateTime() != QDateTime(q->startDateTime().date()) ||
q->endDateTime() != QDateTime(q->endDateTime().date()))
else if (q->startDateTime() != startOfDay ||
q->endDateTime() != endOfDay)
{
this->SelectRangeRadioButton->setChecked(true);
}
Expand Down Expand Up @@ -109,14 +116,14 @@ ctkDateRangeWidget::ctkDateRangeWidget(QWidget* _parent) : Superclass(_parent)
, d_ptr(new ctkDateRangeWidgetPrivate(*this))
{
Q_D(ctkDateRangeWidget);

d->setupUi(this);

d->DateRangeWidget->setVisible(d->SelectRangeRadioButton->isChecked());

this->setDisplayTime(false);
this->setDateTimeRange(QDateTime(), QDateTime());

// Note that we connect on the clicked() signal and not the toggled.
// The clicked() signal is fired only when the USER clicks the radio button
// and not when the button is checked programatically (except using click()).
Expand Down Expand Up @@ -192,7 +199,11 @@ void ctkDateRangeWidget::setDateTimeRange(QDateTime startDateTime, QDateTime end
// --------------------------------------------------------------------------
void ctkDateRangeWidget::setDateRange(QDate startDate, QDate endDate)
{
#if (QT_VERSION >= QT_VERSION_CHECK(5,14,0))
this->setDateTimeRange(startDate.startOfDay(), endDate.endOfDay());
#else
this->setDateTimeRange(QDateTime(startDate), QDateTime(endDate));
#endif
}

// --------------------------------------------------------------------------
Expand Down Expand Up @@ -264,8 +275,8 @@ void ctkDateRangeWidget::setDisplayTime(bool displayTime)
{
d->StartDate->setDisplayFormat( QString( "MMM dd, yyyy HH:mm:ss") );
d->EndDate->setDisplayFormat( QString( "MMM dd, yyyy HH:mm:ss") );
}
else
}
else
{
d->StartDate->setDisplayFormat( QString( "MMM dd, yyyy") );
d->EndDate->setDisplayFormat( QString( "MMM dd, yyyy") );
Expand Down
3 changes: 2 additions & 1 deletion Libs/Widgets/ctkDirectoryButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ void ctkDirectoryButton::browse()
fileDialog->setOptions(QFlags<QFileDialog::Option>(int(d->DialogOptions)));
#endif
fileDialog->setAcceptMode(d->AcceptMode);
fileDialog->setFileMode(QFileDialog::DirectoryOnly);
fileDialog->setFileMode(QFileDialog::Directory);
fileDialog->setOption(QFileDialog::ShowDirsOnly, true);

if (d->AcceptMode == QFileDialog::AcceptSave)
{
Expand Down
14 changes: 12 additions & 2 deletions Libs/Widgets/ctkDoubleSpinBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,12 @@ QSize ctkDoubleSpinBox::sizeHint() const

this->ensurePolished(); // ensure we are using the right font
const QFontMetrics fm(this->fontMetrics());
newSizeHint.setWidth(fm.width(s + extraString) + extraWidth);
#if (QT_VERSION >= QT_VERSION_CHECK(5,11,0))
int width_in_pixels = fm.horizontalAdvance(s + extraString);
#else
int width_in_pixels = fm.width(s + extraString);
#endif
newSizeHint.setWidth(width_in_pixels + extraWidth);

QStyleOptionSpinBox opt;
d->SpinBox->initStyleOptionSpinBox(&opt);
Expand Down Expand Up @@ -1126,7 +1131,12 @@ QSize ctkDoubleSpinBox::minimumSizeHint() const

this->ensurePolished(); // ensure we are using the right font
const QFontMetrics fm(this->fontMetrics());
newSizeHint.setWidth(fm.width(s + extraString) + extraWidth);
#if (QT_VERSION >= QT_VERSION_CHECK(5,11,0))
int width_in_pixels = fm.horizontalAdvance(s + extraString);
#else
int width_in_pixels = fm.width(s + extraString);
#endif
newSizeHint.setWidth(width_in_pixels + extraWidth);

QStyleOptionSpinBox opt;
d->SpinBox->initStyleOptionSpinBox(&opt);
Expand Down
2 changes: 1 addition & 1 deletion Libs/Widgets/ctkErrorLogWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void ctkErrorLogWidget::onSelectionChanged(const QItemSelection & selected,
QModelIndexList selectedRows =
d->SelectionModel->selectedRows(ctkErrorLogModel::DescriptionColumn);

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

QStringList descriptions;

Expand Down
4 changes: 2 additions & 2 deletions Libs/Widgets/ctkFileDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void ctkFileDialog::setBottomWidget(QWidget* widget, const QString& label)
gridLayout->addWidget(widget,4, 0,1, 2);
}
// The dialog button box is no longer spanned on 2 rows but on 3 rows if
// there is a "bottom widget"
// there is a "bottom widget"
QDialogButtonBox* buttonBox = this->findChild<QDialogButtonBox*>();
Q_ASSERT(buttonBox);
gridLayout->removeWidget(buttonBox);
Expand Down Expand Up @@ -276,7 +276,7 @@ void ctkFileDialog::accept()
}
}
// Don't accept read-only directories if we are in AcceptSave mode.
if ((this->fileMode() == Directory || this->fileMode() == DirectoryOnly) &&
if ((this->fileMode() == Directory) &&
this->acceptMode() == AcceptSave)
{
QStringList files = this->selectedFiles();
Expand Down
25 changes: 17 additions & 8 deletions Libs/Widgets/ctkPathLineEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include <QComboBox>
#include <QCompleter>
#include <QDebug>
#include <QDirModel>
#include <QFileDialog>
#include <QFileSystemModel>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QRegExp>
Expand Down Expand Up @@ -214,22 +214,31 @@ QSize ctkPathLineEditPrivate::recomputeSizeHint(QSize& sh)const
case ctkPathLineEdit::AdjustToContentsOnFirstShow:
if (this->LineEdit->text().isEmpty())
{
textWidth = 7 * this->LineEdit->fontMetrics().width(QLatin1Char('x'));
#if (QT_VERSION >= QT_VERSION_CHECK(5,11,0))
int character_pixel_width = this->LineEdit->fontMetrics().horizontalAdvance(QLatin1Char('x'));
#else
int character_pixel_width = this->LineEdit->fontMetrics().width(QLatin1Char('x'));
#endif
textWidth = 7 * character_pixel_width;
}
else
{
textWidth = this->LineEdit->fontMetrics().boundingRect(this->LineEdit->text()).width() + 8;
}
break;
case QComboBox::AdjustToMinimumContentsLength:
default:
;
}
}

if (this->MinimumContentsLength > 0)
{
textWidth = qMax(textWidth, this->MinimumContentsLength * this->LineEdit->fontMetrics().width(QLatin1Char('X')));
#if (QT_VERSION >= QT_VERSION_CHECK(5,11,0))
int character_pixel_width = this->LineEdit->fontMetrics().horizontalAdvance(QLatin1Char('X'));
#else
int character_pixel_width = this->LineEdit->fontMetrics().width(QLatin1Char('X'));
#endif
textWidth = qMax(textWidth, this->MinimumContentsLength * character_pixel_width);
}

int height = (this->ComboBox ? this->ComboBox->minimumSizeHint() :
Expand All @@ -246,10 +255,10 @@ void ctkPathLineEditPrivate::updateFilter()
Q_Q(ctkPathLineEdit);
// help completion for the QComboBox::QLineEdit
QCompleter *newCompleter = new QCompleter(q);
newCompleter->setModel(new QDirModel(
ctk::nameFiltersToExtensions(this->NameFilters),
this->Filters | QDir::NoDotAndDotDot | QDir::AllDirs,
QDir::Name|QDir::DirsLast, newCompleter));
QFileSystemModel *newmodel = new QFileSystemModel();
newmodel->setNameFilters(ctk::nameFiltersToExtensions(this->NameFilters));
newmodel->setFilter(this->Filters | QDir::NoDotAndDotDot | QDir::AllDirs);
newCompleter->setModel(newmodel);
this->LineEdit->setCompleter(newCompleter);

QObject::connect(this->LineEdit->completer()->completionModel(), SIGNAL(layoutChanged()),
Expand Down
Loading

0 comments on commit b9eb388

Please sign in to comment.