mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-30 23:50: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) | ||||
| { | ||||
|    logger_->debug("LoadFile: {}", filename); | ||||
|    const std::string placefileName = | ||||
|       QDir::toNativeSeparators(QString::fromStdString(filename)).toStdString(); | ||||
| 
 | ||||
|    logger_->debug("LoadFile: {}", placefileName); | ||||
| 
 | ||||
|    boost::asio::post( | ||||
|       p->threadPool_, | ||||
|       [=, this]() | ||||
|       [placefileName, this]() | ||||
|       { | ||||
|          // Load file
 | ||||
|          std::shared_ptr<gr::Placefile> placefile = | ||||
|             gr::Placefile::Load(filename); | ||||
|             gr::Placefile::Load(placefileName); | ||||
| 
 | ||||
|          if (placefile == nullptr) | ||||
|          { | ||||
|  | @ -182,7 +185,7 @@ void PlacefileManager::LoadFile(const std::string& filename) | |||
|          std::unique_lock lock(p->placefileRecordLock_); | ||||
| 
 | ||||
|          // 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 the placefile has been loaded previously, update it
 | ||||
|  | @ -190,19 +193,19 @@ void PlacefileManager::LoadFile(const std::string& filename) | |||
| 
 | ||||
|             lock.unlock(); | ||||
| 
 | ||||
|             Q_EMIT PlacefileUpdated(filename); | ||||
|             Q_EMIT PlacefileUpdated(placefileName); | ||||
|          } | ||||
|          else | ||||
|          { | ||||
|             // If this is a new placefile, add it
 | ||||
|             auto& record = p->placefileRecords_.emplace_back( | ||||
|                std::make_shared<PlacefileRecord>(filename, placefile)); | ||||
|             p->placefileRecordMap_.insert_or_assign(filename, record); | ||||
|                std::make_shared<PlacefileRecord>(placefileName, placefile)); | ||||
|             p->placefileRecordMap_.insert_or_assign(placefileName, record); | ||||
| 
 | ||||
|             lock.unlock(); | ||||
| 
 | ||||
|             Q_EMIT PlacefileEnabled(filename, record->enabled_); | ||||
|             Q_EMIT PlacefileUpdated(filename); | ||||
|             Q_EMIT PlacefileEnabled(placefileName, record->enabled_); | ||||
|             Q_EMIT PlacefileUpdated(placefileName); | ||||
|          } | ||||
|       }); | ||||
| } | ||||
|  |  | |||
|  | @ -4,7 +4,10 @@ | |||
| #include <scwx/util/logger.hpp> | ||||
| 
 | ||||
| #include <QApplication> | ||||
| #include <QCheckBox> | ||||
| #include <QFontMetrics> | ||||
| #include <QStyle> | ||||
| #include <QStyleOption> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
|  | @ -19,7 +22,7 @@ static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | |||
| static constexpr int kFirstColumn = | ||||
|    static_cast<int>(PlacefileModel::Column::Enabled); | ||||
| static constexpr int kLastColumn = | ||||
|    static_cast<int>(PlacefileModel::Column::Description); | ||||
|    static_cast<int>(PlacefileModel::Column::Placefile); | ||||
| static constexpr int kNumColumns = kLastColumn - kFirstColumn + 1; | ||||
| 
 | ||||
| class PlacefileModelImpl | ||||
|  | @ -82,51 +85,88 @@ QVariant PlacefileModel::data(const QModelIndex& index, int role) const | |||
|    const auto& placefileName = p->placefileNames_.at(index.row()); | ||||
| 
 | ||||
