| 1727 | } |
| 1728 | |
| 1729 | void DataSourceModel::setSource(AbstractDataSource *source) |
| 1730 | { |
| 1731 | beginResetModel(); |
| 1732 | m_source = source; |
| 1733 | m_data.clear(); |
| 1734 | if (source) { |
| 1735 | const QStringList mimeTypes = m_source->mimeTypes(); |
| 1736 | m_data.resize(mimeTypes.size()); |
| 1737 | for (auto type = mimeTypes.begin(); type != mimeTypes.end(); ++type) { |
| 1738 | std::optional<Pipe> pipe = Pipe::create(O_CLOEXEC); |
| 1739 | if (!pipe) { |
| 1740 | continue; |
| 1741 | } |
| 1742 | source->requestData(*type, std::move(pipe->writeEndpoint)); |
| 1743 | QFuture<QByteArray> data = QtConcurrent::run(readData, pipe->readEndpoint.take()); |
| 1744 | auto watcher = new QFutureWatcher<QByteArray>(this); |
| 1745 | watcher->setFuture(data); |
| 1746 | const int index = type - mimeTypes.begin(); |
| 1747 | connect(watcher, &QFutureWatcher<QByteArray>::finished, this, [this, watcher, index, source = QPointer(source)] { |
| 1748 | watcher->deleteLater(); |
| 1749 | if (source && source == m_source) { |
| 1750 | m_data[index] = watcher->result(); |
| 1751 | Q_EMIT dataChanged(this->index(index, 1), this->index(index, 1), {Qt::DecorationRole | Qt::DisplayRole}); |
| 1752 | } |
| 1753 | }); |
| 1754 | } |
| 1755 | } |
| 1756 | endResetModel(); |
| 1757 | } |
| 1758 | |
| 1759 | DebugConsoleEffectItem::DebugConsoleEffectItem(const QString &name, bool loaded, QWidget *parent) |
| 1760 | : QWidget(parent) |