30 #include <QStringList>
34 #include <QDataStream>
37 using namespace Data_Structure;
43 rootItem =
new ScenarioItem(QList<QVariant>({
"Scenarios",
"Start",
"Stop",
"Restart",
"Status"}));
53 if (role == Qt::ForegroundRole)
56 if (instance.get() !=
nullptr && !instance->getEnabled())
58 return QColor(Qt::lightGray);
60 if (
index.column() == 4)
64 return QColor(Qt::lightGray);
76 return QColor(Qt::gray);
80 return QColor(Qt::darkYellow);
84 return QColor(Qt::blue);
88 return QColor(Qt::black);
92 else if (role == Qt::ToolTipRole)
94 const QAbstractItemModel* model =
index.model();
95 QString appName = model->data(model->index(
index.row(), 0,
index.parent()), Qt::DisplayRole).toString();
97 if (
index.column() == 1)
99 return QVariant(QString(
"Start ") + appName);
101 else if (
index.column() == 2)
103 return QVariant(QString(
"Stop ") + appName);
105 else if (
index.column() == 3)
107 return QVariant(QString(
"Restart ") + appName);
112 return QVariant::fromValue(
reinterpret_cast<ScenarioItem*
>(
index.internalPointer()));
114 else if (role != Qt::DisplayRole)
128 rootItem =
new ScenarioItem(QList<QVariant>({
"Scenarios",
"Start",
"Stop",
"Restart",
"Status"}));
136 return Qt::CopyAction;
141 Qt::ItemFlags defaultFlags = QAbstractItemModel::flags(
index);
148 return Qt::ItemIsDropEnabled | defaultFlags;
154 types <<
"application/pointer";
159 int row,
int column,
const QModelIndex& parent)
161 if (action == Qt::IgnoreAction)
166 if (!
data->hasFormat(
"application/pointer"))
185 QByteArray encodedData =
data->data(
"application/pointer");
186 QDataStream stream(&encodedData, QIODevice::ReadOnly);
187 QList<QPair<QString, ScenarioManager::Data_Structure::Application*>> result;
190 while (!stream.atEnd())
193 QString instanceName;
194 stream >> holder >> instanceName;
200 result << qMakePair(instanceName, reinterpret_cast<Data_Structure::Application*>(holder));
204 emit applicationsDrop(result, row, parent);
210 for (
int i = 0; i < rootItem->childCount(); i++)
220 QModelIndex topLeft =
index(0, 0);
221 QModelIndex bottomRight =
index(rowCount() - 1, columnCount() - 1);
223 emit dataChanged(topLeft, bottomRight);
247 for (
int i = 0; i < model->rowCount(); ++i)
249 auto index = model->index(i, 0);
250 auto currentScenarioName =
index.data().toString();
251 if (currentScenarioName == scenarioName)
263 for (
int i = 0; i < model->rowCount(); ++i)
265 auto index = model->index(i, 0);
266 auto currentScenarioName =
index.data().toString();
267 if (currentScenarioName == scenarioName)