|    if (role == Qt::ItemDataRole::DisplayRole || | ||||
|        role == Qt::ItemDataRole::ToolTipRole || | ||||
|        role == types::ItemDataRole::SortRole) | ||||
|        role == Qt::ItemDataRole::ToolTipRole) | ||||
|    { | ||||
|       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()) | ||||
|       { | ||||
|       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; | ||||
| 
 | ||||
|       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; | ||||
| 
 | ||||
|       case static_cast<int>(Column::Url): | ||||
|          return QString::fromStdString(placefileName); | ||||
| 
 | ||||
|       case static_cast<int>(Column::Description): | ||||
|       case static_cast<int>(Column::Placefile): | ||||
|       { | ||||
|          auto placefile = p->placefileManager_->Placefile(placefileName); | ||||
|          std::string description = placefileName; | ||||
|          auto        placefile = p->placefileManager_->Placefile(placefileName); | ||||
|          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: | ||||
|          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) | ||||
|    { | ||||
|       switch (index.column()) | ||||
|       { | ||||
|       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): | ||||
|          return p->placefileManager_->PlacefileThresholded(placefileName); | ||||
|          return static_cast<int>( | ||||
|             p->placefileManager_->PlacefileThresholded(placefileName) ? | ||||
|                Qt::CheckState::Checked : | ||||
|                Qt::CheckState::Unchecked); | ||||
| 
 | ||||
|       default: | ||||
|          break; | ||||
|  | @ -147,41 +187,53 @@ QVariant PlacefileModel::headerData(int             section, | |||
|          switch (section) | ||||
|          { | ||||
|          case static_cast<int>(Column::Enabled): | ||||
|             return tr("Enabled"); | ||||
|             return tr("E"); | ||||
| 
 | ||||
|          case static_cast<int>(Column::Thresholds): | ||||
|             return tr("Thresholds"); | ||||
|             return tr("T"); | ||||
| 
 | ||||
|          case static_cast<int>(Column::Url): | ||||
|             return tr("URL"); | ||||
| 
 | ||||
|          case static_cast<int>(Column::Description): | ||||
|             return tr("Description"); | ||||
|          case static_cast<int>(Column::Placefile): | ||||
|             return tr("Placefile"); | ||||
| 
 | ||||
|          default: | ||||
|             break; | ||||
|          } | ||||
|       } | ||||
|    } | ||||
|    else if (role == Qt::ItemDataRole::SizeHintRole) | ||||
|    else if (role == Qt::ItemDataRole::ToolTipRole) | ||||
|    { | ||||
|       static const QFontMetrics fontMetrics(QApplication::font()); | ||||
| 
 | ||||
|       QSize contentsSize {}; | ||||
| 
 | ||||
|       switch (section) | ||||
|       { | ||||
|       case static_cast<int>(Column::Url): | ||||
|          contentsSize = fontMetrics.size(0, QString(15, 'W')); | ||||
|          break; | ||||
|       case static_cast<int>(Column::Enabled): | ||||
|          return tr("Enabled"); | ||||
| 
 | ||||
|       case static_cast<int>(Column::Thresholds): | ||||
|          return tr("Thresholds"); | ||||
| 
 | ||||
|       default: | ||||
|          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: | ||||
|    enum class Column : int | ||||
|    { | ||||
|       Enabled     = 0, | ||||
|       Thresholds  = 1, | ||||
|       Url         = 2, | ||||
|       Description = 3 | ||||
|       Enabled    = 0, | ||||
|       Thresholds = 1, | ||||
|       Placefile  = 2 | ||||
|    }; | ||||
| 
 | ||||
|    explicit PlacefileModel(QObject* parent = nullptr); | ||||
|  |  | |||
|  | @ -58,19 +58,21 @@ PlacefileSettingsWidget::PlacefileSettingsWidget(QWidget* parent) : | |||
|    ui->setupUi(this); | ||||
| 
 | ||||
|    ui->placefileView->setModel(p->placefileProxyModel_); | ||||
|    ui->placefileView->header()->setSortIndicator( | ||||
|       static_cast<int>(model::PlacefileModel::Column::Url), Qt::AscendingOrder); | ||||
| 
 | ||||
|    ui->placefileView->resizeColumnToContents( | ||||
|       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)); | ||||
|    auto placefileViewHeader = ui->placefileView->header(); | ||||
| 
 | ||||
|    ui->placefileView->setItemDelegateForColumn( | ||||
|       static_cast<int>(model::PlacefileModel::Column::Url), | ||||
|       p->leftElidedItemDelegate_); | ||||
|    placefileViewHeader->setMinimumSectionSize(10); | ||||
|    placefileViewHeader->setSortIndicator( | ||||
|       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(); | ||||
| } | ||||
|  |  | |||
|  | @ -16,6 +16,9 @@ | |||
|   <layout class="QVBoxLayout" name="verticalLayout"> | ||||
|    <item> | ||||
|     <widget class="QTreeView" name="placefileView"> | ||||
|      <property name="alternatingRowColors"> | ||||
|       <bool>true</bool> | ||||
|      </property> | ||||
|      <property name="indentation"> | ||||
|       <number>0</number> | ||||
|      </property> | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat