mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-21 10:09:39 +00:00
rewrote run tool profile management
This commit is contained in:
parent
717c1b15f5
commit
3ed2edb7cb
2 changed files with 57 additions and 21 deletions
|
@ -1,6 +1,8 @@
|
||||||
|
|
||||||
#include "scenetoolrun.hpp"
|
#include "scenetoolrun.hpp"
|
||||||
|
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
#include <QTableWidget>
|
#include <QTableWidget>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
|
@ -11,11 +13,11 @@ void CSVWidget::SceneToolRun::adjustToolTips()
|
||||||
{
|
{
|
||||||
QString toolTip = mToolTip;
|
QString toolTip = mToolTip;
|
||||||
|
|
||||||
if (mCurrentIndex==-1)
|
if (mSelected==mProfiles.end())
|
||||||
toolTip += "<p>No debug profile selected (function disabled)";
|
toolTip += "<p>No debug profile selected (function disabled)";
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
toolTip += "<p>Debug profile: " + QString::fromUtf8 (mProfiles[mCurrentIndex].c_str());
|
toolTip += "<p>Debug profile: " + QString::fromUtf8 (mSelected->c_str());
|
||||||
toolTip += "<p>(right click to switch to a different profile)";
|
toolTip += "<p>(right click to switch to a different profile)";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,16 +26,19 @@ void CSVWidget::SceneToolRun::adjustToolTips()
|
||||||
|
|
||||||
void CSVWidget::SceneToolRun::updateIcon()
|
void CSVWidget::SceneToolRun::updateIcon()
|
||||||
{
|
{
|
||||||
setIcon (QIcon (mCurrentIndex==-1 ? mIconDisabled : mIcon));
|
setIcon (QIcon (mSelected==mProfiles.end() ? mIconDisabled : mIcon));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVWidget::SceneToolRun::updatePanel()
|
void CSVWidget::SceneToolRun::updatePanel()
|
||||||
{
|
{
|
||||||
mTable->setRowCount (mProfiles.size());
|
mTable->setRowCount (mProfiles.size());
|
||||||
|
|
||||||
for (int i=0; i<static_cast<int> (mProfiles.size()); ++i)
|
int i = 0;
|
||||||
|
|
||||||
|
for (std::set<std::string>::const_iterator iter (mProfiles.begin()); iter!=mProfiles.end();
|
||||||
|
++iter, ++i)
|
||||||
{
|
{
|
||||||
mTable->setItem (i, 0, new QTableWidgetItem (QString::fromUtf8 (mProfiles[i].c_str())));
|
mTable->setItem (i, 0, new QTableWidgetItem (QString::fromUtf8 (iter->c_str())));
|
||||||
|
|
||||||
mTable->setItem (i, 1, new QTableWidgetItem (
|
mTable->setItem (i, 1, new QTableWidgetItem (
|
||||||
QApplication::style()->standardIcon (QStyle::SP_TitleBarCloseButton), ""));
|
QApplication::style()->standardIcon (QStyle::SP_TitleBarCloseButton), ""));
|
||||||
|
@ -42,8 +47,8 @@ void CSVWidget::SceneToolRun::updatePanel()
|
||||||
|
|
||||||
CSVWidget::SceneToolRun::SceneToolRun (SceneToolbar *parent, const QString& toolTip,
|
CSVWidget::SceneToolRun::SceneToolRun (SceneToolbar *parent, const QString& toolTip,
|
||||||
const QString& icon, const QString& iconDisabled, const std::vector<std::string>& profiles)
|
const QString& icon, const QString& iconDisabled, const std::vector<std::string>& profiles)
|
||||||
: SceneTool (parent, Type_TopAction), mProfiles (profiles),
|
: SceneTool (parent, Type_TopAction), mProfiles (profiles.begin(), profiles.end()),
|
||||||
mCurrentIndex (profiles.empty() ? -1 : 0), mToolTip (toolTip), mIcon (icon),
|
mSelected (mProfiles.begin()), mToolTip (toolTip), mIcon (icon),
|
||||||
mIconDisabled (iconDisabled)
|
mIconDisabled (iconDisabled)
|
||||||
{
|
{
|
||||||
updateIcon();
|
updateIcon();
|
||||||
|
@ -80,42 +85,67 @@ void CSVWidget::SceneToolRun::showPanel (const QPoint& position)
|
||||||
|
|
||||||
void CSVWidget::SceneToolRun::activate()
|
void CSVWidget::SceneToolRun::activate()
|
||||||
{
|
{
|
||||||
if (mCurrentIndex!=-1)
|
if (mSelected!=mProfiles.end())
|
||||||
emit runRequest (mProfiles[mCurrentIndex]);
|
emit runRequest (*mSelected);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVWidget::SceneToolRun::removeProfile (const std::string& profile)
|
void CSVWidget::SceneToolRun::removeProfile (const std::string& profile)
|
||||||
{
|
{
|
||||||
std::pair<std::vector<std::string>::iterator, std::vector<std::string>::iterator>
|
std::set<std::string>::iterator iter = mProfiles.find (profile);
|
||||||
result = std::equal_range (mProfiles.begin(), mProfiles.end(), profile);
|
|
||||||
|
|
||||||
if (result.first!=result.second)
|
if (iter!=mProfiles.end())
|
||||||
{
|
{
|
||||||
mProfiles.erase (result.first);
|
if (iter==mSelected)
|
||||||
|
{
|
||||||
|
if (iter!=mProfiles.begin())
|
||||||
|
--mSelected;
|
||||||
|
else
|
||||||
|
++mSelected;
|
||||||
|
}
|
||||||
|
|
||||||
if (mCurrentIndex>=static_cast<int> (mProfiles.size()))
|
mProfiles.erase (iter);
|
||||||
--mCurrentIndex;
|
|
||||||
|
|
||||||
if (mCurrentIndex==-1)
|
if (mSelected==mProfiles.end())
|
||||||
updateIcon();
|
updateIcon();
|
||||||
|
|
||||||
adjustToolTips();
|
adjustToolTips();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSVWidget::SceneToolRun::addProfile (const std::string& profile)
|
||||||
|
{
|
||||||
|
std::set<std::string>::iterator iter = mProfiles.find (profile);
|
||||||
|
|
||||||
|
if (iter==mProfiles.end())
|
||||||
|
{
|
||||||
|
mProfiles.insert (profile);
|
||||||
|
|
||||||
|
if (mSelected==mProfiles.end())
|
||||||
|
{
|
||||||
|
mSelected = mProfiles.begin();
|
||||||
|
updateIcon();
|
||||||
|
}
|
||||||
|
|
||||||
|
adjustToolTips();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CSVWidget::SceneToolRun::clicked (const QModelIndex& index)
|
void CSVWidget::SceneToolRun::clicked (const QModelIndex& index)
|
||||||
{
|
{
|
||||||
if (index.column()==0)
|
if (index.column()==0)
|
||||||
{
|
{
|
||||||
// select profile
|
// select profile
|
||||||
mCurrentIndex = index.row();
|
mSelected = mProfiles.begin();
|
||||||
|
std::advance (mSelected, index.row());
|
||||||
mPanel->hide();
|
mPanel->hide();
|
||||||
adjustToolTips();
|
adjustToolTips();
|
||||||
}
|
}
|
||||||
else if (index.column()==1)
|
else if (index.column()==1)
|
||||||
{
|
{
|
||||||
// remove profile from list
|
// remove profile from list
|
||||||
removeProfile (mProfiles.at (index.row()));
|
std::set<std::string>::iterator iter = mProfiles.begin();
|
||||||
|
std::advance (iter, index.row());
|
||||||
|
removeProfile (*iter);
|
||||||
updatePanel();
|
updatePanel();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef CSV_WIDGET_SCENETOOLRUN_H
|
#ifndef CSV_WIDGET_SCENETOOLRUN_H
|
||||||
#define CSV_WIDGET_SCENETOOLRUN_H
|
#define CSV_WIDGET_SCENETOOLRUN_H
|
||||||
|
|
||||||
#include <vector>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "scenetool.hpp"
|
#include "scenetool.hpp"
|
||||||
|
@ -16,8 +16,8 @@ namespace CSVWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
std::vector<std::string> mProfiles;
|
std::set<std::string> mProfiles;
|
||||||
int mCurrentIndex;
|
std::set<std::string>::iterator mSelected;
|
||||||
QString mToolTip;
|
QString mToolTip;
|
||||||
QString mIcon;
|
QString mIcon;
|
||||||
QString mIconDisabled;
|
QString mIconDisabled;
|
||||||
|
@ -45,6 +45,12 @@ namespace CSVWidget
|
||||||
/// panel.
|
/// panel.
|
||||||
void removeProfile (const std::string& profile);
|
void removeProfile (const std::string& profile);
|
||||||
|
|
||||||
|
/// \attention This function doe not add the profile to the profile selection
|
||||||
|
/// panel. This only happens when the panel is re-opened.
|
||||||
|
///
|
||||||
|
/// \note Adding profiles that are already listed is a no-op.
|
||||||
|
void addProfile (const std::string& profile);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void clicked (const QModelIndex& index);
|
void clicked (const QModelIndex& index);
|
||||||
|
|
Loading…
Reference in a new issue