Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions YUViewLib/src/playlistitem/playlistItemCompressedVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ void playlistItemCompressedVideo::loadRawData(int frameIdx, bool caching)
auto ffmpegDec =
(caching ? dynamic_cast<decoder::decoderFFmpeg *>(this->cachingDecoder.get())
: dynamic_cast<decoder::decoderFFmpeg *>(this->loadingDecoder.get()));
if (!ffmpegDec->pushAVPacket(pkt))
if (!ffmpegDec || !ffmpegDec->pushAVPacket(pkt))
{
if (ffmpegDec->state() != decoder::DecoderState::RetrieveFrames)
// The decoder did not switch to decoding frame mode. Error.
Expand Down Expand Up @@ -1307,8 +1307,10 @@ void playlistItemCompressedVideo::displaySignalComboBoxChanged(int idx)
// A different display signal was chosen. Invalidate the cache and signal that we will need a
// redraw.
auto yuvVideo = dynamic_cast<video::yuv::videoHandlerYUV *>(this->video.get());
yuvVideo->showPixelValuesAsDiff = this->loadingDecoder->isSignalDifference(idx);
yuvVideo->invalidateAllBuffers();
if (yuvVideo)
yuvVideo->showPixelValuesAsDiff = this->loadingDecoder->isSignalDifference(idx);
if (this->video)
this->video->invalidateAllBuffers();

emit SignalItemChanged(true, RECACHE_CLEAR);
}
Expand All @@ -1326,9 +1328,10 @@ void playlistItemCompressedVideo::decoderComboxBoxChanged(int idx)
// A different display signal was chosen. Invalidate the cache and signal that we will need a
// redraw.
auto yuvVideo = dynamic_cast<video::yuv::videoHandlerYUV *>(this->video.get());
if (this->loadingDecoder)
if (yuvVideo && this->loadingDecoder)
yuvVideo->showPixelValuesAsDiff = this->loadingDecoder->isSignalDifference(idx);
yuvVideo->invalidateAllBuffers();
if (this->video)
this->video->invalidateAllBuffers();

// Reset the decoded frame indices so that decoding of the current frame is triggered
this->currentFrameIdx[0] = -1;
Expand Down
35 changes: 14 additions & 21 deletions YUViewLib/src/playlistitem/playlistItemOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ void playlistItemOverlay::slotControlChanged()
this->arangementMode = this->ui.comboBoxArangementMode->currentIndex();
for (int i = 1; i < this->childCount(); i++)
{
auto p = this->getCutomPositionOfItem(i);
auto p = this->getCustomPositionOfItem(i);
this->customPositions[i - 1] = p;
}

Expand Down Expand Up @@ -759,36 +759,30 @@ void playlistItemOverlay::updateCustomPositionGrid()
}
}

QPoint playlistItemOverlay::getCutomPositionOfItem(int itemIdx) const
QPoint playlistItemOverlay::getCustomPositionOfItem(int itemIdx) const
{
assert(itemIdx >= 1);

if (this->customPositionGrid == nullptr)
return {};
if (this->customPositionGrid->columnCount() < 3)
if (!this->customPositionGrid || this->customPositionGrid->columnCount() < 3)
return {};

int gridRowIdx = itemIdx - 1;
if (gridRowIdx >= this->customPositionGrid->rowCount())
return QPoint();
return {};

// There should be 2 spin boxes in this row
auto layoutItemX = this->customPositionGrid->itemAtPosition(gridRowIdx, 1);
auto layoutWidgetX = dynamic_cast<QWidgetItem *>(layoutItemX);
if (layoutWidgetX == nullptr)
auto layoutWidgetX = dynamic_cast<QWidgetItem *>(this->customPositionGrid->itemAtPosition(gridRowIdx, 1));
if (!layoutWidgetX)
return {};
auto widgetX = dynamic_cast<QWidget *>(layoutWidgetX->widget());
auto spinBoxX = dynamic_cast<QSpinBox *>(widgetX);
if (spinBoxX == nullptr)
auto spinBoxX = dynamic_cast<QSpinBox *>(layoutWidgetX->widget());
if (!spinBoxX)
return {};

auto layoutItemY = this->customPositionGrid->itemAtPosition(gridRowIdx, 2);
auto layoutWidgetY = dynamic_cast<QWidgetItem *>(layoutItemY);
if (layoutWidgetY == nullptr)
auto layoutWidgetY = dynamic_cast<QWidgetItem *>(this->customPositionGrid->itemAtPosition(gridRowIdx, 2));
if (!layoutWidgetY)
return {};
auto widgetY = dynamic_cast<QWidget *>(layoutWidgetY->widget());
auto spinBoxY = dynamic_cast<QSpinBox *>(widgetY);
if (spinBoxY == nullptr)
auto spinBoxY = dynamic_cast<QSpinBox *>(layoutWidgetY->widget());
if (!spinBoxY)
return {};

return QPoint(spinBoxX->value(), spinBoxY->value());
Expand All @@ -800,9 +794,8 @@ void playlistItemOverlay::guessBestLayout()
bool statisticsPresent = false;
for (int i = 0; i < this->childCount(); i++)
{
auto childItem = this->getChildPlaylistItem(i);
auto childStas = dynamic_cast<playlistItemStatisticsFile *>(childItem);
if (childStas)
auto childStats = dynamic_cast<playlistItemStatisticsFile *>(this->getChildPlaylistItem(i));
if (childStats)
statisticsPresent = true;
}

Expand Down
2 changes: 1 addition & 1 deletion YUViewLib/src/playlistitem/playlistItemOverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class playlistItemOverlay : public playlistItemContainer
QGridLayout *customPositionGrid{};
void updateCustomPositionGrid();
void clear(int startRow);
QPoint getCutomPositionOfItem(int itemIndex) const;
QPoint getCustomPositionOfItem(int itemIndex) const;

int overlayMode{0};
int arangementMode{0};
Expand Down
19 changes: 8 additions & 11 deletions YUViewLib/src/ui/Mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,10 @@ MainWindow::MainWindow(bool useAlternativeSources, QWidget *parent) : QMainWindo

QWidget *MainWindow::getMainWindow()
{
QWidgetList l = QApplication::topLevelWidgets();
for (QWidget *w : l)
for (const auto widget : QApplication::topLevelWidgets())
{
MainWindow *mw = dynamic_cast<MainWindow *>(w);
if (mw)
return mw;
if (const auto mainWindow = dynamic_cast<MainWindow *>(widget))
return mainWindow;
}
return nullptr;
}
Expand Down Expand Up @@ -798,17 +796,16 @@ void MainWindow::updateSettings()
// Set the right theme
QSettings settings;
QString themeName = settings.value("Theme", "Default").toString();
QString themeFile = functions::getThemeFileName(themeName);
QString themeFileName = functions::getThemeFileName(themeName);

QString styleSheet;
if (!themeFile.isEmpty())
if (!themeFileName.isEmpty())
{
// Get the qss text of the theme
QFile f(themeFile);
if (f.exists())
QFile themeFile(themeFileName);
if (themeFile.exists() && themeFile.open(QFile::ReadOnly | QFile::Text))
{
f.open(QFile::ReadOnly | QFile::Text);
QTextStream ts(&f);
QTextStream ts(&themeFile);
styleSheet = ts.readAll();

// Now replace the placeholder color values with the real values
Expand Down
76 changes: 30 additions & 46 deletions YUViewLib/src/ui/widgets/PlaylistTreeWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,18 @@ PlaylistTreeWidget::~PlaylistTreeWidget()

playlistItem *PlaylistTreeWidget::getDropTarget(const QPoint &pos) const
{
auto pItem = dynamic_cast<playlistItem *>(this->itemAt(pos));
if (pItem != nullptr)
{
// check if dropped on or below/above pItem
auto rc = this->visualItemRect(pItem);
auto rcNew = QRect(rc.left(), rc.top() + 2, rc.width(), rc.height() - 4);
if (!rcNew.contains(pos, true))
// dropped next to pItem
pItem = nullptr;
}
auto item = dynamic_cast<playlistItem *>(this->itemAt(pos));
if (!item)
return {};

return pItem;
// check if dropped on or below/above pItem
auto rc = this->visualItemRect(item);
auto rcNew = QRect(rc.left(), rc.top() + 2, rc.width(), rc.height() - 4);
if (!rcNew.contains(pos, true))
// dropped next to item
return nullptr;

return item;
}

void PlaylistTreeWidget::dragMoveEvent(QDragMoveEvent *event)
Expand Down Expand Up @@ -252,19 +252,14 @@ void PlaylistTreeWidget::dropEvent(QDropEvent *event)
}
else
{
// get the list of the items that are about to be dragged
QList<QTreeWidgetItem *> dragItems = selectedItems();

// Actually move all the items
QTreeWidget::dropEvent(event);

// Query the selected items that were dropped and add a new bufferStatusWidget
// for each of them. The old bufferStatusWidget will be deleted by the tree widget.
QList<int> toRows;
for (QTreeWidgetItem *item : dragItems)
for (auto item : selectedItems())
{
playlistItem *plItem = dynamic_cast<playlistItem *>(item);
if (plItem)
if (const auto plItem = dynamic_cast<playlistItem *>(item))
setItemWidget(item, 1, new bufferStatusWidget(plItem, this));
}

Expand All @@ -291,9 +286,9 @@ void PlaylistTreeWidget::updateAllContainterItems()
{
for (int i = 0; i < topLevelItemCount(); i++)
{
QTreeWidgetItem *item = topLevelItem(i);
playlistItemContainer *containerItem = dynamic_cast<playlistItemContainer *>(item);
if (containerItem != nullptr)
auto item = topLevelItem(i);
auto containerItem = dynamic_cast<playlistItemContainer *>(item);
if (containerItem)
containerItem->updateChildItems();
}
}
Expand All @@ -319,8 +314,8 @@ void PlaylistTreeWidget::addDifferenceItem()
QVector<QTreeWidgetItem *> selection;
for (int i = 0; i < this->selectedItems().count(); i++)
{
auto item = dynamic_cast<playlistItem *>(this->selectedItems()[i]);
if (item && item->canBeUsedInProcessing())
auto plItem = dynamic_cast<playlistItem *>(this->selectedItems()[i]);
if (plItem && plItem->canBeUsedInProcessing())
selection.append(this->selectedItems()[i]);
}

Expand Down Expand Up @@ -407,8 +402,7 @@ void PlaylistTreeWidget::addOverlayItem()
QList<QTreeWidgetItem *> selection;
for (int i = 0; i < selectedItems().count(); i++)
{
playlistItem *item = dynamic_cast<playlistItem *>(selectedItems()[i]);
if (item)
if (const auto plItem = dynamic_cast<playlistItem *>(selectedItems()[i]))
selection.append(selectedItems()[i]);
}

Expand Down Expand Up @@ -518,8 +512,8 @@ void PlaylistTreeWidget::slotItemChanged(bool redraw, recacheIndicator recache)

if (recache != RECACHE_NONE)
{
playlistItem *senderItem = dynamic_cast<playlistItem *>(sender);
emit signalItemRecache(senderItem, recache);
auto senderItem = dynamic_cast<playlistItem *>(sender);
emit signalItemRecache(senderItem, recache);
}
}

Expand Down Expand Up @@ -673,7 +667,7 @@ void PlaylistTreeWidget::deletePlaylistItems(bool deleteAllItems)
QList<playlistItem *> unfoldedItemList;
for (playlistItem *plItem : itemList)
{
playlistItemContainer *containerItem = dynamic_cast<playlistItemContainer *>(plItem);
auto containerItem = dynamic_cast<playlistItemContainer *>(plItem);
if (containerItem)
{
// Add all children (if not yet in the list)
Expand All @@ -700,8 +694,7 @@ void PlaylistTreeWidget::deletePlaylistItems(bool deleteAllItems)

// If the item is in a container item we have to inform the container that the item will be
// deleted.
playlistItem *parentItem = plItem->parentPlaylistItem();
if (parentItem)
if (auto parentItem = plItem->parentPlaylistItem())
parentItem->itemAboutToBeDeleted(plItem);
else
{
Expand Down Expand Up @@ -826,12 +819,8 @@ QString PlaylistTreeWidget::getPlaylistString(QDir dirName)
// Append all the playlist items to the output
for (int i = 0; i < topLevelItemCount(); ++i)
{
QTreeWidgetItem *item = topLevelItem(i);
playlistItem *plItem = dynamic_cast<playlistItem *>(item);
if (!plItem)
continue;

plItem->savePlaylist(plist, dirName);
if (auto plItm = dynamic_cast<playlistItem *>(topLevelItem(i)))
plItm->savePlaylist(plist, dirName);
}

// Append the view states
Expand Down Expand Up @@ -994,9 +983,7 @@ void PlaylistTreeWidget::checkAndUpdateItems()
for (int i = 0; i < topLevelItemCount(); ++i)
{
auto plItem = dynamic_cast<playlistItem *>(this->topLevelItem(i));

// Check (and reset) the flag if the source was changed.
if (plItem->isSourceChanged())
if (plItem && plItem->isSourceChanged())
changedItems.push_back(plItem);
}

Expand Down Expand Up @@ -1029,8 +1016,8 @@ void PlaylistTreeWidget::updateSettings()
{
for (int i = 0; i < this->topLevelItemCount(); ++i)
{
auto plItem = dynamic_cast<playlistItem *>(this->topLevelItem(i));
plItem->updateSettings();
if (auto plItem = dynamic_cast<playlistItem *>(this->topLevelItem(i)))
plItem->updateSettings();
}
}

Expand Down Expand Up @@ -1146,15 +1133,12 @@ QList<playlistItem *> PlaylistTreeWidget::getAllPlaylistItems(const bool topLeve
QList<playlistItem *> returnList;
for (int i = 0; i < topLevelItemCount(); i++)
{
QTreeWidgetItem *item = topLevelItem(i);
playlistItem *plItem = dynamic_cast<playlistItem *>(item);
if (plItem != nullptr)
if (auto plItem = dynamic_cast<playlistItem *>(topLevelItem(i)))
{
returnList.append(plItem);
if (!topLevelOnly)
{
playlistItemContainer *container = dynamic_cast<playlistItemContainer *>(plItem);
if (container)
if (auto container = dynamic_cast<playlistItemContainer *>(plItem))
returnList.append(container->getAllChildPlaylistItems());
}
}
Expand Down
17 changes: 11 additions & 6 deletions YUViewLib/src/video/caching/VideoCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,12 @@ void VideoCache::loadFrame(playlistItem *item, int frameIndex, int loadingSlot)
void VideoCache::interactiveLoaderFinished()
{
// Get the thread that caused this call
QObject *sender = QObject::sender();
LoadingWorker *worker = dynamic_cast<LoadingWorker *>(sender);
int threadID = (interactiveThread[0]->worker() == worker) ? 0 : 1;
auto sender = QObject::sender();
auto worker = dynamic_cast<LoadingWorker *>(sender);
if (!worker)
return;

auto threadID = (interactiveThread[0]->worker() == worker) ? 0 : 1;
assert(worker == interactiveThread[0]->worker() || worker == interactiveThread[1]->worker());

// Check the list of items that are scheduled for deletion. Because a loading thread finished,
Expand Down Expand Up @@ -879,9 +882,11 @@ void VideoCache::watchItemForCachingFinished(playlistItem *item)
void VideoCache::threadCachingFinished()
{
// Get the thread that caused this call
QObject *sender = QObject::sender();
LoadingWorker *worker = dynamic_cast<LoadingWorker *>(sender);
Q_ASSERT_X(worker->isWorking(), Q_FUNC_INFO, "The worker that just finished was not working?");
auto sender = QObject::sender();
auto worker = dynamic_cast<LoadingWorker *>(sender);
Q_ASSERT_X(
worker && worker->isWorking(), Q_FUNC_INFO, "The worker that just finished was not working?");

worker->setWorking(false);
DEBUG_CACHING_DETAIL(
"VideoCache::threadCachingFinished - state %d - worker %p", workersState, worker);
Expand Down
8 changes: 4 additions & 4 deletions YUViewLib/src/video/rgb/videoHandlerRGB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ QStringPairList videoHandlerRGB::getPixelValues(const QPoint &pixelP
if (item2 != nullptr)
{
auto rgbItem2 = dynamic_cast<const videoHandlerRGB *const>(item2);
if (rgbItem2 == nullptr)
if (!rgbItem2)
// The second item is not a videoHandlerRGB. Get the values from the FrameHandler.
return FrameHandler::getPixelValues(pixelPos, frameIdx, item2, frameIdx1);

Expand Down Expand Up @@ -772,7 +772,7 @@ void videoHandlerRGB::drawPixelValues(QPainter *painter,

// Get the other RGB item (if any)
auto rgbItem2 = dynamic_cast<videoHandlerRGB *>(item2);
if (item2 != nullptr && rgbItem2 == nullptr)
if (item2 && !rgbItem2)
{
// The second item is not a videoHandlerRGB item
FrameHandler::drawPixelValues(
Expand Down Expand Up @@ -869,8 +869,8 @@ QImage videoHandlerRGB::calculateDifference(FrameHandler *item2,
const int amplificationFactor,
const bool markDifference)
{
videoHandlerRGB *rgbItem2 = dynamic_cast<videoHandlerRGB *>(item2);
if (rgbItem2 == nullptr)
auto rgbItem2 = dynamic_cast<videoHandlerRGB *>(item2);
if (!rgbItem2)
// The given item is not a RGB source. We cannot compare raw RGB values to non raw RGB values.
// Call the base class comparison function to compare the items using the RGB 888 values.
return videoHandler::calculateDifference(
Expand Down
4 changes: 2 additions & 2 deletions YUViewLib/src/video/videoHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ QImage videoHandler::calculateDifference(FrameHandler *item2,
const bool markDifference)
{
// Try to cast item2 to a videoHandler
videoHandler *videoItem2 = dynamic_cast<videoHandler *>(item2);
if (videoItem2 == nullptr)
auto videoItem2 = dynamic_cast<videoHandler *>(item2);
if (!videoItem2)
{
// The item2 is not a videoItem but this one is.
if (currentImageIndex != frameIdxItem0)
Expand Down
Loading
Loading