Qt: Fix copy-from menu

It stopped working after moving to the ProfileModel

Change-Id: I20d095ece8ce842e9ded4489fd8e062b35ffc968
Reviewed-on: https://code.wireshark.org/review/34030
Petri-Dish: Roland Knall <rknall@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Roland Knall <rknall@gmail.com>
This commit is contained in:
Roland Knall 2019-07-20 22:53:33 +02:00
parent 3a62b1bc75
commit 4e2a63f543
3 changed files with 46 additions and 16 deletions

View File

@ -248,7 +248,7 @@ QVariant ProfileModel::data(const QModelIndex &index, int role) const
{
QFont font;
if ( prof->is_global || prof->status == PROF_STAT_DEFAULT )
if ( prof->is_global )
font.setItalic(true);
if ( set_profile_.compare(prof->name) == 0 )

View File

@ -20,9 +20,12 @@ CopyFromProfileMenu::CopyFromProfileMenu(QString filename, QWidget *parent) :
{
ProfileModel model(this);
QList<QAction *> global;
QList<QAction *> user;
QActionGroup global(this);
QActionGroup user(this);
QAction * pa = systemDefault(filename);
if ( pa )
global << pa;
for(int cnt = 0; cnt < model.rowCount(); cnt++)
{
@ -45,31 +48,55 @@ CopyFromProfileMenu::CopyFromProfileMenu(QString filename, QWidget *parent) :
if ( ! config_file_exists_with_entries(fi.absoluteFilePath().toUtf8().constData(), '#') )
continue;
QAction * pa = Q_NULLPTR;
if ( idx.data(ProfileModel::DATA_IS_DEFAULT).toBool() || idx.data(ProfileModel::DATA_IS_GLOBAL).toBool() )
pa = global.addAction(idx.data().toString());
QString name = idx.data().toString();
pa = new QAction(name);
if ( idx.data(ProfileModel::DATA_IS_DEFAULT).toBool() )
addAction(pa);
else if ( idx.data(ProfileModel::DATA_IS_GLOBAL).toBool() )
global << pa;
else
pa = user.addAction(idx.data().toString());
pa->setCheckable(true);
if ( idx.data(ProfileModel::DATA_IS_SELECTED).toBool() )
pa->setChecked(true);
user << pa;
pa->setFont(idx.data(Qt::FontRole).value<QFont>());
pa->setProperty("profile_name", idx.data());
pa->setProperty("profile_name", name);
pa->setProperty("profile_is_global", idx.data(ProfileModel::DATA_IS_GLOBAL));
pa->setProperty("filename", fi.absoluteFilePath());
pa->setData(fi.absoluteFilePath().toUtf8().constData());
}
addActions(global.actions());
if (global.actions().count() > 0)
addSeparator();
addActions(user.actions());
addActions(user);
if (global.count() > 0)
{
if ( actions().count() > 0 )
addSeparator();
addActions(global);
}
have_profiles_ = actions().count() > 0;
}
bool CopyFromProfileMenu::haveProfiles()
{
return have_profiles_;
}
// "System default" is not a profile.
// Add a special entry for this if the filename exists.
QAction * CopyFromProfileMenu::systemDefault(QString filename)
{
QAction * data = Q_NULLPTR;
QDir dataDir(get_datafile_dir());
QString path = dataDir.filePath(filename);
if ( QFile::exists(path) )
{
data = new QAction(tr("System default"));
data->setData(path);
QFont font = data->font();
font.setItalic(true);
data->setFont(font);
}
return data;
}

View File

@ -26,6 +26,9 @@ public:
bool haveProfiles();
private:
QAction * systemDefault(QString filename);
bool have_profiles_;
};