mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 16:40:05 +00:00
Placefile view enhancements
- Size enabled/threshold columns for a checkbox - Combine URL/description columns - Tooltips - Alternating row colors
This commit is contained in:
parent
18c05b3a63
commit
3ff34caa02
5 changed files with 117 additions and 58 deletions
|
|
@ -164,15 +164,18 @@ void PlacefileManager::AddUrl(const std::string& urlString)
|
||||||
|
|
||||||
void PlacefileManager::LoadFile(const std::string& filename)
|
void PlacefileManager::LoadFile(const std::string& filename)
|
||||||
{
|
{
|
||||||
logger_->debug("LoadFile: {}", filename);
|
const std::string placefileName =
|
||||||
|
QDir::toNativeSeparators(QString::fromStdString(filename)).toStdString();
|
||||||
|
|
||||||
|
logger_->debug("LoadFile: {}", placefileName);
|
||||||
|
|
||||||
boost::asio::post(
|
boost::asio::post(
|
||||||
p->threadPool_,
|
p->threadPool_,
|
||||||
[=, this]()
|
[placefileName, this]()
|
||||||
{
|
{
|
||||||
// Load file
|
// Load file
|
||||||
std::shared_ptr<gr::Placefile> placefile =
|
std::shared_ptr<gr::Placefile> placefile =
|
||||||
gr::Placefile::Load(filename);
|
gr::Placefile::Load(placefileName);
|
||||||
|
|
||||||
if (placefile == nullptr)
|
if (placefile == nullptr)
|
||||||
{
|
{
|
||||||
|
|
@ -182,7 +185,7 @@ void PlacefileManager::LoadFile(const std::string& filename)
|
||||||
std::unique_lock lock(p->placefileRecordLock_);
|
std::unique_lock lock(p->placefileRecordLock_);
|
||||||
|
|
||||||
// Determine if the placefile has been loaded previously
|
// Determine if the placefile has been loaded previously
|
||||||
auto it = p->placefileRecordMap_.find(filename);
|
auto it = p->placefileRecordMap_.find(placefileName);
|
||||||
if (it != p->placefileRecordMap_.end())
|
if (it != p->placefileRecordMap_.end())
|
||||||
{
|
{
|
||||||
// If the placefile has been loaded previously, update it
|
// If the placefile has been loaded previously, update it
|
||||||
|
|
@ -190,19 +193,19 @@ void PlacefileManager::LoadFile(const std::string& filename)
|
||||||
|
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
|
|
||||||
Q_EMIT PlacefileUpdated(filename);
|
Q_EMIT PlacefileUpdated(placefileName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// If this is a new placefile, add it
|
// If this is a new placefile, add it
|
||||||
auto& record = p->placefileRecords_.emplace_back(
|
auto& record = p->placefileRecords_.emplace_back(
|
||||||
std::make_shared<PlacefileRecord>(filename, placefile));
|
std::make_shared<PlacefileRecord>(placefileName, placefile));
|
||||||
p->placefileRecordMap_.insert_or_assign(filename, record);
|
p->placefileRecordMap_.insert_or_assign(placefileName, record);
|
||||||
|
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
|
|
||||||
Q_EMIT PlacefileEnabled(filename, record->enabled_);
|
Q_EMIT PlacefileEnabled(placefileName, record->enabled_);
|
||||||
Q_EMIT PlacefileUpdated(filename);
|
Q_EMIT PlacefileUpdated(placefileName);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,10 @@
|
||||||
#include <scwx/util/logger.hpp>
|
#include <scwx/util/logger.hpp>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QCheckBox>
|
||||||
#include <QFontMetrics>
|
#include <QFontMetrics>
|
||||||
|
#include <QStyle>
|
||||||
|
#include <QStyleOption>
|
||||||
|
|
||||||
namespace scwx
|
namespace scwx
|
||||||
{
|
{
|
||||||
|
|
@ -19,7 +22,7 @@ static const auto logger_ = scwx::util::Logger::Create(logPrefix_);
|
||||||
static constexpr int kFirstColumn =
|
static constexpr int kFirstColumn =
|
||||||
static_cast<int>(PlacefileModel::Column::Enabled);
|
static_cast<int>(PlacefileModel::Column::Enabled);
|
||||||
static constexpr int kLastColumn =
|
static constexpr int kLastColumn =
|
||||||
static_cast<int>(PlacefileModel::Column::Description);
|
static_cast<int>(PlacefileModel::Column::Placefile);
|
||||||
static constexpr int kNumColumns = kLastColumn - kFirstColumn + 1;
|
static constexpr int kNumColumns = kLastColumn - kFirstColumn + 1;
|
||||||
|
|
||||||
class PlacefileModelImpl
|
class PlacefileModelImpl
|
||||||
|
|
@ -82,51 +85,88 @@ QVariant PlacefileModel::data(const QModelIndex& index, int role) const
|
||||||
const auto& placefileName = p->placefileNames_.at(index.row());
|
const auto& placefileName = p->placefileNames_.at(index.row());
|
||||||
|
|
||||||
if (role == Qt::ItemDataRole::DisplayRole ||
|
if (role == Qt::ItemDataRole::DisplayRole ||
|
||||||
role == Qt::ItemDataRole::ToolTipRole ||
|
role == Qt::ItemDataRole::ToolTipRole)
|
||||||
role == types::ItemDataRole::SortRole)
|
|
||||||
{
|
{
|
||||||
|
static const QString enabledString = QObject::tr("Enabled");
|
||||||
|
static const QString disabledString = QObject::tr("Disabled");
|
||||||
|
|
||||||
|
static const QString thresholdsEnabledString =
|
||||||
|
QObject::tr("Thresholds Enabled");
|
||||||
|
static const QString thresholdsDisabledString =
|
||||||
|
QObject::tr("Thresholds Disabled");
|
||||||
|
|
||||||
switch (index.column())
|
switch (index.column())
|
||||||
{
|
{
|
||||||
case static_cast<int>(Column::Enabled):
|
case static_cast<int>(Column::Enabled):
|
||||||
if (role == types::ItemDataRole::SortRole)
|
if (role == Qt::ItemDataRole::ToolTipRole)
|
||||||
{
|
{
|
||||||
return p->placefileManager_->PlacefileEnabled(placefileName);
|
return p->placefileManager_->PlacefileEnabled(placefileName) ?
|
||||||
|
enabledString :
|
||||||
|
disabledString;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case static_cast<int>(Column::Thresholds):
|
case static_cast<int>(Column::Thresholds):
|
||||||
if (role == types::ItemDataRole::SortRole)
|
if (role == Qt::ItemDataRole::ToolTipRole)
|
||||||
{
|
{
|
||||||
return p->placefileManager_->PlacefileThresholded(placefileName);
|
return p->placefileManager_->PlacefileThresholded(placefileName) ?
|
||||||
|
thresholdsEnabledString :
|
||||||
|
thresholdsDisabledString;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case static_cast<int>(Column::Url):
|
case static_cast<int>(Column::Placefile):
|
||||||
return QString::fromStdString(placefileName);
|
|
||||||
|
|
||||||
case static_cast<int>(Column::Description):
|
|
||||||
{
|
{
|
||||||
auto placefile = p->placefileManager_->Placefile(placefileName);
|
std::string description = placefileName;
|
||||||
|
auto placefile = p->placefileManager_->Placefile(placefileName);
|
||||||
if (placefile != nullptr)
|
if (placefile != nullptr)
|
||||||
{
|
{
|
||||||
return QString::fromStdString(placefile->title());
|
std::string title = placefile->title();
|
||||||
|
if (!title.empty())
|
||||||
|
{
|
||||||
|
description = title + '\n' + description;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return QString {};
|
|
||||||
|
return QString::fromStdString(description);
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (role == types::ItemDataRole::SortRole)
|
||||||
|
{
|
||||||
|
switch (index.column())
|
||||||
|
{
|
||||||
|
case static_cast<int>(Column::Enabled):
|
||||||
|
return p->placefileManager_->PlacefileEnabled(placefileName);
|
||||||
|
|
||||||
|
case static_cast<int>(Column::Thresholds):
|
||||||
|
return p->placefileManager_->PlacefileThresholded(placefileName);
|
||||||
|
|
||||||
|
case static_cast<int>(Column::Placefile):
|
||||||
|
return QString::fromStdString(placefileName);
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (role == Qt::ItemDataRole::CheckStateRole)
|
else if (role == Qt::ItemDataRole::CheckStateRole)
|
||||||
{
|
{
|
||||||
switch (index.column())
|
switch (index.column())
|
||||||
{
|
{
|
||||||
case static_cast<int>(Column::Enabled):
|
case static_cast<int>(Column::Enabled):
|
||||||
return p->placefileManager_->PlacefileEnabled(placefileName);
|
return static_cast<int>(
|
||||||
|
p->placefileManager_->PlacefileEnabled(placefileName) ?
|
||||||
|
Qt::CheckState::Checked :
|
||||||
|
Qt::CheckState::Unchecked);
|
||||||
|
|
||||||
case static_cast<int>(Column::Thresholds):
|
case static_cast<int>(Column::Thresholds):
|
||||||
return p->placefileManager_->PlacefileThresholded(placefileName);
|
return static_cast<int>(
|
||||||
|
p->placefileManager_->PlacefileThresholded(placefileName) ?
|
||||||
|
Qt::CheckState::Checked :
|
||||||
|
Qt::CheckState::Unchecked);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
@ -147,41 +187,53 @@ QVariant PlacefileModel::headerData(int section,
|
||||||
switch (section)
|
switch (section)
|
||||||
{
|
{
|
||||||
case static_cast<int>(Column::Enabled):
|
case static_cast<int>(Column::Enabled):
|
||||||
return tr("Enabled");
|
return tr("E");
|
||||||
|
|
||||||
case static_cast<int>(Column::Thresholds):
|
case static_cast<int>(Column::Thresholds):
|
||||||
return tr("Thresholds");
|
return tr("T");
|
||||||
|
|
||||||
case static_cast<int>(Column::Url):
|
case static_cast<int>(Column::Placefile):
|
||||||
return tr("URL");
|
return tr("Placefile");
|
||||||
|
|
||||||
case static_cast<int>(Column::Description):
|
|
||||||
return tr("Description");
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (role == Qt::ItemDataRole::SizeHintRole)
|
else if (role == Qt::ItemDataRole::ToolTipRole)
|
||||||
{
|
{
|
||||||
static const QFontMetrics fontMetrics(QApplication::font());
|
|
||||||
|
|
||||||
QSize contentsSize {};
|
|
||||||
|
|
||||||
switch (section)
|
switch (section)
|
||||||
{
|
{
|
||||||
case static_cast<int>(Column::Url):
|
case static_cast<int>(Column::Enabled):
|
||||||
contentsSize = fontMetrics.size(0, QString(15, 'W'));
|
return tr("Enabled");
|
||||||
break;
|
|
||||||
|
case static_cast<int>(Column::Thresholds):
|
||||||
|
return tr("Thresholds");
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (contentsSize != QSize {})
|
else if (role == Qt::ItemDataRole::SizeHintRole)
|
||||||
|
{
|
||||||
|
switch (section)
|
||||||
{
|
{
|
||||||
return contentsSize;
|
case static_cast<int>(Column::Enabled):
|
||||||
|
case static_cast<int>(Column::Thresholds):
|
||||||
|
{
|
||||||
|
static const QCheckBox checkBox {};
|
||||||
|
QStyleOptionButton option {};
|
||||||
|
option.initFrom(&checkBox);
|
||||||
|
|
||||||
|
// Width values from QCheckBox
|
||||||
|
return QApplication::style()->sizeFromContents(
|
||||||
|
QStyle::ContentsType::CT_CheckBox,
|
||||||
|
&option,
|
||||||
|
{option.iconSize.width() + 4, 0});
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,9 @@ class PlacefileModel : public QAbstractTableModel
|
||||||
public:
|
public:
|
||||||
enum class Column : int
|
enum class Column : int
|
||||||
{
|
{
|
||||||
Enabled = 0,
|
Enabled = 0,
|
||||||
Thresholds = 1,
|
Thresholds = 1,
|
||||||
Url = 2,
|
Placefile = 2
|
||||||
Description = 3
|
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit PlacefileModel(QObject* parent = nullptr);
|
explicit PlacefileModel(QObject* parent = nullptr);
|
||||||
|
|
|
||||||
|
|
@ -58,19 +58,21 @@ PlacefileSettingsWidget::PlacefileSettingsWidget(QWidget* parent) :
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
ui->placefileView->setModel(p->placefileProxyModel_);
|
ui->placefileView->setModel(p->placefileProxyModel_);
|
||||||
ui->placefileView->header()->setSortIndicator(
|
|
||||||
static_cast<int>(model::PlacefileModel::Column::Url), Qt::AscendingOrder);
|
|
||||||
|
|
||||||
ui->placefileView->resizeColumnToContents(
|
auto placefileViewHeader = ui->placefileView->header();
|
||||||
static_cast<int>(model::PlacefileModel::Column::Enabled));
|
|
||||||
ui->placefileView->resizeColumnToContents(
|
|
||||||
static_cast<int>(model::PlacefileModel::Column::Thresholds));
|
|
||||||
ui->placefileView->resizeColumnToContents(
|
|
||||||
static_cast<int>(model::PlacefileModel::Column::Url));
|
|
||||||
|
|
||||||
ui->placefileView->setItemDelegateForColumn(
|
placefileViewHeader->setMinimumSectionSize(10);
|
||||||
static_cast<int>(model::PlacefileModel::Column::Url),
|
placefileViewHeader->setSortIndicator(
|
||||||
p->leftElidedItemDelegate_);
|
static_cast<int>(model::PlacefileModel::Column::Placefile),
|
||||||
|
Qt::AscendingOrder);
|
||||||
|
|
||||||
|
// Enabled and Thresholds columns have a fixed size (checkbox)
|
||||||
|
placefileViewHeader->setSectionResizeMode(
|
||||||
|
static_cast<int>(model::PlacefileModel::Column::Enabled),
|
||||||
|
QHeaderView::ResizeMode::ResizeToContents);
|
||||||
|
placefileViewHeader->setSectionResizeMode(
|
||||||
|
static_cast<int>(model::PlacefileModel::Column::Thresholds),
|
||||||
|
QHeaderView::ResizeMode::ResizeToContents);
|
||||||
|
|
||||||
p->ConnectSignals();
|
p->ConnectSignals();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,9 @@
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTreeView" name="placefileView">
|
<widget class="QTreeView" name="placefileView">
|
||||||
|
<property name="alternatingRowColors">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
<property name="indentation">
|
<property name="indentation">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue