Skip to content
Permalink
Browse files

change from ListView to TableView.(refs #78)

  • Loading branch information...
haraki committed Jun 11, 2019
1 parent db216df commit 35d907434d4bbd54ee05e36130ee33f864c0f92b
Showing with 74 additions and 8 deletions.
  1. +5 −3 selectstoragefavoritedialog.cpp
  2. +25 −3 selectstoragefavoritedialog.ui
  3. +41 −2 storagefavoriteinfomodel.cpp
  4. +3 −0 storagefavoriteinfomodel.h
@@ -13,8 +13,10 @@ SelectStorageFavoriteDialog::SelectStorageFavoriteDialog(QWidget *parent/* = Q_N

m_sfInfoModel = new StorageFavoriteInfoModel();

ui->storagesFavoritesListView->setModel(m_sfInfoModel);
ui->storagesFavoritesListView->setCurrentIndex(m_sfInfoModel->index(0));
ui->storagesFavoritesTableView->setModel(m_sfInfoModel);
ui->storagesFavoritesTableView->setCurrentIndex(m_sfInfoModel->index(0));

ui->storagesFavoritesTableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
}

SelectStorageFavoriteDialog::~SelectStorageFavoriteDialog()
@@ -26,7 +28,7 @@ SelectStorageFavoriteDialog::~SelectStorageFavoriteDialog()

void SelectStorageFavoriteDialog::accept()
{
m_selectedPath = m_sfInfoModel->data(ui->storagesFavoritesListView->currentIndex(), StorageFavoriteInfoModel::PathRole).toString();
m_selectedPath = m_sfInfoModel->data(ui->storagesFavoritesTableView->currentIndex(), StorageFavoriteInfoModel::PathRole).toString();

QDialog::accept();
}
@@ -6,16 +6,38 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>489</width>
<height>413</height>
</rect>
</property>
<property name="windowTitle">
<string>Select Storage / Favorite folder</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListView" name="storagesFavoritesListView"/>
<widget class="QTableView" name="storagesFavoritesTableView">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="showGrid">
<bool>false</bool>
</property>
<attribute name="horizontalHeaderVisible">
<bool>true</bool>
</attribute>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
@@ -58,7 +58,7 @@ int StorageFavoriteInfoModel::initialize()
return 0;
}

int StorageFavoriteInfoModel::rowCount(const QModelIndex &parent/* = Q_NULLPTR*/) const
int StorageFavoriteInfoModel::rowCount(const QModelIndex &parent/* = QModelIndex()*/) const
{
if(parent.isValid())
{
@@ -68,6 +68,17 @@ int StorageFavoriteInfoModel::rowCount(const QModelIndex &parent/* = Q_NULLPTR*/
return m_infos.count();
}

int StorageFavoriteInfoModel::columnCount(const QModelIndex &parent/* = QModelIndex()*/) const
{
if(parent.isValid())
{
return 0;
}

return 2;
}


QHash<int, QByteArray> StorageFavoriteInfoModel::roleNames() const
{
QHash<int, QByteArray> roles;
@@ -89,7 +100,15 @@ QVariant StorageFavoriteInfoModel::data(const QModelIndex &index, int role) cons
switch (role)
{
case Qt::DisplayRole:
return info.getName() + " [" + info.getPath() + "]";
if(index.column() == 0)
{
return info.getName();
}
else if(index.column() == 1)
{
return info.getPath();
}
break;
case TypeRole:
return info.getTypeName();
case NameRole:
@@ -101,4 +120,24 @@ QVariant StorageFavoriteInfoModel::data(const QModelIndex &index, int role) cons
return QVariant();
}

QVariant StorageFavoriteInfoModel::headerData(int section, Qt::Orientation orientation, int role/* = Qt::DisplayRole*/) const
{
Q_UNUSED(orientation);

if(role == Qt::DisplayRole)
{
if(section == 0)
{
return tr("Name");
}
else if(section == 1)
{
return tr("Path");
}
}

return QVariant();
}


} // namespace Farman
@@ -54,8 +54,10 @@ class StorageFavoriteInfoModel : public QAbstractListModel

// Basic functionality:
int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;

QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;

protected:
QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
@@ -64,6 +66,7 @@ class StorageFavoriteInfoModel : public QAbstractListModel
int initialize();

QList<StorageFavoriteInfo> m_infos;
QFileSystemModel* m_fileSystemModel;
};

} // namespace Farman

0 comments on commit 35d9074

Please sign in to comment.
You can’t perform that action at this time.