MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / openCfg

Method openCfg

gui/librarydialog.cpp:92–146  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92void LibraryDialog::openCfg()
93{
94 const QString datadir = getDataDir();
95
96 QString selectedFilter;
97 const QString filter(tr("Library files (*.cfg)"));
98 const QString selectedFile = QFileDialog::getOpenFileName(this,
99 tr("Open library file"),
100 datadir,
101 filter,
102 &selectedFilter);
103
104 if (selectedFile.isEmpty())
105 return;
106
107 QFile file(selectedFile);
108 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
109 QMessageBox msg(QMessageBox::Critical,
110 tr("Cppcheck"),
111 tr("Cannot open file %1.").arg(selectedFile),
112 QMessageBox::Ok,
113 this);
114 msg.exec();
115 return;
116 }
117
118 CppcheckLibraryData tempdata;
119 const QString errmsg = tempdata.open(file);
120 if (!errmsg.isNull()) {
121 QMessageBox msg(QMessageBox::Critical,
122 tr("Cppcheck"),
123 tr("Failed to load %1. %2.").arg(selectedFile).arg(errmsg),
124 QMessageBox::Ok,
125 this);
126 msg.exec();
127 return;
128 }
129
130 mIgnoreChanges = true;
131 mData.swap(tempdata);
132 mFileName = selectedFile;
133 mUi->buttonSave->setEnabled(false);
134 mUi->buttonSaveAs->setEnabled(true);
135 mUi->filter->clear();
136 mUi->functions->clear();
137 for (CppcheckLibraryData::Function &function : mData.functions) {
138 mUi->functions->addItem(new FunctionListItem(mUi->functions,
139 &function,
140 false));
141 }
142 mUi->sortFunctions->setEnabled(!mData.functions.empty());
143 mUi->filter->setEnabled(!mData.functions.empty());
144 mUi->addFunction->setEnabled(true);
145 mIgnoreChanges = false;
146}
147
148void LibraryDialog::saveCfg()
149{

Callers

nothing calls this directly

Calls 8

getDataDirFunction · 0.85
isEmptyMethod · 0.80
setEnabledMethod · 0.80
addItemMethod · 0.80
openMethod · 0.45
swapMethod · 0.45
clearMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected