Skip to content

Commit

Permalink
Fix item inserting/adding in release
Browse files Browse the repository at this point in the history
  • Loading branch information
MishkaRogachev committed Mar 26, 2018
1 parent 1246cf3 commit 1ec546e
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
4 changes: 3 additions & 1 deletion sources/db/generic_repository/generic_repository.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ template<class T>
bool GenericRepository<T>::runQuerry()
{
if (m_query.exec()) return true;
qWarning() << m_query.lastError() << m_query.executedQuery();

// TODO: log with db log level
qDebug() << m_query.lastError() << m_query.executedQuery();
return false;
}

Expand Down
33 changes: 15 additions & 18 deletions sources/domain/services/mission_service/mission_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,42 +117,40 @@ MissionItemPtr MissionService::currentWaypoint(int vehicleId) const
}

dto::MissionItemPtr MissionService::addNewMissionItem(int missionId,
MissionItem::Command command,
dto::MissionItem::Command command,
int sequence)
{
QMutexLocker locker(&d->mutex);

MissionPtr mission = this->mission(missionId);
dto::MissionPtr mission = this->mission(missionId);
if (mission.isNull() || mission->count() < sequence) return dto::MissionItemPtr();

MissionItemPtr item = MissionItemPtr::create();
MissionItemPtr lastItem = this->missionItem(missionId, sequence - 1);
dto::MissionItemPtr item = dto::MissionItemPtr::create();
dto::MissionItemPtr lastItem = this->missionItem(missionId, sequence - 1);

item->setMissionId(missionId);
item->setCommand(command);
item->setSequence(sequence);

switch (command) { // TODO: to MissionItemFactory
case MissionItem::Home:
case dto::MissionItem::Home:
item->setAltitude(0);
item->setAltitudeRelative(false);
break;
case MissionItem::Waypoint:
case dto::MissionItem::Waypoint:
if (lastItem)
{
item->setAltitudeRelative(lastItem->isAltitudeRelative());
item->setAltitude(lastItem->altitude());
}
break;
case MissionItem::Takeoff:
if (lastItem)
{
item->setAltitude(50); // TODO: default parms to settings
item->setAltitudeRelative(true);
}
item->setParameter(MissionItem::Pitch, 15);
case dto::MissionItem::Takeoff:
if (lastItem) item->setAltitudeRelative(true);
item->setAltitude(settings::Provider::value(
settings::parameters::defaultTakeoffAltitude).toReal());
item->setParameter(dto::MissionItem::Pitch, 15);
break;
case MissionItem::Landing:
case dto::MissionItem::Landing:
if (lastItem)
{
item->setAltitude(0);
Expand All @@ -163,17 +161,17 @@ dto::MissionItemPtr MissionService::addNewMissionItem(int missionId,
break;
}

// TODO: querry by sequence
for (const dto::MissionItemPtr& other: this->missionItems(missionId))
{
if (other->sequence() < sequence) continue;

other->setSequence(other->sequence() + 1);
other->setStatus(MissionItem::NotActual);
other->setStatus(dto::MissionItem::NotActual);
this->save(other);
}

mission->setCount(mission->count() + 1);
this->save(mission);
if (!this->save(item)) return dto::MissionItemPtr();

dto::MissionAssignmentPtr assignment = this->missionAssignment(missionId);
if (assignment)
Expand All @@ -182,7 +180,6 @@ dto::MissionItemPtr MissionService::addNewMissionItem(int missionId,
emit assignmentChanged(assignment);
}

Q_ASSERT(this->save(item)); // FIXME: handle if can not save
return item;
}

Expand Down
3 changes: 2 additions & 1 deletion sources/domain/services/mission_service/mission_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ namespace domain
dto::MissionAssignmentPtrList missionAssignments() const;

dto::MissionItemPtr currentWaypoint(int vehicleId) const;
dto::MissionItemPtr addNewMissionItem(int missionId, dto::MissionItem::Command command,
dto::MissionItemPtr addNewMissionItem(int missionId,
dto::MissionItem::Command command,
int sequence);
void addNewMission(const QString& name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ QVariant MissionPointMapItemModel::data(const QModelIndex& index, int role) cons
const dto::MissionItemPtr& item = m_items.at(index.row());
if (item.isNull()) return QVariant();

const dto::MissionPtr& mission = m_service->mission(item->missionId());

switch (role)
{
case ItemRole:
Expand All @@ -62,7 +60,7 @@ QVariant MissionPointMapItemModel::data(const QModelIndex& index, int role) cons
case ItemVisibleRole:
{
return settings::Provider::value(settings::mission::mission +
QString::number(mission->id()) + "/" +
QString::number(item->missionId()) + "/" +
settings::mission::visibility).toBool()
&& (item->isPositionatedItem());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void MissionItemEditPresenter::setItem(int id)
void MissionItemEditPresenter::save()
{
int commandIndex = this->viewProperty(PROPERTY(commandIndex)).toInt();
if (commandIndex < d->availableCommands.count())
if (commandIndex >= 0 && commandIndex < d->availableCommands.count())
{
d->item->setCommand(d->availableCommands.at(commandIndex));
}
Expand Down
1 change: 1 addition & 0 deletions sources/settings/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace settings
{
const QString defaultAcceptanceRadius = "Parameters/defaultAcceptanceRadius";
const QString defaultTakeoffPitch = "Parameters/defaultTakeoffPitch";
const QString defaultTakeoffAltitude = "Parameters/defaultTakeoffAltitude";
const QString minAltitude = "Parameters/minAltitude";
const QString maxAltitude = "Parameters/maxAltitude";
const QString precisionAltitude = "Parameters/precisionAltitude";
Expand Down
1 change: 1 addition & 0 deletions sources/settings/settings_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace

{ parameters::defaultAcceptanceRadius, 3 },
{ parameters::defaultTakeoffPitch, 15 },
{ parameters::defaultTakeoffAltitude, 50 },
{ parameters::minAltitude, -500 }, // 418 m Daed Sea shore
{ parameters::maxAltitude, 50000 },
{ parameters::precisionAltitude, 1 },
Expand Down

0 comments on commit 1ec546e

Please sign in to comment.