mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-12-17 16:38:20 -05:00
50846fe90a
This allows writable files to be located in the "correct" location for each platform rather than in the directory of the executable which, in general, is not recommended or allowed in some cases. A preprocessor macro WSJT_STANDARD_FILE_LOCATIONS is used to switch be tween old and new functionality, currently it is on by default. It can be turned off by defining it to a false value (0) or more simply with cmake-gui setting the option with the same name. JTAlert can only work with the old non-standard file locations until Laurie VK3AMA chooses to support the new file locations. Even if the above is not enabled; the QSettings file is written to a user specific location so it will be shared by all instances of the program (i.e. across upgrades). See below for multiple concurrent instance support changes. Added a command line parser module for Fortran. Added 'lib/options.f90' to facilitate more complex argument passing to jt9 to cover explicit file locations. Changed the way multiple concurrent instances are handled. This is to allow the program to be run multiple times from the same installation directory. A new wsjtx command line optional argument is available "-r" or "--rig" which enables multiple concurrent instance support. The parameter of the new option is a unique name signifying a rig or equivalent. The name is used as the shared memory segment key and in window titles. The name is also used to access unique settings files and writable data files like ALL.TXT and log files. No attempt has been made to share these files between concurrent instances. If "-r" or "--rig" is used without a parameter it still enables multiple concurrent instance support for that instance. All instances must use a unique parameter, one of which may be empty. The rig name is appended the QCoreApplication::applicationName() for convenient usage like window titles. Set non Qt locale to "C". This ensures that C library functions give consistent results whatever the system locale is set to. QApplication follows the system locale as before. Thus using QApplication and its descendants like widgets and QString for all user visible formating will give correct l10n and using C/C++ library will give consistent formatting across locales. Added top level C++ exception handling to main.cpp. Because the new transceiver framework uses exceptions internally, the main function now handles any exceptions that aren't caught. Retired devsetup, replaced with Configuration. Configuration is a class that encapsulates most of the configuration behavior. Because rig configuration is so closely coupled with rig operation, Configuration serves as a proxy for access to the rig control functions. See Configuration.hpp for more details of the Configuration interface. Menu changes. Various checkable menu actions moved from main menu to the Configuration dialog. The whole settings menu has been retired with the single "Settings..." action moved to the file menu for consistency on Mac where it appears as "Preferences" in line with Mac guidelines. New data models for data used by the application. ADIF amateur band parameters, free text message macros, spot working frequencies and, station information (station descriptions and transverter offsets per band) each implement the QAbstractItemModel interface allowing them to be used directly with Qt view widgets (Bands.hpp, FrequencyList.hpp and, StationList.hpp). Configuration manages maintenance of an instance of all but the former of the above models. The ADIF band model is owned by Configuration but requires no user maintenance as it is immutable. Band combo box gets more functionality. This widget is now an editable QComboBox with some extra input capabilities. The popup list is still the list of spot working frequencies, now showing the actual frequency decorated with the band name. This allows multiple spot frequencies on a band if required. The line edit allows direct frequency entry in mega-Hertz with a completer built in to suggest the available spot working frequencies. It also allows band name entry where the first available spot working frequency is selected. Recognized band names are those that are defined by the ADIF specification and can be found in in the implementation of the ADIF bands model (Bands.cpp). If an out of band frequency is chosen, the line edit shows a warning red background and the text "OOB". Out of band is only defined by the ADIF band limits which in general are wider than any entities regulations. Qt 5.2 now supports default audio i/p and o/p devices. These devices are placeholders for whatever the user defines as the default device. Because of this they need special treatment as the actual device used is chosen at open time behind the scenes. Close-down behavior is simplified. The close-down semantics were broken such that some objects were not being shut down cleanly, this required amendments to facilitate correct close down of threads. User font selection added to Configuration UI. Buttons to set the application font and the font for the band and Rx frequency activity widgets have been added to the Configuration UI to replace the file based font size control. Free text macros now selected directly. The free text line edit widgets are now editable combo boxes that have the current free text macro definitions as their popup list. The old context menu to do this has been retired. Astronomical data window dynamically formatted and has font a chooser. This window is now autonomous, has its own font chooser and, dynamically resizes to cover the contents. Double click to Tx enabled now has its own widget in the status bar. QDir used for portable path and file name handling throughout. The "Monitor", "Decode", "Enable Tx" and, "Tune" buttons are now checkable. Being checkable allows these buttons control their own state and rendering. Calls to PSK Reporter interface simplified. In mainwindow.cpp the calls to this interface are rationalized to just 3 locations. Manipulation of ALL.TXT simplified. Moved, where possible, to common functions. Elevated frequency types to be Qt types. Frequency and FrequencyDelta defined as Qt types in their meta-type system (Radio.hpp). They are integral types for maximum accuracy. Re-factored rig control calls in mainwindow.cpp. The new Configuration proxy access to rig control required many changes (mostly simplifications) to the MainWindow rig control code. Some common code has been gathered in member functions like qsy(), monitor(), band_changed() and auto_tx_mode(). Rig control enhancements. The rig control for clients interface is declared as an abstract interface (See Transceiver.hpp). Concrete implementations of this interface are provided for the Hamlib rig control library, DX Lab Suite Commander via a TCP/IP command channel, Ham Radio Deluxe also via a TCP/IP command channel and, OmniRig via its Windows COM server interface. Concrete Transceiver implementations are expected to be moved to a separate thread after construction since many operations are blocking and not suitable for running in a GUI thread. To facilitate this all instantiation of concrete Transceiver instances are handled by Configuration using a factory class (TransceiverFactory) for configuration parameter based instantiation. Various common functionality shared by different rig interface implementations are factored out into helper base classes that implement or delegate parts of the Transceiver interface. They are TransceiverBase which caches state to minimize expensive rig commands, it also maps the Transceiver interface into a more convenient form for implementation (template methods). PollingTransceiver that provides a state polling mechanism that only reports actual changes. EmulateSplitTransceiver that provides split operation by QSYing on PTT state changes. EmulateSplitTransceiver can be used with any implementation as it follows the GoF Decorator pattern and can wrap any Transceiver implementation. OmniRigTransceiver is derived directly from TransceiverBase since it doesn't require polling due to its asynchronous nature. OmniRigTransceiver is only built on Windows as it is a COM server client. To build it you must first install the OmniRig client on the development machine (http://www.dxatlas.com/omnirig/). DXLabSuiteCommanderTransceiver derives from PollingTransceiver since it is a synchronous communications channel. No third party library is required for this interface. HRDTransceiver also derives from PollingTransceiver. The HRD interface library has been reverse engineered to provide functionality with all available versions of HRD. No third party libraries are required. HamlibTransceiver likewise derives from PollingTransceiver since the Hamlib asynchronous interface is non-functional. Although this class will interface with the release version of Hamlib (1.2.15.3); for correct operation on most rigs it needs to run with the latest master branch code of Hamlib. During development many changes to Hamlib have been submitted and accepted, hence this requirement. Hamlib source can be obtained from git://git.code.sf.net/p/hamlib/code and at the time of writing he master branch was at SHA 6e4432. The Hamlib interface directly calls the "C" interface and the modified rigclass.{h,cpp} files have been retired. There is a rig type selection of "None" which may be used for non-CAT rigs, this is actually a connection to the dummy Hamlib device. PollingTransvceiver derives from TransceiverBase and TransceiverBase derives from the Transceiver interface. Each interface implementation offers some possibility of PTT control via a different serial port than the CAT port. We also support PTT control directly via a second serial port. This is done by delegating to a dummy Hamlib instance which is only used for PTT control. This means that DXLabSuiteCommanderTransceiver, HRDTransceiver and OmniRigTransceiver always wrap a dummy HamlibTransceiver instance. The factory class TransceiverFactory manages all these constructional complexities. Serial port selection combo boxes are now editable with a manually entered value being saved to the settings file. This allows a non-standard port device to be used without having to edit the settings file manually. For TCP/IP network CAT interfaces; the network address and port may be specified allowing the target device to be located on a different machine from the one running wsjtx if required. The default used when the address field is left blank is the correct one for normal usage on the local host. Selecting a polling interval of zero is no longer possible, this is because the rig control capability can no longer support one way connection. This is in line with most other CAT control software. In the Configuration dialog there are options to select split mode control by the software and mode control by the software. For the former "None", "Rig" and "Fake it" are available, for the latter "None", "USB" and, "Data" are available. Because tone generation is implicitly linked to split mode operation; it is no longer possible to have the software in split mode and the rig not or vice versa. This may mean some rigs cannot be used in split mode and therefore not in dual JT65+JT9 until issues with CAT control with that rig are resolved. Single mode with VOX keying and no CAT control are still possible so even the most basic transceiver setup is supported as before. Configuration now supports a frequency offset suitable for transverter operation. The station details model (StationList.hpp) includes a column to store an offset for each band if required. CMake build script improvements. The CMakeLists.txt from the 'lib' directory has been retired with its contents merged into the top level CMakeLists.txt. Install target support has been greatly improved with the Release build configuration now building a fully standalone installation on Mac and Windows. The Debug configuration still builds an installation that has environment dependencies for external libraries, which is desirable for testing and debugging. Package target support is largely complete for Mac, Windows and, Linux, it should be possible to build release installers directly from CMake/CPack. Cmake FindXXXX.cmake modules have been added to improve the location of fftw-3 and Hamlib packages. Version numbers are now stored in Versions.cmake and work in concert with automatic svn revision lookup during build. The version string becomes 'rlocal'± if there are any uncommitted changes in the build source tree. Moved resource like files to Qt resources. Because location of resource files (when they cannot go into the installation directory because of packaging rules) is hard to standardize. I have used the Qt resource system for all ancillary data files. Some like kvasd.dat are dumped out to the temp (working directory) because they are accessed by an external program, others like the audio samples are copied out so they appear in the data directory under the default save directory. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@3929 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
552 lines
14 KiB
C++
552 lines
14 KiB
C++
#include "StationList.hpp"
|
|
|
|
#include <utility>
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
|
|
#include <QMetaType>
|
|
#include <QAbstractTableModel>
|
|
#include <QObject>
|
|
#include <QString>
|
|
#include <QVector>
|
|
#include <QStringList>
|
|
#include <QMimeData>
|
|
#include <QDataStream>
|
|
#include <QByteArray>
|
|
#include <QDebug>
|
|
|
|
#include "pimpl_impl.hpp"
|
|
|
|
#include "Bands.hpp"
|
|
|
|
namespace
|
|
{
|
|
struct init
|
|
{
|
|
init ()
|
|
{
|
|
qRegisterMetaType<StationList::Station> ("Station");
|
|
qRegisterMetaTypeStreamOperators<StationList::Station> ("Station");
|
|
qRegisterMetaType<StationList::Stations> ("Stations");
|
|
qRegisterMetaTypeStreamOperators<StationList::Stations> ("Stations");
|
|
}
|
|
} static_initializer;
|
|
}
|
|
|
|
#if !defined (QT_NO_DEBUG_STREAM)
|
|
QDebug operator << (QDebug debug, StationList::Station const& station)
|
|
{
|
|
debug.nospace () << "Station("
|
|
<< station.band_name_ << ", "
|
|
<< station.offset_ << ", "
|
|
<< station.antenna_description_ << ')';
|
|
return debug.space ();
|
|
}
|
|
#endif
|
|
|
|
QDataStream& operator << (QDataStream& os, StationList::Station const& station)
|
|
{
|
|
return os << station.band_name_
|
|
<< station.offset_
|
|
<< station.antenna_description_;
|
|
}
|
|
|
|
QDataStream& operator >> (QDataStream& is, StationList::Station& station)
|
|
{
|
|
return is >> station.band_name_
|
|
>> station.offset_
|
|
>> station.antenna_description_;
|
|
}
|
|
|
|
|
|
class StationList::impl final
|
|
: public QAbstractTableModel
|
|
{
|
|
public:
|
|
impl (Bands const * bands, Stations stations, QObject * parent)
|
|
: QAbstractTableModel {parent}
|
|
, bands_ {bands}
|
|
, stations_ {stations}
|
|
{
|
|
}
|
|
|
|
Stations const& stations () const {return stations_;}
|
|
void assign (Stations);
|
|
QModelIndex add (Station);
|
|
FrequencyDelta offset (Frequency) const;
|
|
|
|
protected:
|
|
// Implement the QAbstractTableModel interface.
|
|
int rowCount (QModelIndex const& parent = QModelIndex {}) const override;
|
|
int columnCount (QModelIndex const& parent = QModelIndex {}) const override;
|
|
Qt::ItemFlags flags (QModelIndex const& = QModelIndex {}) const override;
|
|
QVariant data (QModelIndex const&, int role) const override;
|
|
QVariant headerData (int section, Qt::Orientation, int = Qt::DisplayRole) const override;
|
|
bool setData (QModelIndex const&, QVariant const& value, int role = Qt::EditRole) override;
|
|
bool removeRows (int row, int count, QModelIndex const& parent = QModelIndex {}) override;
|
|
bool insertRows (int row, int count, QModelIndex const& parent = QModelIndex {}) override;
|
|
Qt::DropActions supportedDropActions () const override;
|
|
QStringList mimeTypes () const override;
|
|
QMimeData * mimeData (QModelIndexList const&) const override;
|
|
bool dropMimeData (QMimeData const *, Qt::DropAction, int row, int column, QModelIndex const& parent) override;
|
|
|
|
private:
|
|
// Helper method for band validation.
|
|
QModelIndex first_matching_band (QString const& band_name) const
|
|
{
|
|
// find first exact match in bands
|
|
auto matches = bands_->match (bands_->index (0, 0)
|
|
, Qt::DisplayRole
|
|
, band_name
|
|
, 1
|
|
, Qt::MatchExactly);
|
|
return matches.isEmpty () ? QModelIndex {} : matches.first ();
|
|
}
|
|
|
|
static int constexpr num_columns {3};
|
|
static auto constexpr mime_type = "application/wsjt.antenna-descriptions";
|
|
|
|
Bands const * bands_;
|
|
Stations stations_;
|
|
};
|
|
|
|
StationList::StationList (Bands const * bands, QObject * parent)
|
|
: StationList {bands, {}, parent}
|
|
{
|
|
}
|
|
|
|
StationList::StationList (Bands const * bands, Stations stations, QObject * parent)
|
|
: QSortFilterProxyModel {parent}
|
|
, m_ {bands, stations, parent}
|
|
{
|
|
// setDynamicSortFilter (true);
|
|
setSourceModel (&*m_);
|
|
setSortRole (SortRole);
|
|
}
|
|
|
|
StationList::~StationList ()
|
|
{
|
|
}
|
|
|
|
StationList& StationList::operator = (Stations stations)
|
|
{
|
|
m_->assign (stations);
|
|
return *this;
|
|
}
|
|
|
|
auto StationList::stations () const -> Stations
|
|
{
|
|
return m_->stations ();
|
|
}
|
|
|
|
QModelIndex StationList::add (Station s)
|
|
{
|
|
return mapFromSource (m_->add (s));
|
|
}
|
|
|
|
bool StationList::remove (Station s)
|
|
{
|
|
auto row = m_->stations ().indexOf (s);
|
|
|
|
if (0 > row)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return removeRow (row);
|
|
}
|
|
|
|
namespace
|
|
{
|
|
bool row_is_higher (QModelIndex const& lhs, QModelIndex const& rhs)
|
|
{
|
|
return lhs.row () > rhs.row ();
|
|
}
|
|
}
|
|
|
|
bool StationList::removeDisjointRows (QModelIndexList rows)
|
|
{
|
|
bool result {true};
|
|
|
|
// We must work with source model indexes because we don't want row
|
|
// removes to invalidate model indexes we haven't yet processed. We
|
|
// achieve that by processing them in decending row order.
|
|
for (int r = 0; r < rows.size (); ++r)
|
|
{
|
|
rows[r] = mapToSource (rows[r]);
|
|
}
|
|
|
|
// reverse sort by row
|
|
qSort (rows.begin (), rows.end (), row_is_higher);
|
|
Q_FOREACH (auto index, rows)
|
|
{
|
|
if (result && !m_->removeRow (index.row ()))
|
|
{
|
|
result = false;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
auto StationList::offset (Frequency f) const -> FrequencyDelta
|
|
{
|
|
return m_->offset (f);
|
|
}
|
|
|
|
|
|
void StationList::impl::assign (Stations stations)
|
|
{
|
|
beginResetModel ();
|
|
std::swap (stations_, stations);
|
|
endResetModel ();
|
|
}
|
|
|
|
QModelIndex StationList::impl::add (Station s)
|
|
{
|
|
// Any band that isn't in the list may be added
|
|
if (!stations_.contains (s))
|
|
{
|
|
auto row = stations_.size ();
|
|
|
|
beginInsertRows (QModelIndex {}, row, row);
|
|
stations_.append (s);
|
|
endInsertRows ();
|
|
|
|
return index (row, 0);
|
|
}
|
|
|
|
return QModelIndex {};
|
|
}
|
|
|
|
auto StationList::impl::offset (Frequency f) const -> FrequencyDelta
|
|
{
|
|
// Lookup band for frequency
|
|
auto band_index = bands_->find (f);
|
|
if (band_index.isValid ())
|
|
{
|
|
auto band_name = band_index.data ().toString ();
|
|
|
|
// Lookup station for band
|
|
for (int i = 0; i < stations ().size (); ++i)
|
|
{
|
|
if (stations_[i].band_name_ == band_name)
|
|
{
|
|
return stations_[i].offset_;
|
|
}
|
|
}
|
|
}
|
|
|
|
return 0; // no offset
|
|
}
|
|
|
|
int StationList::impl::rowCount (QModelIndex const& parent) const
|
|
{
|
|
return parent.isValid () ? 0 : stations_.size ();
|
|
}
|
|
|
|
int StationList::impl::columnCount (QModelIndex const& parent) const
|
|
{
|
|
return parent.isValid () ? 0 : num_columns;
|
|
}
|
|
|
|
Qt::ItemFlags StationList::impl::flags (QModelIndex const& index) const
|
|
{
|
|
auto result = QAbstractTableModel::flags (index);
|
|
|
|
auto row = index.row ();
|
|
auto column = index.column ();
|
|
|
|
if (index.isValid ()
|
|
&& row < stations_.size ()
|
|
&& column < num_columns)
|
|
{
|
|
if (2 == column)
|
|
{
|
|
result |= Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
|
|
}
|
|
else
|
|
{
|
|
result |= Qt::ItemIsEditable | Qt::ItemIsDropEnabled;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
result |= Qt::ItemIsDropEnabled;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
QVariant StationList::impl::data (QModelIndex const& index, int role) const
|
|
{
|
|
QVariant item;
|
|
|
|
auto row = index.row ();
|
|
auto column = index.column ();
|
|
|
|
if (index.isValid ()
|
|
&& row < stations_.size ())
|
|
{
|
|
switch (column)
|
|
{
|
|
case 0: // band name
|
|
switch (role)
|
|
{
|
|
case SortRole:
|
|
{
|
|
// Lookup band.
|
|
auto band_index = first_matching_band (stations_.at (row).band_name_);
|
|
// Use the sort role value of the band.
|
|
item = band_index.data (Bands::SortRole);
|
|
}
|
|
break;
|
|
|
|
case Qt::DisplayRole:
|
|
case Qt::EditRole:
|
|
case Qt::AccessibleTextRole:
|
|
item = stations_.at (row).band_name_;
|
|
break;
|
|
|
|
case Qt::ToolTipRole:
|
|
case Qt::AccessibleDescriptionRole:
|
|
item = tr ("Band name");
|
|
break;
|
|
|
|
case Qt::TextAlignmentRole:
|
|
item = Qt::AlignHCenter + Qt::AlignVCenter;
|
|
break;
|
|
}
|
|
break;
|
|
|
|
case 1: // frequency offset
|
|
{
|
|
auto frequency_offset = stations_.at (row).offset_;
|
|
switch (role)
|
|
{
|
|
case Qt::AccessibleTextRole:
|
|
item = frequency_offset;
|
|
break;
|
|
|
|
case SortRole:
|
|
case Qt::DisplayRole:
|
|
case Qt::EditRole:
|
|
item = frequency_offset;
|
|
break;
|
|
|
|
case Qt::ToolTipRole:
|
|
case Qt::AccessibleDescriptionRole:
|
|
item = tr ("Frequency offset");
|
|
break;
|
|
|
|
case Qt::TextAlignmentRole:
|
|
item = Qt::AlignRight + Qt::AlignVCenter;
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
|
|
case 2: // antenna description
|
|
switch (role)
|
|
{
|
|
case SortRole:
|
|
case Qt::EditRole:
|
|
case Qt::DisplayRole:
|
|
case Qt::AccessibleTextRole:
|
|
item = stations_.at (row).antenna_description_;
|
|
break;
|
|
|
|
case Qt::ToolTipRole:
|
|
case Qt::AccessibleDescriptionRole:
|
|
item = tr ("Antenna description");
|
|
break;
|
|
|
|
case Qt::TextAlignmentRole:
|
|
item = Qt::AlignLeft + Qt::AlignVCenter;
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
return item;
|
|
}
|
|
|
|
QVariant StationList::impl::headerData (int section, Qt::Orientation orientation, int role) const
|
|
{
|
|
QVariant header;
|
|
|
|
if (Qt::DisplayRole == role && Qt::Horizontal == orientation)
|
|
{
|
|
switch (section)
|
|
{
|
|
case 0: header = tr ("Band"); break;
|
|
case 1: header = tr ("Offset"); break;
|
|
case 2: header = tr ("Antenna Description"); break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
header = QAbstractTableModel::headerData (section, orientation, role);
|
|
}
|
|
|
|
return header;
|
|
}
|
|
|
|
bool StationList::impl::setData (QModelIndex const& model_index, QVariant const& value, int role)
|
|
{
|
|
bool changed {false};
|
|
|
|
auto row = model_index.row ();
|
|
auto size = stations_.size ();
|
|
if (model_index.isValid ()
|
|
&& Qt::EditRole == role
|
|
&& row < size)
|
|
{
|
|
QVector<int> roles;
|
|
roles << role;
|
|
|
|
switch (model_index.column ())
|
|
{
|
|
case 0:
|
|
{
|
|
// Check if band name is valid.
|
|
auto band_index = first_matching_band (value.toString ());
|
|
if (band_index.isValid ())
|
|
{
|
|
stations_[row].band_name_ = band_index.data ().toString ();
|
|
Q_EMIT dataChanged (model_index, model_index, roles);
|
|
changed = true;
|
|
}
|
|
}
|
|
break;
|
|
|
|
case 1:
|
|
{
|
|
stations_[row].offset_ = value.value<FrequencyDelta> ();
|
|
Q_EMIT dataChanged (model_index, model_index, roles);
|
|
changed = true;
|
|
}
|
|
break;
|
|
|
|
case 2:
|
|
stations_[row].antenna_description_ = value.toString ();
|
|
Q_EMIT dataChanged (model_index, model_index, roles);
|
|
changed = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return changed;
|
|
}
|
|
|
|
bool StationList::impl::removeRows (int row, int count, QModelIndex const& parent)
|
|
{
|
|
if (0 < count && (row + count) <= rowCount (parent))
|
|
{
|
|
beginRemoveRows (parent, row, row + count - 1);
|
|
for (auto r = 0; r < count; ++r)
|
|
{
|
|
stations_.removeAt (row);
|
|
}
|
|
endRemoveRows ();
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool StationList::impl::insertRows (int row, int count, QModelIndex const& parent)
|
|
{
|
|
if (0 < count)
|
|
{
|
|
beginInsertRows (parent, row, row + count - 1);
|
|
for (auto r = 0; r < count; ++r)
|
|
{
|
|
stations_.insert (row, Station ());
|
|
}
|
|
endInsertRows ();
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
Qt::DropActions StationList::impl::supportedDropActions () const
|
|
{
|
|
return Qt::CopyAction | Qt::MoveAction;
|
|
}
|
|
|
|
QStringList StationList::impl::mimeTypes () const
|
|
{
|
|
QStringList types;
|
|
types << mime_type;
|
|
types << "application/wsjt.Frequencies";
|
|
return types;
|
|
}
|
|
|
|
QMimeData * StationList::impl::mimeData (QModelIndexList const& items) const
|
|
{
|
|
QMimeData * mime_data = new QMimeData {};
|
|
QByteArray encoded_data;
|
|
QDataStream stream {&encoded_data, QIODevice::WriteOnly};
|
|
|
|
Q_FOREACH (auto const& item, items)
|
|
{
|
|
if (item.isValid ())
|
|
{
|
|
stream << QString {data (item, Qt::DisplayRole).toString ()};
|
|
}
|
|
}
|
|
|
|
mime_data->setData (mime_type, encoded_data);
|
|
return mime_data;
|
|
}
|
|
|
|
bool StationList::impl::dropMimeData (QMimeData const * data, Qt::DropAction action, int /* row */, int /* column */, QModelIndex const& parent)
|
|
{
|
|
if (Qt::IgnoreAction == action)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (parent.isValid ()
|
|
&& 2 == parent.column ()
|
|
&& data->hasFormat (mime_type))
|
|
{
|
|
QByteArray encoded_data {data->data (mime_type)};
|
|
QDataStream stream {&encoded_data, QIODevice::ReadOnly};
|
|
auto dest_index = parent;
|
|
while (!stream.atEnd ())
|
|
{
|
|
QString text;
|
|
stream >> text;
|
|
setData (dest_index, text);
|
|
dest_index = index (dest_index.row () + 1, dest_index.column (), QModelIndex {});
|
|
}
|
|
return true;
|
|
}
|
|
else if (data->hasFormat ("application/wsjt.Frequencies"))
|
|
{
|
|
QByteArray encoded_data {data->data ("application/wsjt.Frequencies")};
|
|
QDataStream stream {&encoded_data, QIODevice::ReadOnly};
|
|
while (!stream.atEnd ())
|
|
{
|
|
QString frequency_string;
|
|
stream >> frequency_string;
|
|
auto frequency = Radio::frequency (frequency_string, 0);
|
|
auto band_index = bands_->find (frequency);
|
|
if (stations_.cend () == std::find_if (stations_.cbegin ()
|
|
, stations_.cend ()
|
|
, [&band_index] (Station const& s) {return s.band_name_ == band_index.data ().toString ();}))
|
|
{
|
|
add (Station {band_index.data ().toString (), 0, QString {}});
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|