Skip to content
Snippets Groups Projects
Commit e5657838 authored by Daniel Müller's avatar Daniel Müller
Browse files

* Further minor bug fixes

parent 7b27debd
No related branches found
No related tags found
No related merge requests found
Showing
with 266 additions and 238 deletions
...@@ -10,14 +10,14 @@ ...@@ -10,14 +10,14 @@
#define GRNDR_INFO_TITLE "Grinder" #define GRNDR_INFO_TITLE "Grinder"
#define GRNDR_INFO_COPYRIGHT "Copyright (c) WWU Muenster" #define GRNDR_INFO_COPYRIGHT "Copyright (c) WWU Muenster"
#define GRNDR_INFO_DATE "08.9.2019" #define GRNDR_INFO_DATE "19.9.2019"
#define GRNDR_INFO_COMPANY "WWU Muenster" #define GRNDR_INFO_COMPANY "WWU Muenster"
#define GRNDR_INFO_WEBSITE "http://www.uni-muenster.de" #define GRNDR_INFO_WEBSITE "http://www.uni-muenster.de"
#define GRNDR_VERSION_MAJOR 0 #define GRNDR_VERSION_MAJOR 0
#define GRNDR_VERSION_MINOR 15 #define GRNDR_VERSION_MINOR 15
#define GRNDR_VERSION_REVISION 0 #define GRNDR_VERSION_REVISION 0
#define GRNDR_VERSION_BUILD 391 #define GRNDR_VERSION_BUILD 392
namespace grndr namespace grndr
{ {
......
...@@ -23,7 +23,7 @@ const char* GrabCutProcessor::Data_Value_FGModel = "FGModel"; ...@@ -23,7 +23,7 @@ const char* GrabCutProcessor::Data_Value_FGModel = "FGModel";
GrabCutProcessor::GrabCutProcessor(const Block* block) : Processor(block) GrabCutProcessor::GrabCutProcessor(const Block* block) : Processor(block)
{ {
qRegisterMetaType<cv::Mat>();
} }
void GrabCutProcessor::execute(EngineExecutionContext& ctx) void GrabCutProcessor::execute(EngineExecutionContext& ctx)
......
...@@ -12,7 +12,7 @@ const char* ImageTagsProcessor::Data_Value_ImageTags = "ImageTags"; ...@@ -12,7 +12,7 @@ const char* ImageTagsProcessor::Data_Value_ImageTags = "ImageTags";
ImageTagsProcessor::ImageTagsProcessor(const Block* block) : Processor(block) ImageTagsProcessor::ImageTagsProcessor(const Block* block) : Processor(block)
{ {
qRegisterMetaType<const ImageTags*>();
} }
void ImageTagsProcessor::execute(EngineExecutionContext& ctx) void ImageTagsProcessor::execute(EngineExecutionContext& ctx)
......
...@@ -29,7 +29,9 @@ ImageBuild::ImageBuild(const Block* block, const std::vector<const ImageReferenc ...@@ -29,7 +29,9 @@ ImageBuild::ImageBuild(const Block* block, const std::vector<const ImageReferenc
if (imageReferences.empty()) if (imageReferences.empty())
throw std::invalid_argument{_EXCPT("imageReferences may not be empty")}; throw std::invalid_argument{_EXCPT("imageReferences may not be empty")};
qRegisterMetaType<Connection*>(); qRegisterMetaType<const Block*>();
qRegisterMetaType<const ImageReference*>();
qRegisterMetaType<const Connection*>();
// Listen for connection events on the image tags in-port // Listen for connection events on the image tags in-port
if (auto imageTagsInPort = _block->ports().selectByType(PortType::ImageTagsIn)) if (auto imageTagsInPort = _block->ports().selectByType(PortType::ImageTagsIn))
......
...@@ -33,6 +33,9 @@ Layer::Layer(ImageBuild* imageBuild, QString name, Type type, Flags flags, const ...@@ -33,6 +33,9 @@ Layer::Layer(ImageBuild* imageBuild, QString name, Type type, Flags flags, const
if (type == Type::AutoGenerated && !generatingBlock) if (type == Type::AutoGenerated && !generatingBlock)
throw std::invalid_argument{_EXCPT("generatingBlock may not be null")}; throw std::invalid_argument{_EXCPT("generatingBlock may not be null")};
qRegisterMetaType<const Block*>();
qRegisterMetaType<const ImageReference*>();
checkPointers(); checkPointers();
if (_type == Type::AutoGenerated) if (_type == Type::AutoGenerated)
......
...@@ -24,6 +24,7 @@ void InferenceBlock::initBlock() ...@@ -24,6 +24,7 @@ void InferenceBlock::initBlock()
MachineLearningBlock::initBlock(); MachineLearningBlock::initBlock();
// Listen for various events in order to create the dynamic out-ports // Listen for various events in order to create the dynamic out-ports
qRegisterMetaType<std::shared_ptr<ImageTag>>();
qRegisterMetaType<const Connection*>(); qRegisterMetaType<const Connection*>();
connect(_imageTagsPort.get(), &Port::portConnected, this, &InferenceBlock::imageTagsConnected); connect(_imageTagsPort.get(), &Port::portConnected, this, &InferenceBlock::imageTagsConnected);
......
...@@ -17,7 +17,7 @@ const char* MachineLearningMethodProcessor<MethodType>::Data_Value_State = "Stat ...@@ -17,7 +17,7 @@ const char* MachineLearningMethodProcessor<MethodType>::Data_Value_State = "Stat
template<typename MethodType> template<typename MethodType>
MachineLearningMethodProcessor<MethodType>::MachineLearningMethodProcessor(const Block* block) : Processor<MachineLearningMethodBlock<MethodType>>(block) MachineLearningMethodProcessor<MethodType>::MachineLearningMethodProcessor(const Block* block) : Processor<MachineLearningMethodBlock<MethodType>>(block)
{ {
qRegisterMetaType<const MachineLearningMethodBase*>();
} }
template<typename MethodType> template<typename MethodType>
......
...@@ -25,7 +25,9 @@ template<typename BlockType> ...@@ -25,7 +25,9 @@ template<typename BlockType>
MachineLearningProcessor<BlockType>::MachineLearningProcessor(const Block* block, MachineLearningProcessor::SpawnType spawnType, bool requiresBatchMode) : PipelineTaskProcessor<BlockType, MachineLearningTask, MachineLearningTaskData>(block, requiresBatchMode), MachineLearningProcessor<BlockType>::MachineLearningProcessor(const Block* block, MachineLearningProcessor::SpawnType spawnType, bool requiresBatchMode) : PipelineTaskProcessor<BlockType, MachineLearningTask, MachineLearningTaskData>(block, requiresBatchMode),
_spawnType{spawnType} _spawnType{spawnType}
{ {
qRegisterMetaType<const MachineLearningMethodBase*>();
qRegisterMetaType<const ImageTags*>();
qRegisterMetaType<std::shared_ptr<MachineLearningTask>>();
} }
template<typename BlockType> template<typename BlockType>
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
#include "BaristaNetworkPropertyEditor.h" #include "BaristaNetworkPropertyEditor.h"
#include "core/GrinderApplication.h" #include "core/GrinderApplication.h"
Q_DECLARE_METATYPE(ImageReference*)
BaristaNetworkPropertyEditor::BaristaNetworkPropertyEditor(BaristaNetworkProperty* property, QWidget *parent) : PropertyEditor(property, parent) BaristaNetworkPropertyEditor::BaristaNetworkPropertyEditor(BaristaNetworkProperty* property, QWidget *parent) : PropertyEditor(property, parent)
{ {
// Fill the network list // Fill the network list
......
...@@ -9,6 +9,11 @@ ...@@ -9,6 +9,11 @@
Q_DECLARE_METATYPE(BaristaNetwork*); Q_DECLARE_METATYPE(BaristaNetwork*);
BaristaNetworksComboBox::BaristaNetworksComboBox(QWidget* parent) : QComboBox(parent)
{
qRegisterMetaType<BaristaNetwork*>();
}
void BaristaNetworksComboBox::populate() void BaristaNetworksComboBox::populate()
{ {
clear(); clear();
......
...@@ -17,7 +17,7 @@ namespace grndr ...@@ -17,7 +17,7 @@ namespace grndr
Q_OBJECT Q_OBJECT
public: public:
using QComboBox::QComboBox; BaristaNetworksComboBox(QWidget *parent = nullptr);
public: public:
void populate(); void populate();
......
/****************************************************************************** /******************************************************************************
* File: SplitConnectionDialog.cpp * File: SplitConnectionDialog.cpp
* Date: 24.7.2018 * Date: 24.7.2018
*****************************************************************************/ *****************************************************************************/
#include "Grinder.h" #include "Grinder.h"
#include "SplitConnectionDialog.h" #include "SplitConnectionDialog.h"
#include "ui_SplitConnectionDialog.h" #include "ui_SplitConnectionDialog.h"
#include "pipeline/Block.h" #include "pipeline/Block.h"
Q_DECLARE_METATYPE(Port*) Q_DECLARE_METATYPE(Port*)
SplitConnectionDialog::SplitConnectionDialog(const Block* sourceBlock, const Block* destBlock, const Block* insertBlock, const Port* sourcePort, const Port* destPort, QWidget *parent) : QDialog(parent, Qt::Dialog|Qt::WindowTitleHint|Qt::WindowCloseButtonHint), SplitConnectionDialog::SplitConnectionDialog(const Block* sourceBlock, const Block* destBlock, const Block* insertBlock, const Port* sourcePort, const Port* destPort, QWidget *parent) : QDialog(parent, Qt::Dialog|Qt::WindowTitleHint|Qt::WindowCloseButtonHint),
ui{new Ui::SplitConnectionDialog} ui{new Ui::SplitConnectionDialog}
{ {
setupUi(); qRegisterMetaType<Port*>();
fillPorts(sourceBlock, Port::Direction::Out, ui->lstSourcePort, sourcePort); setupUi();
fillPorts(destBlock, Port::Direction::In, ui->lstDestPort, destPort);
fillPorts(insertBlock, Port::Direction::In, ui->lstIncomingPort); fillPorts(sourceBlock, Port::Direction::Out, ui->lstSourcePort, sourcePort);
fillPorts(insertBlock, Port::Direction::Out, ui->lstOutgoingPort); fillPorts(destBlock, Port::Direction::In, ui->lstDestPort, destPort);
} fillPorts(insertBlock, Port::Direction::In, ui->lstIncomingPort);
fillPorts(insertBlock, Port::Direction::Out, ui->lstOutgoingPort);
SplitConnectionDialog::~SplitConnectionDialog() }
{
delete ui; SplitConnectionDialog::~SplitConnectionDialog()
} {
delete ui;
Port* SplitConnectionDialog::sourcePort() const }
{
return ui->lstSourcePort->currentData().value<Port*>(); Port* SplitConnectionDialog::sourcePort() const
} {
return ui->lstSourcePort->currentData().value<Port*>();
Port* SplitConnectionDialog::destPort() const }
{
return ui->lstDestPort->currentData().value<Port*>(); Port* SplitConnectionDialog::destPort() const
} {
return ui->lstDestPort->currentData().value<Port*>();
Port* SplitConnectionDialog::incomingPort() const }
{
return ui->lstIncomingPort->currentData().value<Port*>(); Port* SplitConnectionDialog::incomingPort() const
} {
return ui->lstIncomingPort->currentData().value<Port*>();
Port* SplitConnectionDialog::outgoingPort() const }
{
return ui->lstOutgoingPort->currentData().value<Port*>(); Port* SplitConnectionDialog::outgoingPort() const
} {
return ui->lstOutgoingPort->currentData().value<Port*>();
void SplitConnectionDialog::fillPorts(const Block* block, Port::Direction portDir, QComboBox* comboBox, const Port* defaultPort) }
{
for (auto& port : block->ports().selectByDirection(portDir)) void SplitConnectionDialog::fillPorts(const Block* block, Port::Direction portDir, QComboBox* comboBox, const Port* defaultPort)
{ {
comboBox->addItem(port->getFormattedName(), QVariant::fromValue(port.get())); for (auto& port : block->ports().selectByDirection(portDir))
{
if (port.get() == defaultPort) comboBox->addItem(port->getFormattedName(), QVariant::fromValue(port.get()));
comboBox->setCurrentIndex(comboBox->count() - 1);
} if (port.get() == defaultPort)
comboBox->setCurrentIndex(comboBox->count() - 1);
if (comboBox->count() == 0) }
{
comboBox->addItem("No ports to display", QVariant::fromValue<Port*>(nullptr)); if (comboBox->count() == 0)
comboBox->setEnabled(false); {
} comboBox->addItem("No ports to display", QVariant::fromValue<Port*>(nullptr));
} comboBox->setEnabled(false);
}
void SplitConnectionDialog::setupUi() }
{
ui->setupUi(this); void SplitConnectionDialog::setupUi()
} {
ui->setupUi(this);
}
...@@ -30,6 +30,8 @@ ImageEditorWidget::ImageEditorWidget(ImageEditor* imageEditor, QWidget* parent) ...@@ -30,6 +30,8 @@ ImageEditorWidget::ImageEditorWidget(ImageEditor* imageEditor, QWidget* parent)
if (!imageEditor) if (!imageEditor)
throw std::runtime_error{_EXCPT("imageEditor may not be null")}; throw std::runtime_error{_EXCPT("imageEditor may not be null")};
qRegisterMetaType<std::shared_ptr<ImageReference>>();
// Create editor actions // Create editor actions
_copyImageBuildAction = UIUtils::createAction(this, "&Copy image build", FILE_ICON_COPY, SLOT(copyImageBuild()), "Copy the current image build to the clipboard (Ctrl+Shift+C)", "Ctrl+Shift+C", Qt::WidgetWithChildrenShortcut); _copyImageBuildAction = UIUtils::createAction(this, "&Copy image build", FILE_ICON_COPY, SLOT(copyImageBuild()), "Copy the current image build to the clipboard (Ctrl+Shift+C)", "Ctrl+Shift+C", Qt::WidgetWithChildrenShortcut);
_pasteImageBuildAction = UIUtils::createAction(this, "&Paste image build", FILE_ICON_PASTE, SLOT(pasteImageBuild()), "Paste an image build from the clipboard (Ctrl+Shift+V)", "Ctrl+Shift+V", Qt::WidgetWithChildrenShortcut); _pasteImageBuildAction = UIUtils::createAction(this, "&Paste image build", FILE_ICON_PASTE, SLOT(pasteImageBuild()), "Paste an image build from the clipboard (Ctrl+Shift+V)", "Ctrl+Shift+V", Qt::WidgetWithChildrenShortcut);
...@@ -46,13 +48,10 @@ ImageEditorWidget::ImageEditorWidget(ImageEditor* imageEditor, QWidget* parent) ...@@ -46,13 +48,10 @@ ImageEditorWidget::ImageEditorWidget(ImageEditor* imageEditor, QWidget* parent)
setupUi(); setupUi();
// Reflect primary color changes // Reflect primary color changes
connect(&_imageEditor->environment(), &ImageEditorEnvironment::primaryColorChanged, this, &ImageEditorWidget::primaryColorChanged); connect(&_imageEditor->environment(), &ImageEditorEnvironment::primaryColorChanged, this, &ImageEditorWidget::primaryColorChanged);
// Listen for various events to update our actions // Listen for various events to update our actions
qRegisterMetaType<std::shared_ptr<ImageReference>>();
connect(&grinder()->project(), SIGNAL(imageReferenceCreated(const std::shared_ptr<ImageReference>&)), this, SLOT(updateActions())); connect(&grinder()->project(), SIGNAL(imageReferenceCreated(const std::shared_ptr<ImageReference>&)), this, SLOT(updateActions()));
connect(&grinder()->project(), SIGNAL(imageReferenceRemoved(const std::shared_ptr<ImageReference>&)), this, SLOT(updateActions()), Qt::QueuedConnection); // Delay this signal so that the image reference has been removed from the image references list connect(&grinder()->project(), SIGNAL(imageReferenceRemoved(const std::shared_ptr<ImageReference>&)), this, SLOT(updateActions()), Qt::QueuedConnection); // Delay this signal so that the image reference has been removed from the image references list
connect(&grinder()->clipboardManager(), &ClipboardManager::dataChanged, this, &ImageEditorWidget::updateActions); connect(&grinder()->clipboardManager(), &ClipboardManager::dataChanged, this, &ImageEditorWidget::updateActions);
......
...@@ -22,10 +22,14 @@ ...@@ -22,10 +22,14 @@
#include <opencv2/highgui.hpp> #include <opencv2/highgui.hpp>
Q_DECLARE_METATYPE(std::shared_ptr<Block>) Q_DECLARE_METATYPE(std::shared_ptr<Block>)
Q_DECLARE_METATYPE(std::shared_ptr<ImageReference>)
GrinderWindow::GrinderWindow(QWidget* parent) : QMainWindow(parent), GrinderWindow::GrinderWindow(QWidget* parent) : QMainWindow(parent),
ui{new Ui::GrinderWindow()} ui{new Ui::GrinderWindow()}
{ {
qRegisterMetaType<std::shared_ptr<Block>>();
qRegisterMetaType<std::shared_ptr<ImageReference>>();
setupUi(); setupUi();
// Connect signals to update our UI // Connect signals to update our UI
...@@ -35,7 +39,7 @@ GrinderWindow::GrinderWindow(QWidget* parent) : QMainWindow(parent), ...@@ -35,7 +39,7 @@ GrinderWindow::GrinderWindow(QWidget* parent) : QMainWindow(parent),
connect(&grinder()->projectController(), SIGNAL(projectLoaded(QString)), this, SLOT(updateRecentProjects(QString))); connect(&grinder()->projectController(), SIGNAL(projectLoaded(QString)), this, SLOT(updateRecentProjects(QString)));
connect(&grinder()->projectController(), SIGNAL(projectSaved(QString)), this, SLOT(updateRecentProjects(QString))); connect(&grinder()->projectController(), SIGNAL(projectSaved(QString)), this, SLOT(updateRecentProjects(QString)));
connect(&grinder()->project(), SIGNAL(imageReferenceCreated(const std::shared_ptr<ImageReference>&)), this, SLOT(updateActions())); connect(&grinder()->project(), SIGNAL(imageReferenceCreated(const std::shared_ptr<ImageReference>&)), this, SLOT(updateActions()));
connect(&grinder()->project(), SIGNAL(imageReferenceRemoved(const std::shared_ptr<ImageReference>&)), this, SLOT(updateActions())); connect(&grinder()->project(), SIGNAL(imageReferenceRemoved(const std::shared_ptr<ImageReference>&)), this, SLOT(updateActions()), Qt::QueuedConnection); // Delay this signal so that the image has been removed
// React to setting changes // React to setting changes
connect(&grinder()->settings(), &GrinderSettings::settingsChanged, this, &GrinderWindow::settingsChanged); connect(&grinder()->settings(), &GrinderSettings::settingsChanged, this, &GrinderWindow::settingsChanged);
......
/****************************************************************************** /******************************************************************************
* File: ImageReferencePropertyEditor.cpp * File: ImageReferencePropertyEditor.cpp
* Date: 12.4.2018 * Date: 12.4.2018
*****************************************************************************/ *****************************************************************************/
#include "Grinder.h" #include "Grinder.h"
#include "ImageReferencePropertyEditor.h" #include "ImageReferencePropertyEditor.h"
#include "core/GrinderApplication.h" #include "core/GrinderApplication.h"
Q_DECLARE_METATYPE(ImageReference*) Q_DECLARE_METATYPE(ImageReference*)
ImageReferencePropertyEditor::ImageReferencePropertyEditor(ImageReferenceProperty* property, QWidget *parent) : PropertyEditor(property, parent) ImageReferencePropertyEditor::ImageReferencePropertyEditor(ImageReferenceProperty* property, QWidget *parent) : PropertyEditor(property, parent)
{ {
// Fill the image references list qRegisterMetaType<ImageReference*>();
populateImageReferences();
// Fill the image references list
// Update the property whenever the current index has been changed populateImageReferences();
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(currentIndexChanged(int)));
// Update the property whenever the current index has been changed
// React to new or deleted image references connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(currentIndexChanged(int)));
connect(&grinder()->project(), SIGNAL(imageReferenceCreated(const std::shared_ptr<ImageReference>&)), this, SLOT(populateImageReferences()));
connect(&grinder()->project(), SIGNAL(imageReferenceRemoved(const std::shared_ptr<ImageReference>&)), this, SLOT(populateImageReferences())); // React to new or deleted image references
} connect(&grinder()->project(), SIGNAL(imageReferenceCreated(const std::shared_ptr<ImageReference>&)), this, SLOT(populateImageReferences()));
connect(&grinder()->project(), SIGNAL(imageReferenceRemoved(const std::shared_ptr<ImageReference>&)), this, SLOT(populateImageReferences()));
void ImageReferencePropertyEditor::applyPropertyValue() }
{
bool itemSelected = false; void ImageReferencePropertyEditor::applyPropertyValue()
{
// Search for the corresponding image reference item in the list bool itemSelected = false;
if (auto imageRef = _property->getValue())
{ // Search for the corresponding image reference item in the list
for (int i = 0; i < count(); ++i) if (auto imageRef = _property->getValue())
{ {
auto data = itemData(i); for (int i = 0; i < count(); ++i)
{
if (data.value<ImageReference*>() == imageRef) auto data = itemData(i);
{
setCurrentIndex(i); if (data.value<ImageReference*>() == imageRef)
itemSelected = true; {
break; setCurrentIndex(i);
} itemSelected = true;
} break;
} }
}
// If no item was selected, select the default (active image) one }
if (!itemSelected)
setCurrentIndex(0); // If no item was selected, select the default (active image) one
} if (!itemSelected)
setCurrentIndex(0);
void ImageReferencePropertyEditor::populateImageReferences() }
{
clear(); void ImageReferencePropertyEditor::populateImageReferences()
{
// The first item always represents the currently active image clear();
addItem("<Active image>", QVariant::fromValue<ImageReference*>(nullptr));
// The first item always represents the currently active image
auto boldFont = font(); addItem("<Active image>", QVariant::fromValue<ImageReference*>(nullptr));
boldFont.setBold(true);
setItemData(0, boldFont, Qt::FontRole); auto boldFont = font();
boldFont.setBold(true);
insertSeparator(1); setItemData(0, boldFont, Qt::FontRole);
// Add all image references insertSeparator(1);
for (const auto& imageRef : grinder()->project().imageReferences().sorted())
addItem(imageRef->getImageFileName(), QVariant::fromValue(imageRef.get())); // Add all image references
for (const auto& imageRef : grinder()->project().imageReferences().sorted())
applyPropertyValue(); addItem(imageRef->getImageFileName(), QVariant::fromValue(imageRef.get()));
}
applyPropertyValue();
void ImageReferencePropertyEditor::currentIndexChanged(int index) }
{
_property->setValue(itemData(index).value<ImageReference*>()); void ImageReferencePropertyEditor::currentIndexChanged(int index)
} {
_property->setValue(itemData(index).value<ImageReference*>());
}
...@@ -9,6 +9,11 @@ ...@@ -9,6 +9,11 @@
Q_DECLARE_METATYPE(Block*); Q_DECLARE_METATYPE(Block*);
CanvasBlocksComboBox::CanvasBlocksComboBox(QWidget* parent) : QComboBox(parent)
{
qRegisterMetaType<Block*>();
}
void CanvasBlocksComboBox::populate(const Label* label, QString noneItemText) void CanvasBlocksComboBox::populate(const Label* label, QString noneItemText)
{ {
clear(); clear();
......
...@@ -18,7 +18,7 @@ namespace grndr ...@@ -18,7 +18,7 @@ namespace grndr
Q_OBJECT Q_OBJECT
public: public:
using QComboBox::QComboBox; CanvasBlocksComboBox(QWidget *parent = nullptr);
public: public:
void populate(const Label* label, QString noneItemText = ""); void populate(const Label* label, QString noneItemText = "");
......
/****************************************************************************** /******************************************************************************
* File: LabelsComboBox.cpp * File: LabelsComboBox.cpp
* Date: 13.12.2018 * Date: 13.12.2018
*****************************************************************************/ *****************************************************************************/
#include "Grinder.h" #include "Grinder.h"
#include "LabelsComboBox.h" #include "LabelsComboBox.h"
#include "project/LabelVector.h" #include "project/LabelVector.h"
#include "core/GrinderApplication.h" #include "core/GrinderApplication.h"
Q_DECLARE_METATYPE(Label*); Q_DECLARE_METATYPE(Label*);
void LabelsComboBox::populate(const LabelVector& labels) LabelsComboBox::LabelsComboBox(QWidget* parent) : QComboBox(parent)
{ {
int index = 0; qRegisterMetaType<Label*>();
}
// Add all labels
for (const auto& label : labels) void LabelsComboBox::populate(const LabelVector& labels)
{ {
addItem(label->getName(), QVariant::fromValue(label.get())); int index = 0;
if (label.get() == grinder()->projectController().activeLabel()) // Add all labels
index = count() - 1; for (const auto& label : labels)
} {
addItem(label->getName(), QVariant::fromValue(label.get()));
if (count() == 0)
{ if (label.get() == grinder()->projectController().activeLabel())
addItem("No labels to display", QVariant::fromValue<Label*>(nullptr)); index = count() - 1;
setEnabled(false); }
}
if (count() == 0)
setCurrentIndex(index); {
} addItem("No labels to display", QVariant::fromValue<Label*>(nullptr));
setEnabled(false);
Label* LabelsComboBox::getSelectedLabel() const }
{
return currentData().value<Label*>(); setCurrentIndex(index);
} }
void LabelsComboBox::selectLabel(const Label* label) Label* LabelsComboBox::getSelectedLabel() const
{ {
for (int i = 0; i < count(); ++i) return currentData().value<Label*>();
{ }
if (itemData(i).value<Label*>() == label)
{ void LabelsComboBox::selectLabel(const Label* label)
setCurrentIndex(i); {
break; for (int i = 0; i < count(); ++i)
} {
} if (itemData(i).value<Label*>() == label)
} {
setCurrentIndex(i);
break;
}
}
}
/****************************************************************************** /******************************************************************************
* File: LabelsComboBox.h * File: LabelsComboBox.h
* Date: 13.12.2018 * Date: 13.12.2018
*****************************************************************************/ *****************************************************************************/
#ifndef LABELSCOMBOBOX_H #ifndef LABELSCOMBOBOX_H
#define LABELSCOMBOBOX_H #define LABELSCOMBOBOX_H
#include <QComboBox> #include <QComboBox>
namespace grndr namespace grndr
{ {
class Label; class Label;
class LabelVector; class LabelVector;
class LabelsComboBox : public QComboBox class LabelsComboBox : public QComboBox
{ {
Q_OBJECT Q_OBJECT
public: public:
using QComboBox::QComboBox; LabelsComboBox(QWidget *parent = nullptr);
public: public:
void populate(const LabelVector& labels); void populate(const LabelVector& labels);
Label* getSelectedLabel() const; Label* getSelectedLabel() const;
void selectLabel(const Label* label); void selectLabel(const Label* label);
}; };
} }
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment