Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests for DiagramContainer #32

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 13 additions & 3 deletions application/sources/diagram_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ DiagramContainer::DiagramContainer(QObject* parent) : QAbstractItemModel(parent)

#ifdef DIAGRAM_CONTAINER_DEBUG_MODE
std::cout << "Elements contained by the DiagramContainer:" << std::endl;
root_item->PrintAllElementsBelow();
root_element->PrintAllElementsRecursive();
std::cout << std::endl;
#endif
}
Expand Down Expand Up @@ -334,9 +334,19 @@ QModelIndex DiagramContainer::parent(const QModelIndex &index) const
{
Element* indexed_element = static_cast<Element*>(index.internalPointer());
Element* parent_element = indexed_element->parent;
Element* parent_of_parent_element = parent_element->parent;
if(root_element.get() != parent_element)
{
result = createIndex(0, (column_count - 1), parent_element);
int row = 0;
for(std::size_t i = parent_of_parent_element->GetNumberOfChildren(); i > 0; --i)
{
std::size_t index_of_parent = i - 1;
if(parent_of_parent_element->GetIndexWithChild(parent_element, index_of_parent) == true)
{
row = static_cast<int>(index_of_parent);
}
}
result = createIndex(row, (column_count - 1), parent_element);
}
}

Expand Down Expand Up @@ -622,7 +632,7 @@ void DiagramContainer::Element::CallFunctionOnElementsRecursive(std::function<vo
#ifdef DIAGRAM_CONTAINER_DEBUG_MODE
void DiagramContainer::Element::PrintAllElementsRecursive(const std::string& identation) const
{
std::cout << identation << "Name: \"" << name << "\", Address: " << this << std::endl;
std::cout << identation << "Name: \"" << std::get<DataType_Name>(data) << "\", Address: " << this << std::endl;

for(const auto& i : children)
{
Expand Down
16 changes: 8 additions & 8 deletions application/sources/diagram_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class DiagramContainer : public QAbstractItemModel
public:
DiagramContainer(QObject* parent = nullptr);

DiagramContainer(const DiagramContainer& new_backend) = delete;
DiagramContainer(DiagramContainer&& new_backend) = delete;
DiagramContainer(const DiagramContainer&) = delete;
DiagramContainer(DiagramContainer&&) = delete;

DiagramContainer& operator=(const DiagramContainer& new_backend) = delete;
DiagramContainer& operator=(DiagramContainer&& new_backend) = delete;
DiagramContainer& operator=(const DiagramContainer&) = delete;
DiagramContainer& operator=(DiagramContainer&&) = delete;

virtual ~DiagramContainer() override = default;

Expand Down Expand Up @@ -112,11 +112,11 @@ class DiagramContainer : public QAbstractItemModel
explicit Element(const DataType& new_data, Element* new_parent = nullptr, const Qt::ItemFlags& new_flags = element_flags_default, const Qt::CheckState new_check_state = Qt::Unchecked)
: data(new_data), parent(new_parent), flags(new_flags), check_state(new_check_state) {}

Element(const Element& new_backend) = delete;
Element(Element&& new_backend) = delete;
Element(const Element&) = delete;
Element(Element&&) = delete;

Element& operator=(const Element& new_backend) = delete;
Element& operator=(Element&& new_backend) = delete;
Element& operator=(const Element&) = delete;
Element& operator=(Element&&) = delete;

~Element() = default;

Expand Down
2 changes: 1 addition & 1 deletion tests/sources/test_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@

TEST(TestBackend, Constructor)
{
Backend myBackend();
Backend myBackend;
}
Loading