示例#1
0
void
AttachmentModel::moveAttachmentsUpOrDown(QList<Attachment *> attachments,
                                         bool up) {
  auto attachmentRowMap = QHash<Attachment *, int>{};
  for (auto const &attachment : attachments)
    attachmentRowMap[attachment] = rowForAttachment(*attachment);

  std::sort(attachments.begin(), attachments.end(), [&attachmentRowMap](Attachment *a, Attachment *b) { return attachmentRowMap[a] < attachmentRowMap[b]; });

  if (!up)
    std::reverse(attachments.begin(), attachments.end());

  auto couldNotBeMoved = QHash<Attachment *, bool>{};
  auto isSelected      = QHash<Attachment *, bool>{};
  auto const direction = up ? -1 : +1;
  auto const numRows   = rowCount();

  for (auto const &attachment : attachments) {
    isSelected[attachment] = true;

    auto currentRow = rowForAttachment(*attachment);
    Q_ASSERT(0 <= currentRow);

    auto targetRow = currentRow + direction;

    if (   (0       >  targetRow)
        || (numRows <= targetRow)
        || couldNotBeMoved[attachmentForRow(targetRow).get()])
      couldNotBeMoved[attachment] = true;

    else
      insertRow(targetRow, takeRow(currentRow));
  }
}
示例#2
0
QList<AttachmentPtr>
AttachmentModel::attachments() {
  auto attachments = QList<AttachmentPtr>{};
  for (auto row = 0, numRows = rowCount(); row < numRows; ++row)
    attachments << attachmentForRow(row);

  return attachments;
}
void
AttachmentModel::retranslateUi() {
  setHorizontalHeaderLabels(          QStringList{} << QY("Name") << QY("MIME type") << QY("Description") << QY("Attach to") << QY("Source file name") << QY("Directory"));
  Util::setSymbolicColumnNames(*this, QStringList{} <<  Q("name") <<  Q("mimeType")  <<  Q("description") <<  Q("attachTo")  <<  Q("sourceFileName")   <<  Q("directory"));

  for (auto row = 0, numRows = rowCount(); row < numRows; ++row)
    setRowData(itemsForRow(row), *attachmentForRow(row));
}
示例#4
0
int
AttachmentModel::rowForAttachment(Attachment const &attachment)
  const {
  for (auto row = 0, numRows = rowCount(); row < numRows; ++row)
    if (attachmentForRow(row).get() == &attachment)
      return row;

  return -1;
}
void
AttachmentModel::retranslateUi() {
  Util::setDisplayableAndSymbolicColumnNames(*this, {
    { QY("Name"),             Q("name")           },
    { QY("MIME type"),        Q("mimeType")       },
    { QY("Description"),      Q("description")    },
    { QY("Attach to"),        Q("attachTo")       },
    { QY("Source file name"), Q("sourceFileName") },
    { QY("Directory"),        Q("directory")      },
    { QY("Size"),             Q("size")           },
  });

  for (auto row = 0, numRows = rowCount(); row < numRows; ++row)
    setRowData(itemsForRow(row), *attachmentForRow(row));
}