I need some advice about custom models. My only experience is using QTableWidget so this model/view stuff is new to me. I'm currently using Qt 4.3.4 on Windows XP.
My application is designed to configure network devices. From an outside source, it receives data for each device found on the network. Some of this data is to be displayed in tables (some of the displayed data is to be editable). The application will have a QTabWidget for each type of device and a tab to display all devices found. Each tab will display a table containing a subset of it's data.
Issue: The base table will show only the common data for each device found. The other 2 device-specific tables will show the common data plus some device-specific data.
Example:
- Type-A table will display:
- Name
- SubType
- IP Address
- Port1 Value
- Port2 Value
- Type-B table will display:
- Name
- SubType
- IP Address
- Group ID
- Base table will display all Type-A and all Type-B devices:
- Name
- SubType
- IP Address
My data sets are something like this:
Qt Code:
class CBaseData { public: CBaseData( int nDevType ); virtual ~CBaseData( void ); // Accessors bool IsDynamicIP( void ) { return m_bIsDynamicIP; } uint1 GetIPMode( void ) { return m_bIsDynamicIP ? 1 : 0; } void SetIPMode( bool bIsDynamic ) { m_bIsDynamicIP = bIsDynamic; } int GetDevType( void ) { return m_nDevType; } void SetDevType( int nDevType ) { m_nDevType = nDevType; } protected: int m_nDevType; // Device Type bool m_bIsDynamicIP; // Static or dynamic IP address QString m_sID; // Device ID uint4 m_sIPAddr; // IP address of device uint4 m_sSubNetMask; // Subnet Mask of device uint4 m_sDefIP; // Default IP address of device QString m_sName; // Name of device QString m_sModelName; // Manufacturer model name for this device (read-only) QString m_sSerialNum; // Device serial number QString m_sHardwareVer; // Hardware version number (read-only) QString m_sSoftwareVer; // Application software version number (read-only) // ... extra network connection data }; class CTypeAData : public CBaseData { public: CTypeAData( int nDevType ); virtual ~CTypeAData( void ); // Accessors uint4 GetPort1Num( void ) { return m_nPort1Num; } void SetPort1Num( uint4 nNum ) { m_nPort1Num = nNum; } uint4 GetPort2Num( void ) { return m_nPort2Num; } void SetPort2Num( uint4 nNum ) { m_nPort2Num = nNum; } protected: uint4 m_nPort1Num; // value for port 1 uint4 m_nPort2Num; // value for port 2 // ...extra private data }; class CTypeBData : public CBaseData { public: CTypeBData( void ); virtual ~CTypeBData( void ); // Accessors uint1 GetGroupID( void ) { return m_nGrpID; } void SetGroupID( const uint1 nID ) { m_nGrpID = nID; } protected: uint1 m_nSMPTEGrpID; // Group ID - R/W // ...extra private data };To copy to clipboard, switch view to plain text mode
As you can see, each data class seems to map nicely to a device/table. My problem is deciding the model(s) to choose.
I would like to use QAbstractTableModel as the parent of a custom model. Because I'm dealing with different data sets it seems like I will need a separate model for each table BUT I don't want to duplicate any code for the the Base table model.
Possibilities (please note that I'm just exploring here):
- Keep a data pointer to each type of data in my custom model. Somehow determine which device type is required for model function calls.
- Create a separate model for each data type. (How to handle the Base data table?)
- Create a 'base' model and use that as a parent for custom Type-A and Type-B models. (Can this even be done?)
- Any other possibilities out there?
Bookmarks