Some improvements. Functional.

This commit is contained in:
Martín Lucas Golini
2022-01-26 01:56:54 -03:00
parent c3daad6553
commit c296dff7a2
12 changed files with 296 additions and 168 deletions

View File

@@ -166,6 +166,7 @@ class EE_API FileSystemModel : public Model {
void handleFileEvent( const FileEvent& event );
~FileSystemModel();
protected:
std::atomic<bool> mInitOK;
std::string mRootPath;
@@ -181,6 +182,7 @@ class EE_API FileSystemModel : public Model {
FileSystemModel( const std::string& rootPath, const Mode& mode,
const DisplayConfig displayConfig );
size_t getFileIndex( Node* parent, const FileInfo& file );
};
}}} // namespace EE::UI::Models

View File

@@ -1,6 +1,8 @@
#ifndef EE_UI_MODELS_MODEL_HPP
#define EE_UI_MODELS_MODEL_HPP
#include <eepp/system/lock.hpp>
#include <eepp/system/mutex.hpp>
#include <eepp/ui/models/modelindex.hpp>
#include <eepp/ui/models/modelrole.hpp>
#include <eepp/ui/models/variant.hpp>
@@ -120,10 +122,10 @@ class EE_API Model {
void beginInsertRows( ModelIndex const& parent, int first, int last );
void beginInsertColumns( ModelIndex const& parent, int first, int last );
void beginMoveRows( ModelIndex const& source_parent, int first, int last,
ModelIndex const& target_parent, int target_index );
void beginMoveColumns( ModelIndex const& source_parent, int first, int last,
ModelIndex const& target_parent, int target_index );
void beginMoveRows( ModelIndex const& sourceParent, int first, int last,
ModelIndex const& targetParent, int target_index );
void beginMoveColumns( ModelIndex const& sourceParent, int first, int last,
ModelIndex const& targetParent, int target_index );
void beginDeleteRows( ModelIndex const& parent, int first, int last );
void beginDeleteColumns( ModelIndex const& parent, int first, int last );
@@ -134,6 +136,12 @@ class EE_API Model {
void endDeleteRows();
void endDeleteColumns();
Mutex& resourceLock();
void acquireResourceLock() { mResourceLock.lock(); }
void releaseResourceLock() { mResourceLock.unlock(); }
protected:
Model(){};
@@ -150,10 +158,10 @@ class EE_API Model {
struct Operation {
OperationType type{ OperationType::Invalid };
Direction direction{ Direction::Row };
ModelIndex source_parent;
ModelIndex sourceParent;
int first{ 0 };
int last{ 0 };
ModelIndex target_parent;
ModelIndex targetParent;
int target{ 0 };
Operation( OperationType type ) : type( type ) {}
@@ -162,7 +170,7 @@ class EE_API Model {
int last ) :
type( type ),
direction( direction ),
source_parent( parent ),
sourceParent( parent ),
first( first ),
last( last ) {}
@@ -170,10 +178,10 @@ class EE_API Model {
int first, int last, ModelIndex const& targetParent, int target ) :
type( type ),
direction( direction ),
source_parent( sourceParent ),
sourceParent( sourceParent ),
first( first ),
last( last ),
target_parent( targetParent ),
targetParent( targetParent ),
target( target ) {}
};
@@ -195,6 +203,7 @@ class EE_API Model {
std::unordered_set<UIAbstractView*> mViews;
std::unordered_set<Client*> mClients;
std::function<void()> mOnUpdate;
Mutex mResourceLock;
};
inline ModelIndex ModelIndex::parent() const {

View File

@@ -13,9 +13,9 @@ class PersistentHandle {
friend class Model;
friend class PersistentModelIndex;
PersistentHandle( ModelIndex const& index ) : m_index( index ) {}
PersistentHandle( ModelIndex const& index ) : mIndex( index ) {}
ModelIndex m_index;
ModelIndex mIndex;
};
class PersistentModelIndex {
@@ -28,8 +28,8 @@ class PersistentModelIndex {
PersistentModelIndex& operator=( PersistentModelIndex const& ) = default;
PersistentModelIndex& operator=( PersistentModelIndex&& ) = default;
bool isValid() const { return hasValidHandle() && m_handle.lock()->m_index.isValid(); }
bool hasValidHandle() const { return !m_handle.expired(); }
bool isValid() const { return hasValidHandle() && mHandle.lock()->mIndex.isValid(); }
bool hasValidHandle() const { return !mHandle.expired(); }
int row() const;
int column() const;
@@ -39,7 +39,7 @@ class PersistentModelIndex {
void* internalData() const {
if ( hasValidHandle() )
return m_handle.lock()->m_index.internalData();
return mHandle.lock()->mIndex.internalData();
else
return nullptr;
}
@@ -51,7 +51,7 @@ class PersistentModelIndex {
bool operator!=( ModelIndex const& ) const;
private:
std::weak_ptr<PersistentHandle> m_handle;
std::weak_ptr<PersistentHandle> mHandle;
};
}}} // namespace EE::UI::Models