Skip to content

Commit

Permalink
Small changes that can prevent users from duplicate layer names
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlamhauge authored and chchwy committed Oct 4, 2018
1 parent 064b32d commit 6075bdf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
45 changes: 41 additions & 4 deletions app/src/actioncommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,14 @@ Status ActionCommands::addNewBitmapLayer()
QString text = QInputDialog::getText(nullptr, tr("Layer Properties"),
tr("Layer name:"), QLineEdit::Normal,
tr("Bitmap Layer"), &ok);
if (ok && !text.isEmpty())
if (ok && !text.isEmpty() && checkNewLayerName(text))
{
mEditor->layers()->createBitmapLayer(text);
}
else
{
uniqueNameMsg();
}
return Status::OK;
}

Expand All @@ -608,10 +612,14 @@ Status ActionCommands::addNewVectorLayer()
QString text = QInputDialog::getText(nullptr, tr("Layer Properties"),
tr("Layer name:"), QLineEdit::Normal,
tr("Vector Layer"), &ok);
if (ok && !text.isEmpty())
if (ok && !text.isEmpty() && checkNewLayerName(text))
{
mEditor->layers()->createVectorLayer(text);
}
else
{
uniqueNameMsg();
}

return Status::OK;
}
Expand All @@ -622,10 +630,14 @@ Status ActionCommands::addNewCameraLayer()
QString text = QInputDialog::getText(nullptr, tr("Layer Properties"),
tr("Layer name:"), QLineEdit::Normal,
tr("Camera Layer"), &ok);
if (ok && !text.isEmpty())
if (ok && !text.isEmpty() && checkNewLayerName(text))
{
mEditor->layers()->createCameraLayer(text);
}
else
{
uniqueNameMsg();
}

return Status::OK;
}
Expand All @@ -636,13 +648,17 @@ Status ActionCommands::addNewSoundLayer()
QString strLayerName = QInputDialog::getText(nullptr, tr("Layer Properties"),
tr("Layer name:"), QLineEdit::Normal,
tr("Sound Layer"), &ok);
if (ok && !strLayerName.isEmpty())
if (ok && !strLayerName.isEmpty() && checkNewLayerName(strLayerName))
{
Layer* layer = mEditor->layers()->createSoundLayer(strLayerName);
mEditor->layers()->setCurrentLayer(layer);

return Status::OK;
}
else
{
uniqueNameMsg();
}
return Status::FAIL;
}

Expand All @@ -668,6 +684,27 @@ Status ActionCommands::deleteCurrentLayer()
return Status::OK;
}

bool ActionCommands::checkNewLayerName(QString s)
{
LayerManager* layerMgr = mEditor->layers();
bool b = true;
for (int i = 0; i < layerMgr->count(); i++)
{
if (layerMgr->getLayer(i)->name() == s)
{
b = false;
}
}
return b;
}

void ActionCommands::uniqueNameMsg()
{
QMessageBox msgBox;
msgBox.setText(tr("Filename must be unique and not empty"));
msgBox.exec();
}


void ActionCommands::help()
{
Expand Down
2 changes: 2 additions & 0 deletions app/src/actioncommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class ActionCommands : public QObject
Status addNewCameraLayer();
Status addNewSoundLayer();
Status deleteCurrentLayer();
bool checkNewLayerName(QString s);
void uniqueNameMsg();

// Help
void help();
Expand Down

0 comments on commit 6075bdf

Please sign in to comment.