get rid of FileSelection class and variadic templates
This commit is contained in:
parent
8b5631d73b
commit
376aa6bdf1
|
@ -50,32 +50,37 @@ static QskDialog::Action qskActionCandidate( const QskDialogButtonBox* buttonBox
|
||||||
return QskDialog::NoAction;
|
return QskDialog::NoAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QskDialog::DialogCode qskExec( QskDialogWindow* dialogWindow )
|
||||||
|
{
|
||||||
|
#if 1
|
||||||
|
auto focusIndicator = new QskFocusIndicator();
|
||||||
|
focusIndicator->setObjectName( QStringLiteral( "DialogFocusIndicator" ) );
|
||||||
|
dialogWindow->addItem( focusIndicator );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return dialogWindow->exec();
|
||||||
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
template< typename W, typename T, typename... Args >
|
template< typename W >
|
||||||
class WindowOrSubWindow : public W, public T
|
class WindowOrSubWindow : public W
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WindowOrSubWindow( QObject* parent, const QString& title,
|
WindowOrSubWindow( QObject* parent, const QString& title,
|
||||||
QskDialog::Actions actions, QskDialog::Action defaultAction, Args... args )
|
QskDialog::Actions actions, QskDialog::Action defaultAction )
|
||||||
: W( parent, title, actions, defaultAction )
|
: W( parent, title, actions, defaultAction )
|
||||||
, T( parent, args... )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void setContentItem()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename T, typename... Args >
|
template<>
|
||||||
class WindowOrSubWindow< QskDialogWindow, T, Args... > : public QskDialogWindow, public T
|
class WindowOrSubWindow< QskDialogWindow > : public QskDialogWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WindowOrSubWindow( QObject* parent, const QString& title,
|
WindowOrSubWindow( QObject* parent, const QString& title,
|
||||||
QskDialog::Actions actions, QskDialog::Action defaultAction, Args... args )
|
QskDialog::Actions actions, QskDialog::Action defaultAction )
|
||||||
: QskDialogWindow( static_cast< QWindow* >( parent ) )
|
: QskDialogWindow( static_cast< QWindow* >( parent ) )
|
||||||
, T( parent, args... )
|
|
||||||
{
|
{
|
||||||
auto* transientParent = static_cast< QWindow* >( parent );
|
auto* transientParent = static_cast< QWindow* >( parent );
|
||||||
setTransientParent( transientParent );
|
setTransientParent( transientParent );
|
||||||
|
@ -125,14 +130,13 @@ namespace
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename T, typename... Args >
|
template<>
|
||||||
class WindowOrSubWindow< QskDialogSubWindow, T, Args... > : public QskDialogSubWindow, public T
|
class WindowOrSubWindow< QskDialogSubWindow > : public QskDialogSubWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WindowOrSubWindow( QObject* parent, const QString& title,
|
WindowOrSubWindow( QObject* parent, const QString& title,
|
||||||
QskDialog::Actions actions, QskDialog::Action defaultAction, Args... args )
|
QskDialog::Actions actions, QskDialog::Action defaultAction )
|
||||||
: QskDialogSubWindow( static_cast< QQuickWindow* >( parent )->contentItem() )
|
: QskDialogSubWindow( static_cast< QQuickWindow* >( parent )->contentItem() )
|
||||||
, T( parent, args... )
|
|
||||||
{
|
{
|
||||||
setPopupFlag( QskPopup::DeleteOnClose );
|
setPopupFlag( QskPopup::DeleteOnClose );
|
||||||
setModal( true );
|
setModal( true );
|
||||||
|
@ -161,46 +165,19 @@ namespace
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileSelection // ### looks like we don't need this class
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FileSelection( QObject* parent, const QString& directory )
|
|
||||||
: m_model( new QFileSystemModel( parent ) )
|
|
||||||
{
|
|
||||||
m_model->setRootPath( directory );
|
|
||||||
}
|
|
||||||
|
|
||||||
QString selectedFile() const
|
|
||||||
{
|
|
||||||
const auto index = m_model->index( m_model->rootPath() );
|
|
||||||
return m_model->filePath( index );
|
|
||||||
}
|
|
||||||
|
|
||||||
void setCurrentPath( const QString& path )
|
|
||||||
{
|
|
||||||
m_model->setRootPath( path );
|
|
||||||
}
|
|
||||||
|
|
||||||
QFileSystemModel* model()
|
|
||||||
{
|
|
||||||
return m_model;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
QFileSystemModel* const m_model;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
template< typename W >
|
template< typename W >
|
||||||
class FileSelectionWindow : public WindowOrSubWindow< W, FileSelection, QString >
|
class FileSelectionWindow : public WindowOrSubWindow< W >
|
||||||
{
|
{
|
||||||
using Inherited = WindowOrSubWindow< W, FileSelection, QString >;
|
using Inherited = WindowOrSubWindow< W >;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FileSelectionWindow( QObject* parent, const QString& title,
|
FileSelectionWindow( QObject* parent, const QString& title,
|
||||||
QskDialog::Actions actions, QskDialog::Action defaultAction,const QString& directory )
|
QskDialog::Actions actions, QskDialog::Action defaultAction,const QString& directory )
|
||||||
: WindowOrSubWindow< W, FileSelection, QString >( parent, title, actions, defaultAction, directory )
|
: WindowOrSubWindow< W >( parent, title, actions, defaultAction )
|
||||||
|
, m_model( new QFileSystemModel( parent ) )
|
||||||
{
|
{
|
||||||
|
m_model->setRootPath( directory );
|
||||||
|
|
||||||
auto* outerBox = new QskLinearBox( Qt::Vertical );
|
auto* outerBox = new QskLinearBox( Qt::Vertical );
|
||||||
outerBox->setMargins( 20 );
|
outerBox->setMargins( 20 );
|
||||||
outerBox->setSpacing( 20 );
|
outerBox->setSpacing( 20 );
|
||||||
|
@ -213,6 +190,12 @@ namespace
|
||||||
Inherited::setContentItem( outerBox );
|
Inherited::setContentItem( outerBox );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString selectedFile() const
|
||||||
|
{
|
||||||
|
const auto index = m_model->index( m_model->rootPath() );
|
||||||
|
return m_model->filePath( index );
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupHeader( QQuickItem* parentItem )
|
void setupHeader( QQuickItem* parentItem )
|
||||||
{
|
{
|
||||||
|
@ -269,8 +252,7 @@ namespace
|
||||||
|
|
||||||
QObject::connect( b, &QskPushButton::clicked, this, [this, fi]()
|
QObject::connect( b, &QskPushButton::clicked, this, [this, fi]()
|
||||||
{
|
{
|
||||||
FileSelection::setCurrentPath( fi.filePath() );
|
m_model->setRootPath( fi.filePath() );
|
||||||
loadContents();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,20 +269,17 @@ namespace
|
||||||
{
|
{
|
||||||
m_listBox = new QskSimpleListBox( parentItem );
|
m_listBox = new QskSimpleListBox( parentItem );
|
||||||
|
|
||||||
auto* m = FileSelection::model();
|
QObject::connect( m_model, &QFileSystemModel::directoryLoaded,
|
||||||
|
|
||||||
QObject::connect( m, &QFileSystemModel::directoryLoaded,
|
|
||||||
this, &FileSelectionWindow< W >::loadContents );
|
this, &FileSelectionWindow< W >::loadContents );
|
||||||
|
|
||||||
QObject::connect( m, &QFileSystemModel::rootPathChanged,
|
QObject::connect( m_model, &QFileSystemModel::rootPathChanged,
|
||||||
this, &FileSelectionWindow< W >::loadContents );
|
this, &FileSelectionWindow< W >::loadContents );
|
||||||
|
|
||||||
QObject::connect( m_listBox, &QskSimpleListBox::selectedEntryChanged,
|
QObject::connect( m_listBox, &QskSimpleListBox::selectedEntryChanged,
|
||||||
this, [this]( const QString& path )
|
this, [this]( const QString& path )
|
||||||
{
|
{
|
||||||
auto* m = FileSelection::model();
|
QFileInfo fi( m_model->rootPath(), path );
|
||||||
QFileInfo fi( m->rootPath(), path );
|
m_model->setRootPath( fi.absoluteFilePath() );
|
||||||
FileSelection::setCurrentPath( fi.absoluteFilePath() );
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,19 +287,19 @@ namespace
|
||||||
{
|
{
|
||||||
m_listBox->removeBulk( 0 );
|
m_listBox->removeBulk( 0 );
|
||||||
|
|
||||||
auto* m = FileSelection::model();
|
const auto index = m_model->index( m_model->rootPath() );
|
||||||
|
|
||||||
const auto index = m->index( m->rootPath() );
|
for ( int row = 0; row < m_model->rowCount( index ); row++ )
|
||||||
|
|
||||||
for ( int row = 0; row < m->rowCount( index ); row++ )
|
|
||||||
{
|
{
|
||||||
auto idx = m->index( row, 0, index );
|
auto idx = m_model->index( row, 0, index );
|
||||||
m_listBox->append( m->fileName( idx ) );
|
m_listBox->append( m_model->fileName( idx ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
updateHeader( QDir( FileSelection::selectedFile() ).path() );
|
updateHeader( QDir( selectedFile() ).path() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QFileSystemModel* const m_model;
|
||||||
|
|
||||||
QskSimpleListBox* m_listBox;
|
QskSimpleListBox* m_listBox;
|
||||||
QskLinearBox* m_headerBox;
|
QskLinearBox* m_headerBox;
|
||||||
QskScrollArea* m_scrollArea;
|
QskScrollArea* m_scrollArea;
|
||||||
|
@ -328,17 +307,6 @@ namespace
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static QskDialog::DialogCode qskExec( QskDialogWindow* dialogWindow )
|
|
||||||
{
|
|
||||||
#if 1
|
|
||||||
auto focusIndicator = new QskFocusIndicator();
|
|
||||||
focusIndicator->setObjectName( QStringLiteral( "DialogFocusIndicator" ) );
|
|
||||||
dialogWindow->addItem( focusIndicator );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return dialogWindow->exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
static QQuickWindow* qskSomeQuickWindow()
|
static QQuickWindow* qskSomeQuickWindow()
|
||||||
{
|
{
|
||||||
// not the best code ever, but as it is a fallback only
|
// not the best code ever, but as it is a fallback only
|
||||||
|
|
Loading…
Reference in New Issue