logicp 4 gadi atpakaļ
vecāks
revīzija
f66c21e696
4 mainītis faili ar 17 papildinājumiem un 32 dzēšanām
  1. 1 0
      include/task/instagram_task.hpp
  2. 5 5
      include/task/task.hpp
  3. 7 22
      src/argdialog.cpp
  4. 4 5
      src/instagram_task.cpp

+ 1 - 0
include/task/instagram_task.hpp

@@ -7,6 +7,7 @@
 namespace Scheduler {
 namespace Args {
 const QString HEADER_TYPE = "header";
+const QString FILE_TYPE = "files";
 const QString DESCRIPTION_TYPE = "description";
 const QString HASHTAG_TYPE = "hashtags";
 const QString PROMOTE_TYPE = "promote_share";

+ 5 - 5
include/task/task.hpp

@@ -231,11 +231,11 @@ class TaskArgument : TaskArgumentBase {
       } else {
         throw std::out_of_range("Could not find value requested for removal");
       }
-    } else if (value.index() == VariantIndex::STRVEC && unwanted_value.index() == VariantIndex::FILEVEC) {
-      auto&& container = std::get<VariantIndex::STRVEC>(value);
-      auto value_to_remove = std::get<VariantIndex::QSTRING>(unwanted_value);
-      auto it = std::find_if(container.begin(), container.end(), [&value_to_remove](QString s) {
-        return (s == value_to_remove);
+    } else if (value.index() == VariantIndex::FILEVEC && unwanted_value.index() == VariantIndex::QSTRING) {
+      auto&& container = std::get<VariantIndex::FILEVEC>(value);
+      auto file_to_remove = std::get<VariantIndex::QSTRING>(unwanted_value);
+      auto it = std::find_if(container.begin(), container.end(), [&file_to_remove](Scheduler::KFileData f) {
+        return (f.name == file_to_remove);
       });
       if (it != container.end()) {
         container.erase(it);

+ 7 - 22
src/argdialog.cpp

@@ -189,35 +189,20 @@ void ArgDialog::addItem(QString value, QString type) {
   QPushButton *q_pb = new QPushButton();
   q_pb->setText("Delete");
   q_pb->setIcon(std::move(QIcon(":/icons/icons/quit.png")));
+  // Set listener on Delete button
   QObject::connect(q_pb, &QPushButton::clicked, this, [this]() {
     auto row_index = ui->argList->currentRow();
-    // If deleted item is a file, we need to remove it from the task
     auto name = ui->argList->item(row_index, 0)->text();
+    if (name == "file") { // UI displays files as type "file", but the argument is named "files"
+      name = Args::FILE_TYPE;
+    }
     auto value = ui->argList->item(row_index, 1)->text();
-    if (name == "file") {
-      if (!value.isEmpty()) {
-        // All of the following should be done by the task
-        QVector<Scheduler::KFileData> task_files = std::get<VariantIndex::FILEVEC>(m_task->getTaskArgumentValue("files"));
-        auto file_it = std::find_if(task_files.begin(), task_files.end(),
-                                    [value](const Scheduler::KFileData &file) { return file.name == value; });
-        if (file_it != task_files.end()) {  // If file was matched
-          qDebug() << "Removing file from task arguments";
-          task_files.erase(file_it);
-          m_task->setArgument("files", task_files); // Probably not necessary. Try without doing this
-        }
-      }
-    } else {
-      auto&& argument = m_task->getTaskArgument(name);
-      if (argument.isContainer()) {
-        for (auto&& s : value.split("\n")) {
-          m_task->removeArgument(name, s);
-        }
-      } else {
-        argument.clear();
-      }
+    for (auto&& s : value.split("\n")) { // If there are multiple values, they are separated by line breaks
+      m_task->removeArgument(name, s);
     }
     ui->argList->removeRow(row_index);
   });
+
   ui->argList->setItem(row, 0, item);
   ui->argList->setItem(row, 1, item2);
   ui->argList->setCellWidget(row, 3, q_pb);

+ 4 - 5
src/instagram_task.cpp

@@ -85,12 +85,11 @@ void InstagramTask::addArgument(QString name, Scheduler::KFileData file) {
 /**
  * @warning This method is used to remove a value to an argument, and can only be used on arguments whose type is a form of container.
  *
- * @brief InstagramTask::addArgument
+ * @brief InstagramTask::removeArgument
+ *
+ * @param [in] {QString}      name   The name of the argument, whose value is expected to be a container.
+ * @param [in] {TypeVariant}  value  The value to be removed from the container argument.
  *
- * @param [in] {QString}      name  The name of the argument
- * @param [in] {TypeVariant}  file  A data structure to be added to a container of files.
- *                                The KFileData structure contains metadata about a file and
- *                                its data as a byte array
  */
 void InstagramTask::removeArgument(QString name, Scheduler::TypeVariant value) {
   for (auto&& argument : m_arguments) {