A custom QTreeView for displaying and managing files.
More...
#include <file_tree_view.hpp>
|
| void | mouseReleaseEvent (QMouseEvent *event) override |
| | Handles mouse release events to detect file selection.
|
| |
| void | contextMenuEvent (QContextMenuEvent *event) override |
| | Handles context menu events to display file/folder options.
|
| |
|
| void | createNewFile () |
| | Creates a new file in the selected directory.
|
| |
| void | createNewFolder () |
| | Creates a new folder in the selected directory.
|
| |
| void | renameItem () |
| | Renames the selected file or folder.
|
| |
| void | deleteItem () |
| | Deletes the selected file or folder.
|
| |
|
| QMenu * | createContextMenu () |
| |
| QString | getUniqueName (const QString &basePath, const QString &name, const QString &extension=QString()) |
| | Generates a unique name for a file or folder.
|
| |
| bool | createFileOrFolder (const QString &path, bool isFile) |
| | Creates a file or folder at the specified path.
|
| |
A custom QTreeView for displaying and managing files.
The FileTreeView class provides a file explorer with context menu options for creating, renaming, and deleting files and folders.
◆ FileTreeView()
| FileTreeView::FileTreeView |
( |
QWidget * |
parent = nullptr | ) |
|
|
explicit |
Constructs a FileTreeView object.
Initializes the file system model and configures the view.
- Parameters
-
| parent | The parent widget (default is nullptr). |
◆ contextMenuEvent()
| void FileTreeView::contextMenuEvent |
( |
QContextMenuEvent * |
event | ) |
|
|
overrideprotected |
Handles context menu events to display file/folder options.
Displays a context menu with options for creating, renaming, and deleting items.
- Parameters
-
| event | The context menu event. |
◆ createContextMenu()
| QMenu * FileTreeView::createContextMenu |
( |
| ) |
|
|
private |
◆ createFileOrFolder()
| bool FileTreeView::createFileOrFolder |
( |
const QString & |
path, |
|
|
bool |
isFile |
|
) |
| |
|
private |
Creates a file or folder at the specified path.
- Parameters
-
| path | The path to create the file or folder. |
| isFile | True to create a file, false to create a folder. |
- Returns
- True if the creation was successful, false otherwise.
◆ createNewFile
| void FileTreeView::createNewFile |
( |
| ) |
|
|
privateslot |
Creates a new file in the selected directory.
◆ createNewFolder
| void FileTreeView::createNewFolder |
( |
| ) |
|
|
privateslot |
Creates a new folder in the selected directory.
◆ deleteItem
| void FileTreeView::deleteItem |
( |
| ) |
|
|
privateslot |
Deletes the selected file or folder.
◆ fileCreated
| void FileTreeView::fileCreated |
( |
const QString & |
filePath | ) |
|
|
signal |
◆ fileSelected
| void FileTreeView::fileSelected |
( |
const QString & |
filePath | ) |
|
|
signal |
◆ folderCreated
| void FileTreeView::folderCreated |
( |
const QString & |
folderPath | ) |
|
|
signal |
◆ getUniqueName()
| QString FileTreeView::getUniqueName |
( |
const QString & |
basePath, |
|
|
const QString & |
name, |
|
|
const QString & |
extension = QString() |
|
) |
| |
|
private |
Generates a unique name for a file or folder.
Ensures that the name does not conflict with existing items in the directory.
- Parameters
-
| basePath | The base directory path. |
| name | The desired name. |
| extension | The file extension (optional). |
- Returns
- A unique file or folder name.
◆ mouseReleaseEvent()
| void FileTreeView::mouseReleaseEvent |
( |
QMouseEvent * |
event | ) |
|
|
overrideprotected |
Handles mouse release events to detect file selection.
Emits the fileSelected signal when a file is clicked.
- Parameters
-
| event | The mouse release event. |
◆ renameItem
| void FileTreeView::renameItem |
( |
| ) |
|
|
privateslot |
Renames the selected file or folder.
◆ setRootPath()
| void FileTreeView::setRootPath |
( |
const QString & |
path | ) |
|
Sets the root path for the file tree view.
Updates the view to display the contents of the specified directory.
- Parameters
-
| path | The root directory path. |
◆ contextMenuIndex
| QModelIndex FileTreeView::contextMenuIndex |
|
private |
◆ currentFilePath
| QString FileTreeView::currentFilePath |
|
private |
◆ model
| QFileSystemModel* FileTreeView::model |
|
private |
The documentation for this class was generated from the following files: