valentina/container/vcontainer.cpp

206 lines
5.7 KiB
C++
Raw Normal View History

2013-07-13 12:51:31 +02:00
#include "vcontainer.h"
#include <QDebug>
2013-07-17 13:38:11 +02:00
#include "../options.h"
2013-07-13 12:51:31 +02:00
VContainer::VContainer(){
_id = 0;
2013-07-17 13:38:11 +02:00
SetSize(500);
SetGrowth(1760);
2013-07-13 12:51:31 +02:00
}
VPointF VContainer::GetPoint(qint64 id) const{
if(points.contains(id)){
return points.value(id);
} else {
qCritical()<<"Не можу знайти id = "<<id<<" в таблиці.";
throw"Не можу знайти точку за id.";
}
return VPointF();
}
2013-07-17 13:38:11 +02:00
VStandartTableCell VContainer::GetStandartTableCell(const QString &name) const{
if(standartTable.contains(name)){
return standartTable.value(name);
} else {
qCritical()<<"Не можу знайти змінну за імям = "<<name<<" в таблиці.";
throw"Не можу знайти змінну в стандартній таблиці вимірів за ім'ям.";
}
return VStandartTableCell();
}
VIncrementTableRow VContainer::GetIncrementTableRow(const QString& name) const{
if(incrementTable.contains(name)){
return incrementTable.value(name);
} else {
qCritical()<<"Не можу знайти змінну за імям = "<<name<<" в таблиці.";
throw"Не можу знайти змінну в таблиці прибавок за ім'ям.";
}
return VIncrementTableRow();
}
2013-07-13 12:51:31 +02:00
qint64 VContainer::AddPoint(const VPointF& point){
qint64 id = getNextId();
points[id] = point;
return id;
}
2013-07-17 13:38:11 +02:00
void VContainer::AddStandartTableCell(const QString& name, const VStandartTableCell& cell){
standartTable[name] = cell;
}
void VContainer::AddIncrementTableRow(const QString& name, const VIncrementTableRow& cell){
incrementTable[name] = cell;
}
2013-07-13 12:51:31 +02:00
qint64 VContainer::getId(){
return _id;
}
qint64 VContainer::getNextId(){
++_id;
return _id;
}
2013-07-17 13:38:11 +02:00
void VContainer::RemoveIncrementTableRow(const QString& name){
incrementTable.remove(name);
}
2013-07-13 12:51:31 +02:00
void VContainer::UpdatePoint(qint64 id, const VPointF& point){
points[id] = point;
if(id > _id){
_id = id;
}
}
2013-07-17 13:38:11 +02:00
void VContainer::UpdateStandartTableCell(const QString& name, const VStandartTableCell& cell){
standartTable[name] = cell;
}
void VContainer::UpdateIncrementTableRow(const QString& name, const VIncrementTableRow& cell){
incrementTable[name] = cell;
}
qreal VContainer::GetValueStandartTableCell(const QString& name) const{
VStandartTableCell cell = GetStandartTableCell(name);
qreal k_size = ( ( qreal ) (size()/10) - 50.0 ) / 2;
qreal k_growth = ( ( qreal ) (growth()/10) - 176.0 ) / 6;
qreal value = cell.GetBase() + k_size*cell.GetKsize() + k_growth*cell.GetKgrowth();
return value;
}
qreal VContainer::GetValueIncrementTableRow(const QString& name) const{
VIncrementTableRow cell = GetIncrementTableRow(name);
qreal k_size = ( ( qreal ) (size()/10) - 50.0 ) / 2;
qreal k_growth = ( ( qreal ) (growth()/10) - 176.0 ) / 6;
qreal value = cell.getBase() + k_size*cell.getKsize() + k_growth*cell.getKgrowth();
return value;
}
2013-07-13 12:51:31 +02:00
void VContainer::Clear(){
_id = 0;
points.clear();
2013-07-17 13:38:11 +02:00
standartTable.clear();
incrementTable.clear();
2013-07-25 14:00:51 +02:00
lengthLines.clear();
2013-07-17 13:38:11 +02:00
}
void VContainer::ClearIncrementTable(){
incrementTable.clear();
}
2013-07-25 14:00:51 +02:00
void VContainer::ClearLengthLines(){
lengthLines.clear();
}
2013-07-17 13:38:11 +02:00
void VContainer::SetSize(qint32 size){
base["Сг"] = size;
}
void VContainer::SetGrowth(qint32 growth){
base["Р"] = growth;
}
qint32 VContainer::size() const{
return base.value("Сг");
}
qint32 VContainer::growth() const{
return base.value("Р");
}
bool VContainer::IncrementTableContains(const QString& name){
return incrementTable.contains(name);
}
qreal VContainer::FindVar(const QString &name, bool *ok)const{
if(base.contains(name)){
*ok = true;
2013-07-25 14:00:51 +02:00
return base.value(name);
2013-07-17 13:38:11 +02:00
}
if(standartTable.contains(name)){
*ok = true;
2013-07-25 14:00:51 +02:00
return GetValueStandartTableCell(name);
2013-07-17 13:38:11 +02:00
}
if(incrementTable.contains(name)){
*ok = true;
2013-07-25 14:00:51 +02:00
return GetValueIncrementTableRow(name);
}
if(lengthLines.contains(name)){
*ok = true;
return lengthLines.value(name);
2013-07-17 13:38:11 +02:00
}
*ok = false;
return 0;
}
2013-07-25 14:00:51 +02:00
const QMap<qint64, VPointF> *VContainer::DataPoints() const{
return &points;
}
2013-07-17 13:38:11 +02:00
2013-07-25 14:00:51 +02:00
const QMap<QString, qint32> *VContainer::DataBase() const{
return &base;
}
2013-07-17 13:38:11 +02:00
2013-07-25 14:00:51 +02:00
const QMap<QString, VStandartTableCell> *VContainer::DataStandartTable() const{
return &standartTable;
}
2013-07-17 13:38:11 +02:00
2013-07-25 14:00:51 +02:00
const QMap<QString, VIncrementTableRow> *VContainer::DataIncrementTable() const{
return &incrementTable;
}
2013-07-17 13:38:11 +02:00
2013-07-25 14:00:51 +02:00
const QMap<QString, qreal> *VContainer::DataLengthLines() const{
return &lengthLines;
}
2013-07-17 13:38:11 +02:00
2013-07-30 15:09:34 +02:00
void VContainer::AddLine(const qint64 &firstPointId, const qint64 &secondPointId){
QString nameLine = GetNameLine(firstPointId, secondPointId);
VPointF firstPoint = GetPoint(firstPointId);
VPointF secondPoint = GetPoint(secondPointId);
AddLine(nameLine, QLineF(firstPoint.toQPointF(), secondPoint.toQPointF()).length());
}
QString VContainer::GetNameLine(const qint64 &firstPoint, const qint64 &secondPoint) const{
VPointF first = GetPoint(firstPoint);
VPointF second = GetPoint(secondPoint);
return QString("Line_%1_%2").arg(first.name(), second.name());
}
2013-07-25 14:00:51 +02:00
void VContainer::AddLine(const QString &name, const qreal &value){
Q_ASSERT(!name.isEmpty());
lengthLines[name] = value/PrintDPI*25.4;
2013-07-17 13:38:11 +02:00
}
2013-07-25 14:00:51 +02:00
qreal VContainer::GetLine(const QString &name) const{
Q_ASSERT(!name.isEmpty());
if(lengthLines.contains(name)){
return lengthLines.value(name);
} else {
qCritical()<<"Не можу знайти лінію за імям = "<<name<<" в таблиці.";
throw"Не можу знайти лінію таблиці.";
2013-07-17 13:38:11 +02:00
}
2013-07-25 14:00:51 +02:00
return 0;
2013-07-13 12:51:31 +02:00
}