CoreTrace Qt IDE 1.0
The CoreTrace Text editor
 
Loading...
Searching...
No Matches
FileTreeView Class Reference

A custom QTreeView for displaying and managing files. More...

#include <file_tree_view.hpp>

Inheritance diagram for FileTreeView:

Signals

void fileSelected (const QString &filePath)
 
void fileCreated (const QString &filePath)
 
void folderCreated (const QString &folderPath)
 

Public Member Functions

 FileTreeView (QWidget *parent=nullptr)
 Constructs a FileTreeView object.
 
void setRootPath (const QString &path)
 Sets the root path for the file tree view.
 

Protected Member Functions

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.
 

Private Slots

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.
 

Private Member Functions

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.
 

Private Attributes

QFileSystemModel * model
 
QString currentFilePath
 
QModelIndex contextMenuIndex
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ FileTreeView()

FileTreeView::FileTreeView ( QWidget *  parent = nullptr)
explicit

Constructs a FileTreeView object.

Initializes the file system model and configures the view.

Parameters
parentThe parent widget (default is nullptr).

Member Function Documentation

◆ 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
eventThe 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
pathThe path to create the file or folder.
isFileTrue 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
basePathThe base directory path.
nameThe desired name.
extensionThe 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
eventThe 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
pathThe root directory path.

Member Data Documentation

◆ 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: