Permalink
Browse files

added classes and widget for columns descriptions

  • Loading branch information...
ololuki committed May 26, 2017
1 parent 17de85f commit 86c36b7267b658a7efdc6929ac01261efd065841
@@ -26,7 +26,12 @@ SOURCES += main.cpp\
field/WholeField.cpp \
field/WholeFieldImpl.cpp \
field/LineOfPixels.cpp \
field/ArrayOfPixels.cpp
field/ArrayOfPixels.cpp \
field/BlocksDescriptionField.cpp \
field/AddressOnBlocksDescription.cpp \
field/BlockDescription.cpp \
field/LineDescription.cpp \
field/AllLinesDescription.cpp
HEADERS += mainwindow.h \
widgets/DrawingAreaView.h \
@@ -40,6 +45,11 @@ HEADERS += mainwindow.h \
field/WholeField.h \
field/WholeFieldImpl.h \
field/LineOfPixels.h \
field/ArrayOfPixels.h
field/ArrayOfPixels.h \
field/BlocksDescriptionField.h \
field/AddressOnBlocksDescription.h \
field/BlockDescription.h \
field/LineDescription.h \
field/AllLinesDescription.h
FORMS += mainwindow.ui
@@ -0,0 +1,8 @@
#include "AddressOnBlocksDescription.h"
AddressOnBlocksDescription::AddressOnBlocksDescription(AddressOnBlocksDescription::orientation o, size_t line, size_t blockNumber)
: o(o), line(line), count(blockNumber)
{
}
@@ -0,0 +1,30 @@
#ifndef ADDRESSONBLOCKSDESCRIPTION_H
#define ADDRESSONBLOCKSDESCRIPTION_H
///
/// \brief Contains address of every Block Description (number) on BlocksDescriptionField
/// address counts from top do bottom
/// and from left to right
///
class AddressOnBlocksDescription
{
public:
enum orientation
{
HORIZONTAL,
VERTICAL,
};
AddressOnBlocksDescription(AddressOnBlocksDescription::orientation o, size_t line, size_t count);
size_t getLine() {return line;}
size_t getCount() {return count;}
bool isColumn() {return o == VERTICAL;}
bool isRow() {return o == HORIZONTAL;}
private:
orientation o;
size_t line;
size_t count;
};
#endif // ADDRESSONBLOCKSDESCRIPTION_H
@@ -0,0 +1,38 @@
#include "AllLinesDescription.h"
AllLinesDescription::AllLinesDescription(AddressOnBlocksDescription::orientation orientation, size_t numberOfLines)
{
switch(orientation)
{
case AddressOnBlocksDescription::VERTICAL:
for(size_t i = 0; i < numberOfLines; i++)
{
AddressOnBlocksDescription address = AddressOnBlocksDescription(orientation, i, 0);
std::vector<BlockDescription> line;
line.push_back(BlockDescription(address, 0));
lines.push_back(line);
}
break;
case AddressOnBlocksDescription::HORIZONTAL:
// TODO
break;
}
}
size_t AllLinesDescription::numberOfBlocksInLine(size_t lineNumber)
{
return lines[lineNumber].size();
}
bool AllLinesDescription::isDefinedDescriptionAt(size_t line, size_t count)
{
if (line >= lines.size()) return false;
if (count >= lines[line].size()) return false;
return true;
}
void AllLinesDescription::updateDescription(BlockDescription blockDescription)
{
AddressOnBlocksDescription address = blockDescription.getAddress();
lines[address.getLine()][address.getCount()] = blockDescription;
}
@@ -0,0 +1,32 @@
#ifndef ALLLINESDESCRIPTION_H
#define ALLLINESDESCRIPTION_H
#include <vector>
#include "field/BlockDescription.h"
#include "field/LineDescription.h"
///
/// \brief AllLinesDescription contains all descriptions for columns or rows.
/// It stores BlockDescription in vector of vectors.
///
class AllLinesDescription
{
public:
AllLinesDescription() {}
AllLinesDescription(AddressOnBlocksDescription::orientation orientation, size_t numberOfLines);
size_t numberOfBlocksInLine(size_t lineNumber);
bool isDefinedDescriptionAt(size_t line, size_t count); // true if BlockDescription exists on given position
void updateDescription(BlockDescription blockDescription);
//void insertDescriptionBefore(size_t line, size_t count);
//void addDescriptionAtEnd(size_t line);
//void deleteDescriptionAt(size_t line, size_t count);
BlockDescription& operator()(size_t line, size_t count)
{
return lines[line][count];
}
private:
std::vector<std::vector<BlockDescription>> lines;
};
#endif // ALLLINESDESCRIPTION_H
@@ -0,0 +1 @@
#include "BlockDescription.h"
@@ -0,0 +1,28 @@
#ifndef BLOCKDESCRIPTION_H
#define BLOCKDESCRIPTION_H
#include "AddressOnBlocksDescription.h"
#include "pixelSign.h"
///
/// \brief BlockDescription class contains one block description (number) of picture (field).
/// Sign is for future use - every block is currently black.
///
class BlockDescription
{
public:
BlockDescription(AddressOnBlocksDescription address, size_t blockSize, pixelSign sign = pixelSign::SGN_FILL_BLACK)
: address(address), blockSize(blockSize), sign(sign) {}
size_t getBlockSize() {return blockSize;}
void setBlockSize(size_t blockSize) {this->blockSize = blockSize;}
bool isFilledBlack(){return sign == pixelSign::SGN_FILL_BLACK;}
void makeFilledBlack() {sign = pixelSign::SGN_FILL_BLACK;}
AddressOnBlocksDescription getAddress() {return address;}
private:
AddressOnBlocksDescription address;
size_t blockSize;
pixelSign sign;
};
#endif // BLOCKDESCRIPTION_H
@@ -0,0 +1 @@
#include "BlocksDescriptionField.h"
@@ -0,0 +1,23 @@
#ifndef BLOCKSDESCRIPTIONFIELD_H
#define BLOCKSDESCRIPTIONFIELD_H
#include "RootField.h"
#include "AddressOnBlocksDescription.h"
#include "BlockDescription.h"
///
/// \brief BlocksDescriptionField class is "interface" class
/// to share data of Field with ColumnsDescriptionView and RowsDescriptionView.
/// It derives virtual from RootField because RootField is used in class DrawingAreaField too.
///
class BlocksDescriptionField : public virtual RootField
{
public:
virtual BlockDescription getBlockDescription(AddressOnBlocksDescription address) = 0;
virtual void updateBlockDescription(BlockDescription blockDescription) = 0;
virtual size_t numberOfBlocksInColumn(size_t columnNumber) = 0;
virtual bool isDefinedColumnDescriptionAt(size_t line, size_t count) = 0;
};
#endif // BLOCKSDESCRIPTIONFIELD_H
@@ -0,0 +1 @@
#include "LineDescription.h"
@@ -0,0 +1,21 @@
#ifndef LINEDESCRIPTION_H
#define LINEDESCRIPTION_H
#include <vector>
#include "field/BlockDescription.h"
///
/// \brief LineDescription contains BlockDescriptions for one line of picture
///
class LineDescription : std::vector<BlockDescription>
{
public:
LineDescription() {}
LineDescription(std::vector<BlockDescription> vectorToCopy) : std::vector<BlockDescription>(vectorToCopy) {}
size_t size() {return std::vector<BlockDescription>::size();}
//BlockDescription& getPixelAt(const unsigned int count) {return this->at(count);}
BlockDescription& operator[](const unsigned int count) {return std::vector<BlockDescription>::operator[](count);}
};
#endif // LINEDESCRIPTION_H
@@ -2,13 +2,14 @@
#define WHOLEFIELD_H
#include "DrawingAreaField.h"
#include "BlocksDescriptionField.h"
///
/// \brief WholeField class is "interface" that contains whole data about Field.
/// You should invoke RootField(width, height) constructor in child class constructor
///
class WholeField : public DrawingAreaField, virtual public RootField
class WholeField : public DrawingAreaField, public BlocksDescriptionField, virtual public RootField
{
};
@@ -1,9 +1,11 @@
#include "WholeFieldImpl.h"
#include "AllLinesDescription.h"
WholeFieldImpl::WholeFieldImpl(size_t width, size_t height) : RootField(width, height)
{
array = ArrayOfPixels(width, height);
columnsDescription = AllLinesDescription(AddressOnBlocksDescription::orientation::VERTICAL, width);
}
Pixel WholeFieldImpl::getPixel(AddressOnDrawingArea address)
@@ -20,3 +22,28 @@ void WholeFieldImpl::setPixel(Pixel pixel)
array(x, y) = pixel;
emit dataChanged();
}
BlockDescription WholeFieldImpl::getBlockDescription(AddressOnBlocksDescription address)
{
BlockDescription blockDescription = columnsDescription(address.getLine(), address.getCount());
return blockDescription;
}
void WholeFieldImpl::updateBlockDescription(BlockDescription blockDescription)
{
if (blockDescription.getAddress().isColumn())
{
columnsDescription.updateDescription(blockDescription);
}
emit dataChanged();
}
size_t WholeFieldImpl::numberOfBlocksInColumn(size_t columnNumber)
{
return columnsDescription.numberOfBlocksInLine(columnNumber);
}
bool WholeFieldImpl::isDefinedColumnDescriptionAt(size_t line, size_t count)
{
return columnsDescription.isDefinedDescriptionAt(line, count);
}
@@ -3,6 +3,8 @@
#include "WholeField.h"
#include "ArrayOfPixels.h"
#include "AllLinesDescription.h"
///
/// \brief WholeFieldImpl class implementation - contains whole data about Field.
@@ -14,8 +16,13 @@ class WholeFieldImpl : public WholeField
WholeFieldImpl(size_t width, size_t height);
virtual Pixel getPixel(AddressOnDrawingArea address) override;
virtual void setPixel(Pixel pixel) override;
virtual BlockDescription getBlockDescription(AddressOnBlocksDescription address) override;
virtual void updateBlockDescription(BlockDescription blockDescription) override;
virtual size_t numberOfBlocksInColumn(size_t columnNumber) override;
virtual bool isDefinedColumnDescriptionAt(size_t line, size_t count) override;
private:
ArrayOfPixels array;
AllLinesDescription columnsDescription;
};
#endif // WHOLEFIELDIMPL_H
@@ -11,6 +11,7 @@ MainWindow::MainWindow(QWidget *parent) :
ui->setupUi(this);
ui->drawingArea->setField(field);
ui->columnsDescription->setField(field);
}
MainWindow::~MainWindow()
Oops, something went wrong.

0 comments on commit 86c36b7

Please sign in to comment.