32 #include <QHeaderView>
35 #include <QMessageBox>
36 #include <QModelIndexList>
58 for (QModelIndex i = idx; i.isValid(); i = i.parent())
59 paths.prepend(i.data().toString());
60 return paths.join(QLatin1Char {
'/'});
67 setExpandsOnDoubleClick(
false);
72 unused.setVerticalHeader(header());
73 header()->setParent(
this);
74 header()->setStretchLastSection(
false);
75 header()->setTextElideMode(Qt::ElideRight);
76 unused.setVerticalHeader(
new QHeaderView(Qt::Horizontal));
81 if ((event->key() != Qt::Key_Space) && (event->key() != Qt::Key_Select))
83 QTreeView::keyPressEvent(event);
91 QVariant
value = current.data(Qt::CheckStateRole);
98 Qt::CheckState state = (
static_cast<Qt::CheckState
>(
value.toInt()) == Qt::Checked
99 ? Qt::Unchecked : Qt::Checked);
103 for (
const QModelIndex &index : selection)
106 model()->setData(index, state, Qt::CheckStateRole);
112 const QModelIndexList selectedIndexes = selectionModel()->selectedRows(0);
113 if (selectedIndexes.size() != 1)
return;
115 const QPersistentModelIndex modelIndex = selectedIndexes.first();
116 if (!modelIndex.isValid())
return;
126 , modelIndex.data().toString(), &ok, isFile).trimmed();
127 if (!ok || !modelIndex.isValid())
return;
129 const QString oldName = modelIndex.data().toString();
130 if (newName == oldName)
133 const QString parentPath =
getFullPath(modelIndex.parent());
134 const QString oldPath {parentPath.isEmpty() ? oldName : parentPath + QLatin1Char {
'/'} + oldName};
135 const QString newPath {parentPath.isEmpty() ? newName : parentPath + QLatin1Char {
'/'} + newName};
144 model->setData(modelIndex, newName);
154 QModelIndex current = currentIndex();
155 if (!current.isValid())
static QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode=QLineEdit::Normal, const QString &text={}, bool *ok=nullptr, bool excludeExtension=false, Qt::InputMethodHints inputMethodHints=Qt::ImhNone)
void renameFolder(const QString &oldPath, const QString &newPath)
virtual void renameFile(int index, const QString &name)=0
QString message() const noexcept
static QMessageBox::StandardButton warning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons=QMessageBox::Ok, QMessageBox::StandardButton defaultButton=QMessageBox::NoButton)
TorrentContentTreeView(QWidget *parent=nullptr)
void keyPressEvent(QKeyEvent *event) override
QModelIndex currentNameCell()
void renameSelectedFile(BitTorrent::AbstractFileStorage &fileStorage)
T value(const QString &key, const T &defaultValue={})
QString getFullPath(const QModelIndex &idx)