Example #1
0
void MainWindow::onLabelAdded(medusa::Label const & label)
{
  QString labelName = QString::fromStdString(label.GetName());

  switch (label.GetType())
  {
  case medusa::Label::LabelData: dataList->addItem(labelName); break;
  case medusa::Label::LabelCode: codeList->addItem(labelName); break;
  case medusa::Label::LabelString: stringList->addItem(labelName); break;
  default: break;
  }

  if (label.GetType() & medusa::Label::LabelImported)
    importedList->addItem(labelName);
  else if (label.GetType() & medusa::Label::LabelExported)
    exportedList->addItem(labelName);
}
Example #2
0
void MainWindow::onLabelRemoved(medusa::Label const & label)
{
  QString labelName = QString::fromStdString(label.GetName());
  QListWidget *curList = nullptr;

  switch (label.GetType())
  {
  case medusa::Label::LabelData:   curList = dataList;   break;
  case medusa::Label::LabelCode:   curList = codeList;   break;
  case medusa::Label::LabelString: curList = stringList; break;
  default:                                               break;
  }

  if (curList != nullptr)
  {
    auto items = curList->findItems(labelName, Qt::MatchExactly);

    // something bad happened
    if (items.size() != 1) return;

    auto item = items.takeFirst();
    curList->removeItemWidget(item);
    delete item;
  }

  if (label.GetType() & medusa::Label::LabelImported)
    curList = importedList;
  else if (label.GetType() & medusa::Label::LabelExported)
    curList = exportedList;

  if (curList != nullptr)
  {
    auto items = curList->findItems(labelName, Qt::MatchExactly);

    // something bad happened
    if (items.size() != 1) return;

    auto item = items.takeFirst();
    curList->removeItemWidget(item);
    delete item;
  }
}