18
#include "EditWidgetProperties.h"
19
#include "ui_EditWidgetProperties.h"
21
#include "MessageBox.h"
22
#include "core/CustomData.h"
23
#include "core/TimeInfo.h"
27
EditWidgetProperties::EditWidgetProperties(QWidget* parent)
29
, m_ui(new Ui::EditWidgetProperties())
30
, m_customDataModel(new QStandardItemModel(this))
33
m_ui->removeCustomDataButton->setEnabled(false);
34
m_ui->customDataTable->setModel(m_customDataModel);
37
connect(m_ui->customDataTable->selectionModel(),
38
SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
39
SLOT(toggleRemoveButton(QItemSelection)));
41
connect(m_ui->removeCustomDataButton, SIGNAL(clicked()), SLOT(removeSelectedPluginData()));
44
EditWidgetProperties::~EditWidgetProperties() = default;
46
void EditWidgetProperties::setFields(const TimeInfo& timeInfo, const QUuid& uuid)
48
static const QString timeFormat("d MMM yyyy HH:mm:ss");
49
m_ui->modifiedEdit->setText(timeInfo.lastModificationTime().toLocalTime().toString(timeFormat));
50
m_ui->createdEdit->setText(timeInfo.creationTime().toLocalTime().toString(timeFormat));
51
m_ui->accessedEdit->setText(timeInfo.lastAccessTime().toLocalTime().toString(timeFormat));
52
m_ui->uuidEdit->setText(uuid.toRfc4122().toHex());
55
void EditWidgetProperties::setCustomData(CustomData* customData)
58
m_customData->disconnect(this);
61
m_customData = customData;
64
connect(m_customData, &CustomData::modified, this, &EditWidgetProperties::update);
70
void EditWidgetProperties::removeSelectedPluginData()
72
QModelIndexList indexes = m_ui->customDataTable->selectionModel()->selectedRows(0);
73
if (indexes.isEmpty()) {
77
auto result = MessageBox::question(this,
78
tr("Delete plugin data?"),
79
tr("Do you really want to delete the selected plugin data?\n"
80
"This may cause the affected plugins to malfunction."),
81
MessageBox::Delete | MessageBox::Cancel,
84
if (result == MessageBox::Cancel) {
88
QStringList selectedData;
89
for (const auto& index : indexes) {
90
const QString key = index.data().toString();
91
selectedData.append(key);
94
std::sort(selectedData.begin(), selectedData.end());
95
for (const auto& key : selectedData) {
96
m_customData->remove(key);
102
void EditWidgetProperties::toggleRemoveButton(const QItemSelection& selected)
104
m_ui->removeCustomDataButton->setEnabled(!selected.isEmpty());
107
void EditWidgetProperties::update()
109
m_customDataModel->clear();
110
m_customDataModel->setHorizontalHeaderLabels({tr("Key"), tr("Value")});
112
m_ui->removeCustomDataButton->setEnabled(false);
114
for (const QString& key : m_customData->keys()) {
115
m_customDataModel->appendRow(QList<QStandardItem*>()
116
<< new QStandardItem(key) << new QStandardItem(m_customData->value(key)));
118
m_ui->removeCustomDataButton->setEnabled(!m_customData->isEmpty());