full implementation of global run menu item (replaces earlier placeholder implementation)
parent
67dfaa7f35
commit
a728d6d77a
@ -0,0 +1,93 @@
|
||||
|
||||
#include "globaldebugprofilemenu.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include <QActionGroup>
|
||||
|
||||
#include "../../model/world/idtable.hpp"
|
||||
#include "../../model/world/record.hpp"
|
||||
|
||||
void CSVDoc::GlobalDebugProfileMenu::rebuild()
|
||||
{
|
||||
clear();
|
||||
|
||||
delete mActions;
|
||||
mActions = 0;
|
||||
|
||||
int idColumn = mDebugProfiles->findColumnIndex (CSMWorld::Columns::ColumnId_Id);
|
||||
int stateColumn = mDebugProfiles->findColumnIndex (CSMWorld::Columns::ColumnId_Modification);
|
||||
int globalColumn = mDebugProfiles->findColumnIndex (
|
||||
CSMWorld::Columns::ColumnId_GlobalProfile);
|
||||
|
||||
int size = mDebugProfiles->rowCount();
|
||||
|
||||
std::vector<QString> ids;
|
||||
|
||||
for (int i=0; i<size; ++i)
|
||||
{
|
||||
int state = mDebugProfiles->data (mDebugProfiles->index (i, stateColumn)).toInt();
|
||||
|
||||
bool global = mDebugProfiles->data (mDebugProfiles->index (i, globalColumn)).toInt();
|
||||
|
||||
if (state!=CSMWorld::RecordBase::State_Deleted && global)
|
||||
ids.push_back (
|
||||
mDebugProfiles->data (mDebugProfiles->index (i, idColumn)).toString());
|
||||
}
|
||||
|
||||
mActions = new QActionGroup (this);
|
||||
connect (mActions, SIGNAL (triggered (QAction *)), this, SLOT (actionTriggered (QAction *)));
|
||||
|
||||
std::sort (ids.begin(), ids.end());
|
||||
|
||||
for (std::vector<QString>::const_iterator iter (ids.begin()); iter!=ids.end(); ++iter)
|
||||
{
|
||||
mActions->addAction (addAction (*iter));
|
||||
}
|
||||
}
|
||||
|
||||
CSVDoc::GlobalDebugProfileMenu::GlobalDebugProfileMenu (CSMWorld::IdTable *debugProfiles,
|
||||
QWidget *parent)
|
||||
: QMenu (parent), mDebugProfiles (debugProfiles), mActions (0)
|
||||
{
|
||||
rebuild();
|
||||
|
||||
connect (mDebugProfiles, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)),
|
||||
this, SLOT (profileAboutToBeRemoved (const QModelIndex&, int, int)));
|
||||
|
||||
connect (mDebugProfiles, SIGNAL (rowsInserted (const QModelIndex&, int, int)),
|
||||
this, SLOT (profileInserted (const QModelIndex&, int, int)));
|
||||
|
||||
connect (mDebugProfiles, SIGNAL (dataChanged (const QModelIndex&, const QModelIndex&)),
|
||||
this, SLOT (profileChanged (const QModelIndex&, const QModelIndex&)));
|
||||
}
|
||||
|
||||
void CSVDoc::GlobalDebugProfileMenu::updateActions (bool running)
|
||||
{
|
||||
if (mActions)
|
||||
mActions->setEnabled (!running);
|
||||
}
|
||||
|
||||
void CSVDoc::GlobalDebugProfileMenu::profileAboutToBeRemoved (const QModelIndex& parent,
|
||||
int start, int end)
|
||||
{
|
||||
rebuild();
|
||||
}
|
||||
|
||||
void CSVDoc::GlobalDebugProfileMenu::profileInserted (const QModelIndex& parent, int start,
|
||||
int end)
|
||||
{
|
||||
rebuild();
|
||||
}
|
||||
|
||||
void CSVDoc::GlobalDebugProfileMenu::profileChanged (const QModelIndex& topLeft,
|
||||
const QModelIndex& bottomRight)
|
||||
{
|
||||
rebuild();
|
||||
}
|
||||
|
||||
void CSVDoc::GlobalDebugProfileMenu::actionTriggered (QAction *action)
|
||||
{
|
||||
emit triggered (std::string (action->text().toUtf8().constData()));
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
#ifndef CSV_DOC_GLOBALDEBUGPROFILEMENU_H
|
||||
#define CSV_DOC_GLOBALDEBUGPROFILEMENU_H
|
||||
|
||||
#include <QMenu>
|
||||
|
||||
class QModelIndex;
|
||||
class QActionGroup;
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class IdTable;
|
||||
}
|
||||
|
||||
namespace CSVDoc
|
||||
{
|
||||
class GlobalDebugProfileMenu : public QMenu
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
CSMWorld::IdTable *mDebugProfiles;
|
||||
QActionGroup *mActions;
|
||||
|
||||
private:
|
||||
|
||||
void rebuild();
|
||||
|
||||
public:
|
||||
|
||||
GlobalDebugProfileMenu (CSMWorld::IdTable *debugProfiles, QWidget *parent = 0);
|
||||
|
||||
void updateActions (bool running);
|
||||
|
||||
private slots:
|
||||
|
||||
void profileAboutToBeRemoved (const QModelIndex& parent, int start, int end);
|
||||
|
||||
void profileInserted (const QModelIndex& parent, int start, int end);
|
||||
|
||||
void profileChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);
|
||||
|
||||
void actionTriggered (QAction *action);
|
||||
|
||||
signals:
|
||||
|
||||
void triggered (const std::string& profile);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue